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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using ps from sorted by
Terminal - Commands using ps - 232 results
sudo kill -9 $( ps -e | grep Xorg | awk '{ print $1 }' )
2014-06-01 22:43:32
Functions: awk grep kill ps sudo

There are times when a X Window server hangs. When this happens, you can log in on a terminal and kill the Xorg process (i.e. the X Server). This one line command will do the trick.

ps aux | grep 'mysql' | awk '{print $6/1024 " MB";}'
ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
ps aux | grep 'httpd' | awk '{print $6/1024 " MB";}'
ps -e -o pid,vsz,comm= | sort -n -k 2
2014-05-14 00:36:50
Functions: ps sort

left-most column is PID, middle is virtual memory being consumed, right-most is actual process.

ps -efa | grep httpd | grep -v grep | awk '{ print $2 }' |xargs
ps -eo pmem,comm | grep application-name
2014-02-23 13:21:29
User: Darkstar
Functions: grep ps

Displays memory usage for individual instances of an application that spawns multiple instances of itself. This command also works on single process applications.

ps -eo etime,pid,pcpu,ppid,args | sed -e '/\[.\+\]/d' -e '/^[ \t]*[0-9]\{2\}:[0-9]\{2\} /d' | sort -k1r
2014-02-14 00:22:31
User: neurodrone
Functions: ps sed sort

If you have ever been trying to look for a list of processes based on their elapsed time you don't need to look any further.

This command lets you find the list of processes ordered in a reversed order (oldest at the top) that have been running for over an hour on your system. Any system processes are filtered out, leaving only user initiated ones in. I find it extremely useful for debugging and performance analysis.

while ps -p $PID; do sleep 1; done; script2
2014-02-12 08:07:44
User: sanjiv856
Functions: ps sleep

Run one script after another in such a way that second script starts after finishing first one. Without using Pipe | or ampercent && i.e. the first process is already running and you want second one to start after the first one finishes. And this can be done in different folder in case the output of second script will affect the output of first script. So run this on any folder you wish to.

Where $PID is the process id of the already running job (add PID number)

script2 is your script you wish to run after first script ends

sleep 1 is sleep for one second (SUFFIX may be ?s? for seconds (the default), ?m? for minutes, ?h? for hours or ?d? for days, read man sleep)

while [ 1 ] ;do ps aux|awk '{if ($8 ~ "D") print }'; sleep 1 ;done
CMD=chrome ; ps h -o pmem -C $CMD | awk '{sum+=$1} END {print sum}'
ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
2014-01-03 15:33:16
User: Darkstar
Functions: cut grep paste ps

This command will show the sum total of memory used in gigabytes by a program that spawns multiple instances of itself. Replace chrome with whatever program's memory usage you are investigating. This command is rather useless on software that only spawns a single instance of itself.

ps -u marcanuy -o pid,rss,command | awk '{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}'
2013-11-20 01:21:59
User: marcanuy
Functions: awk ps

Add up the amount of memory your processes are using and display the total. Replace marcanuy with your desired username.

ps -p $$
ps r -A
output=$(ps -ef|grep -i java 2>/dev/null); for w in ${output[@]}; do if [[ $w =~ .*Xmx.* ]]; then result=$(grep -oP "[0-9]+" <<< $w); echo $result ;fi ; done| awk 'BEGIN {sum=0} {for(i=1; i<=NF; i++) sum+=$i } END {print sum}'
2013-08-13 14:04:17
User: massiverobot
Functions: awk echo grep ps
Tags: java jvm xmx

This will find all the -Xmx[BIGINT] running on a system, add them up for you and give you the total.

svn ps svn:executable yes /web/itscripts/check_mail.plproperty
$ ps -LF -u user
2013-08-06 21:50:48
User: jld
Functions: ps
Tags: bash processes

Piping ps into grep is mostly useless: ps has its own filter options like -u and -C

psgrep() { ps aux | tee >(head -1>&2) | grep -v " grep $@" | grep "$@" -i --color=auto; }
2013-08-02 12:44:32
User: fnl
Functions: grep head ps tee
Tags: grep ps

Pipes the header row of ps to STDERR, then greps for the command on the output of ps, removing the grep entry before that.

ps -eLF | grep ^user
2013-07-24 09:53:12
User: balsagoth
Functions: grep ps
Tags: bash processes

This shows all process (-e) and threads (-L) in full format (-F)

ps aux | grep $(echo $1 | sed "s/^\(.\)/[\1]/g")
2013-07-16 10:10:51
User: opexxx
Functions: echo grep ps sed
Tags: sed grep ps

grep по ps aux

ps -eo pid,lstart,cmd
2013-06-17 12:52:53
User: kruspemsv
Functions: ps
Tags: PID

That is useful to discover the start time of process older than 1 day.

You can also run:

ls -ld /proc/PID

That's returning the creation date of the proc files from the process. Some users reported that this way might show you a wrong date since any other process like cron, for example, could change this date.

sudo lsof -p `sudo ps aux | grep -i neo4j | grep -v grep | awk '{ print $2 }'`
2013-06-02 10:15:30
User: andycunn
Functions: awk grep ps sudo

Inner "ps...grep..." command searches for a process matching the specified .

"lsof -p lists all file descriptors owned by . Includes open files, sockets, devices, etc...

ps aux | sort -n -k2 | awk '{if ($2 < 300) print($0)}'
2013-05-09 13:09:58
User: lili
Functions: awk ps sort

Display all pid less the 300 processes info

ps aux | awk '/chrome/ {s+=$6}END{print s/1024}';