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 ps from sorted by
Terminal - Commands using ps - 221 results
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
0

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
0

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
0

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
0

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
0

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
0

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
1

grep по ps aux

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

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
0

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
0

Display all pid less the 300 processes info

ps aux | awk '/chrome/ {s+=$6}END{print s/1024}';
ps -A -o rss,command | grep [C]hrome | awk '{sum+=$1} END {printf("%sMB\n",sum/1024)}'
ps -o rss= -C Chrome | (x=0; while read rss; do ((x+=$rss)); done; echo $((x/1024)))
ps -e -m -o user,pid,args,%mem,rss | grep Chrome | perl -ne 'print "$1\n" if / (\d+)$/' | ( x=0;while read line; do (( x += $line )); done; echo $((x/1024)) );
renice -20 -g 2874 (2784 found with ps -Aj)
ps aux | grep [process] | awk '{print $2}' | xargs -I % ls /proc/%/fd | wc -l
ps aux | grep <process> | grep -v grep | awk '{print $2}' | xargs -i -t kill -9 {}
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace -f
2013-02-19 19:14:57
User: msealand
Functions: awk grep ps strace xargs
1

This version also attaches to new processes forked by the parent apache process. That way you can trace all current and *future* apache processes.

ps -u user_name_here | grep process_name_here | wc -l
ps -xaw -o state,ppid | grep Z | grep -v PID | awk '{ print $2 }' | xargs kill -9
2013-01-09 04:21:54
User: terrywang
Functions: awk grep kill ps xargs
-4

Did some research and found the previous command wrong, we don't kill a zombie but its parent. Just made some modifcation to khashmeshab's command.

ps axu | grep [a]pache2
2012-12-15 19:37:19
User: EBAH
Functions: grep ps
12

Trick to avoid the form:

grep process | grep - v grep

while true; do date; ps auxf | awk '{if($8=="D") print $0;}'; sleep 1; done