Bin Zhou
Bin Zhou

Reputation: 603

Bash: kill with pipe

Trying to kill very process related to Java. Is there a way to use pipe for it? I have tried

ps -e|grep "java"|kill

and

ps -e|grep "java"|xargs kill

Neither works.

Upvotes: 4

Views: 7898

Answers (3)

uli42
uli42

Reputation: 313

You can also use pkill java. pkill is pgrep and kill combined into one command.

Upvotes: 1

antak
antak

Reputation: 20759

There is, but this is easier (presuming your system has killall):

killall java

Upvotes: 6

perreal
perreal

Reputation: 97948

pgrep is the right tool for grepping processes:

kill $(pgrep -f java)

the -f flag in pgrep is for matching against the full command line used to execute a process.

Upvotes: 14

Related Questions