Useful shell commands E-mail
Tuesday, 20 October 2009 13:22

I'll keep adding to this list as I discover interesting and/or useful commands.

Kill a process by name

Simply replace <name> with the name of the process you want to stop. I have found that kill doesn't always work, but killall with the s9 parameter gets the job done.

kill $(pgrep <name>)
killall -s9v <name>
pkill <name>

Monitor bandwidth usage

This command displays a pretty comprehensive live report in the shell window, showing where all your bandwidth is going. Replace <interface> with the network connection you want to monitor. Options "eth0" or "wlan0" (without the quotes) should cover the average user's need for monitoring wired and wireless networks respectively.

sudo iftop -BP -i <interface>

Stop, start or restart a service

Replace <name> with the name of the service, and <action> with either "stop", "start" or "restart" (without the quotes).

servce <name> <action>
/etc/init.d/<name> <action>

pushd and popd

Now this is neat. If you are writing a script that needs to change directory, then you can push your current directory onto the stack, then when you are done, pop it off the stack to put you back where you were. The beauty of using a stack is that you can push as many directories onto the stack as you like.

pushd .
... do your thing
popd
blog comments powered by Disqus