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.

Universal configuration monitoring and system of record for IT.

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:



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.




Commands using ps from sorted by
Terminal - Commands using ps - 224 results
ps -A
2009-08-11 16:52:59
User: xraj
Functions: ps

list all the processes

ps -o comm= -p $(ps -o ppid= -p $$)
2009-08-03 07:41:21
User: olorin
Functions: ps

Get the name of the parent command. This might be helpful, if you need to react on that information. E. g. a script called directly via ssh has got sshd as parent, manually invoked the parent process will probably be bash

ps -o rss -C httpd | tail -n +2 | (sed 's/^/x+=/'; echo x) | bc
2009-07-31 15:15:08
Functions: echo ps sed tail

Display the amount of memory used by all the httpd processes. Great in case you are being Slashdoted!

ps -u $USER |grep $1 | awk '{ print $1}'| xargs kill
2009-07-20 10:06:32
User: buffer
Functions: awk grep ps xargs

Well this can come handy , when you don't feel like playing with pid rather if you know

the process name say "firefox",it would kill it.The script given below would kill the process with its name given as first parameter , though not robust enough to notify that process doesn't exist , well if you know what you are doing that's wouldn't be a problem.:)





ps -u $USER |grep $1 | awk '{ print $1}'| xargs kill


ps ax -o "%p %U %u %x %c %n"
2009-07-14 17:21:59
Functions: ps

ps command gives the possibility to display information with custom formatting with the -o options followed by the format specifier list.

ps awwfux | less -S
2009-07-04 09:39:28
User: ToyKeeper
Functions: less ps

If you want a visual representation of the parent/child relationships between processes, this is one easy way to do it. It's useful in debugging collections of shell scripts, because it provides something like a call traceback.

When a shell script breaks, just remember "awwfux".

ps aux | grep -v `whoami`
ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f%\t%.2f%\n",num[user], user, cpu[user], mem[user]) }'
ps auxf | grep httpd | grep -v grep | grep -v defunct | awk '{sum=sum+$6}; END {print sum/1024}'
ps -L -p <pid> | wc -l
ps aux | sort +2n | tail -20
2009-03-31 12:03:34
User: dopeman
Functions: ps sort tail

This command will show the 20 processes using the most CPU time (hungriest at the bottom).

You can see the 20 most memory intensive processes (hungriest at the bottom) by running:

ps aux | sort +3n | tail -20

Or, run both:

echo "CPU:" && ps aux | sort +2n | tail -20 && echo "Memory:" && ps aux | sort +3n | tail -20
[[ $(COLUMNS=200 ps faux | awk '/grep/ {next} /ssh -N -R 4444/ {i++} END {print i}') ]] || nohup ssh -N -R 4444:localhost:22 user@relay &
2009-03-31 09:39:59
User: j0rn
Functions: awk nohup ps ssh
Tags: ssh cronjob

I find it ugly & sexy at the same time isn't it ?

ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9
ps aux | grep 'httpd ' | awk {'print $2'} | xargs kill -9
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed "/^ 0.0 /d"
ps -o %mem= -C firefox-bin | sed -s 's/\..*/%/'
ps axww | grep SomeCommand | awk '{ print $1 }' | xargs kill
2009-02-28 17:48:51
User: philiph
Functions: awk grep ps xargs

This command kills all processes with 'SomeCommand' in the process name. There are other more elegant ways to extract the process names from ps but they are hard to remember and not portable across platforms. Use this command with caution as you could accidentally kill other matching processes!

xargs is particularly handy in this case because it makes it easy to feed the process IDs to kill and it also ensures that you don't try to feed too many PIDs to kill at once and overflow the command-line buffer.

Note that if you are attempting to kill many thousands of runaway processes at once you should use 'kill -9'. Otherwise the system will try to bring each process into memory before killing it and you could run out of memory. Typically when you want to kill many processes at once it is because you are already in a low memory situation so if you don't 'kill -9' you will make things worse

ps -ef | grep [t]clsh
echo COMMAND | xargs -ixxx ps -C xxx -o pid= | xargs -ixxx ls -l /proc/xxx/cwd
ps auxwww | grep outofcontrolprocess | awk '{print $9}' | xargs kill -9
ps aux | awk '/name/ {print $2}'
2009-02-20 21:35:52
User: evil_otto
Functions: awk ps

This finds a process id by name, but without the extra grep that you usually see. Remember, awk can grep too!

ps -eo stat,pid,user,command | egrep "^STAT|^D|^R"
2009-02-20 19:00:17
User: jyoder
Functions: egrep ps

Want to know why your load average is so high? Run this command to see what processes are on the run queue. Runnable processes have a status of "R", and commands waiting on I/O have a status of "D".

On some older versions of Linux may require -emo instead of -eo.

On Solaris: ps -aefL -o s -o user -o comm | egrep "^O|^R|COMMAND"

ps auxw |egrep "PID|process_to_look_at"
2009-02-20 00:17:43
User: tsaavik
Functions: ps


root 1828 0.0 0.0 5396 476 ? Ss 2008 0:00 /usr/sbin/sshd

x11vnc -display :0 -auth $(ps -ef|awk '/xauth/ {print $15}'|head -1) -forever -bg &
2009-02-19 18:55:54
User: nottings
Functions: ps

the $15 may change for you depending on your distro, etc...

ps aux | grep -i firefox | grep -v grep | awk '{print $2}' | xargs -t -i kill -9 {}
2009-02-19 18:50:00
User: blackdude
Functions: awk grep kill ps xargs

This is a nice way to kill processes.. the example here is for firefox!!! substitute firefox for whatever the process name is...