I would like to issue a kill command across many *nix machines. I'm attempting to do something like this:

rsh <remotemachine> ps -ef | grep <somepattern> | awk '{print $2}' | xargs n1 -t -i kill {}

But that issues the kill command on the local machine, not the remote machine. I've also tried something like this:

rsh <remotemachine> kill $(ps -ef | grep <somepattern> | awk '{print $2}')

But that's not working for me either.

  • Don't use rsh! It's not secure at all. Use ssh instead
    – Daenyth
    Jun 26, 2010 at 0:59

4 Answers 4


Assuming you're working on machines that have it, you could also use a more specific utility, like pgrep or pkill. This means you don't have to use grep, awk, or xargs. This would simplify things quite a bit.


rsh "remotemachine" pkill whatevertheprocessnameis

  • This answer is the bomb! I'm running zsh and tmux plugin. It prevented me from restarting my virtual machine the 4th time after switching to a new user and switching back again which causes a tmux to be run in a tmux.
    – Mark
    Oct 12, 2013 at 4:21

ssh user@someserver "ps -ef | grep | awk '{print $2}' | xargs n1 -t -i kill {}"

I refuse to use any other method of remote console other than SSH. It's also virtually everywhere.


On a random aside, I'd recommend you use SSH. RSH sends passwords in the clear, SSH is far more secure.

Either way, you're going to need to escape characters that the local shell is going to interpret. Namely, those pipes. And the single quotes. And the dollar sign. I think the curly braces are OK, but I'd probably be paranoid and do those two. Failure to do this results in the RSH command only getting passed up to the first pipe, then the output of that command getting piped locally to grep, awk, etc.

This is the kind of command that gets irritating. Try this:

rsh <remotemachine> ps -ef \| grep <somepattern> \| awk \'\{print \$2\}\' \| xargs n1 -t -i kill \{\}

--Christopher Karel


This is possible on Windows machine with taskkill, pskill or another command :) Regretably, it is not possible on Linux/UNIX machine without using ssh, rsh or another remote session tool.

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.