Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using kill from sorted by
Terminal - Commands using kill - 93 results
kill -SIGHUP `cat /var/run/mydns.pid`
2011-10-21 14:29:24
User: ironmarc
Functions: kill
1

Occasionally, to force zone updating, cache flush is necessary. This command is better than restart the mydns daemon.

c=$(pgrep <cmd>) && <new_cmd> && kill $c
2011-09-14 19:58:30
User: totti
Functions: kill
1

eg:

Already running cmd

sleep 120

Substitution cmd

c=$(pgrep sleep) && sleep 5 && kill $c
kill -9 `ps -u user -o "pid="`
pgrep -u username php5-fcgi | xargs kill -9
/bin/sh -c 'find . -name FILENAME -print -exec kill $$ \;'
2011-07-20 16:51:18
User: richardneish
Functions: kill
0

If you know that you want only the first match from a 'find' command, this will terminate the find as soon as a match is found.

Recent versions of GNU find have the -quit parameter, which does the same thing as this, so this is only useful if you are stuck with an older version of find. or need to write a backward portable script.

I can't take credit for this - I saw it on a chat room where I work and thought it was useful, so am sharing it here both for others, and in case I want to remember it in the future.

dd if=/dev/urandom of=file.img bs=4KB& pid=$!; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 1 && clear; done
2011-06-24 21:49:10
Functions: dd kill sleep
Tags: dd progress
2

Only slightly different than previous commands. The benefit is that your "watch" should die when the dd command has completed. (Of course this would depend on /proc being available)

pgrep -lf gnome-panel | awk '{if ($2=="gnome-panel") print $1}' | xargs kill -9
2011-06-12 12:23:27
User: UnixNeko
Functions: awk kill xargs
-2

I have some problems with gnome panel which does not load completely leaving me without the actual GUI. This commands helps to kill the gnome-panel process then it should be relaunch automatically.

ps ax | grep -i ProcessName| kill -9 `awk '/FileName.Ext/ {print $1}'`
2011-03-24 02:49:49
User: bytesabit
Functions: grep kill ps
0

Outputs the PID of any given file run from a command line... Hope it helps!

ps ax > processes && cat processes | egrep "*.exe |*exe]" | awk '{ print $1 }' > pstokill && kill $(cat pstokill) && rm processes && rm pstokill
2011-02-26 16:13:58
User: sxiii
Functions: awk cat egrep kill ps rm
Tags: kill wine exe
-4

This command kills all wine instances and each EXE application working on a PC.

Here is command info:

1) ps ax > processes = save process list to file named "processes" (we save it because we don't wont egrep to be found in the future)

2) cat processes | egrep "*.exe |*exe]" = shows the file "processes" and after greps for each *.exe and *exe] in it

3) | awk '{ print $1 }' > pstokill = saves processes PID's to file "pstokill" using awk filter

4) kill $(cat pstokill) = kills each PID in file pstokill, which is shown by cat program

5) rm processes && rm pstokill = removes temporary files

screencast() { arecord -R 1000 -f cd -t wav $1.wav & RECPID=$!; echo "Starting screencast in new shell. Exit subshell to quit."; script -t 2> $1.timing -a $1.session; kill $RECPID; }
2011-01-20 14:35:47
User: bartonski
Functions: arecord cd echo kill script
2

This shell function takes a single argument, which is used as the base name of the .wav, .timing and .session files created. To create a screencast:

screencast test

type and talk ...

then type 'exit' or to exit the screencast.

test.wav will contain the audio from your screencast.

test.session will contain text and control characters needed to paint the screen

test.timing will contain timing information needed to synch individual keystrokes in test.session with the audio.

to play back:

aplay test.wav & scriptreplay test.{timing,session}

NOTE: because the shell function uses the variable "$!", and bash likes to expand '!' during history expansion, you will need to turn off bash's history before you enter the shell function.

This can be achieved using the command

set +H
kill -9 `lsof -t -i :port_number`
alias kfire='for i in `ps aux | grep [F]irefox `; do echo $i; kill $(($i)); done; '
2010-12-27 01:47:58
User: swerve
Functions: alias echo grep kill
-2

This is an attempt to get a command which I can alias. It's ugly but it works. I'm hoping someone can suggest a cleaner version.

I have tried....

# alias kfire="for i in $( ps aux | grep [F]irefox | awk \'{print $2}\' ); do kill $; done"

# alias kfire=`kill $(ps aux | grep [F]irefox | awk '{print $2}' | tr '\n' ' ')`

# alias kfire='ps au | grep -i [F]irefox | awk \'{ print $2 \'} '

and they all fail in a .bashrc I've tried escaping the quotes and can't find a way to make the single quotes ' that awk wants work. Maybe I'm just stubborn but I don't want to put in a little #!/bin/bash file just so I can kill a firefox process all in one stroke. This script works (it kills the process before it errors out)... it's just ugly and there may be a pretty way to do this.

dd if=/path/to/inputfile of=/path/to/outputfile & pid=$! && sleep X && while kill -USR1 $pid; do sleep X; done
2010-12-02 15:07:18
User: cyrusza
Functions: dd kill sleep
Tags: dd copy progress
1

Adjust "sleep X" to your needs.

*NOTE: First sleep is required because bash doesn't have a "post-test" syntax (do XXX while).

kill -l
2010-11-17 23:48:51
User: b_t
Functions: kill
6

This command seems to achieve the similar/same goal.

who -u | grep -vE "^root " | kill `awk '{print $6}'`
kill `ps aux | grep xmms | grep -v grep | awk '{ print $2 }'`
2010-11-11 17:26:26
User: corp769
Functions: awk grep kill
-2

I use this command, within a cron job, to kill XMMS after a certain amount of time. This command returns the PID used by XMMS, and gets passed to the kill command. Another alternative would be ps aux | grep xmms | grep -v grep | awk '{ print $2 }' | xargs kill

kill -9 -1
who -u | grep -vE "^root " | kill `awk '{print $7}'`
2010-11-05 17:43:41
User: ProfessorTux
Functions: grep kill who
Tags: bash
4

Logs all users out except root.

I changed the grep to use a regexp in case a user's username contained the word root.

who -u|grep -v root|awk {'print $6'}|kill `awk {'print $0'}`
2010-11-05 12:19:06
User: leosimon
Functions: awk grep kill who
1

It's only to logout all other user's except "root"

ps -u $USER -lf | grep -vE "\-bash|sshd|ps|grep|PPID" > .tmpkill; if (( $(cat .tmpkill | wc -l) > 0 )); then echo "# KILL EM ALL"; cat .tmpkill; cat .tmpkill | awk '{print $4}' | xargs kill -9; else echo "# NOTHING TO KILL"; fi; cat .tmpkill; rm .tmpkill;
2010-11-04 04:16:50
User: zsugiart
Functions: awk cat echo grep kill ps rm wc xargs
0

Kills all process that belongs to the user that runs it - excluding bash, sshd (so putty/ssh session will be spared). The bit that says grep -vE "..." can be extended to include ps line patterns that you want to spare.

If no process can be found on the hitlist, it will print # NOTHING TO KILL. Otherwise, it will print # KILL EM ALL, with the cull list.

kill -9 `ps xawo state=,pid=|sed -n 's/Z //p'`
2010-10-27 07:38:07
User: AskApache
Functions: kill sed
0

just a leaner, smaller version. Love the original idea!

kill -9 `ps -xaw -o state -o ppid | grep Z | grep -v PID | awk '{print $2}'`
2010-10-27 07:29:14
User: khashmeshab
Functions: awk grep kill
9

It identifies the parents of the Zombie processes and kill them. So the new parent of orphan Zombies will be the Init process and he is already waiting for reaping them. Be careful! It may also kill your useful processes just because they are not taking care and waiting for their children (bad parents!).

kill -9 `ps -xaw -o state -o pid | grep Z | grep -v PID | awk '{print $2}'`
2010-10-27 07:19:52
User: khashmeshab
Functions: awk grep kill
1

Tested on FreeBSD 8.1 and CSH. The scripts works correctly but the Zombies do not die! I hope it will run and function as expected in Linux and others.

kill -9 `ps ax | egrep [f]elix.jar | egrep -o -e '^ *[0-9]+'`
2010-09-30 16:45:47
User: yababay
Functions: egrep kill
Tags: kill
3

Somtime one wants to kill process not by name of executable, but by a parameter name. In such cases killall is not suitable method.

ps -ef | grep [j]boss | awk '{print $2}'|xargs kill -9
2010-09-30 15:55:41
User: utoxin
Functions: awk grep kill ps xargs
Tags: kill
-6

Removed unneeded grep -v by making the initial grep unable to match itself.