I have /tmp/bash.sh that contains a script like this:

killall name*

It works fine if I go to /tmp folder and then run ./bash.sh, but if I go to / then run /tmp/bash.sh or ./tmp/bash.sh it doesn't work. Instead it complains with

name*: no process found

Why? How to fix this?


The killall utility does not take a pattern, it takes a list of one or several process names to send a signal to.

What's happening when you say killall name* is that the shell will expand the unquoted filename globbing pattern name* to all filenames in the current directory that matches that pattern.

You obviously have some filenames in /tmp that matches this pattern and that also corresponds to the processes that you'd like to kill. When there are no matching filenames, like there doesn't seem to be in the / directory on your system, your shell leaves the pattern unexpanded. The killall utility can't find any processes called name* and complains about that in the way that you report in the question.

For a utility that works more like what you expected, consider the pkill utility. With it, you may signal processes based on an extended regular expression matching their names.

The following would send the TERM signal to all processes whose names start with name (note that the pattern should generally be quoted):

pkill '^name'

To signal processes whose name matches name exactly:

pkill '^name$'

or, better,

pkill -x name

To also consider the arguments given to the process, use the -f option with pkill, e.g. to kill the cat command that you started by typing cat myfile:

pkill -f -x 'cat myfile'

See also the pkill manual (man pkill).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.