September 22, 2014

Bash one liners

Automatically remove dead "java" processes, simply replace process with java below

#ps aux | grep <process> | grep <optional other process> | tr -s " " | cut -d" " -f2 | xargs kill -9

The key point here is that the output from the ps command is cluttered with spaces and tabs when used together with cut. So, tr can be used to trim the lines, what the expression does is exactly that . It replaces all spaces with a single space character, allowing us to use this character as a delimiter to cut.

No comments: