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 - 206 results
for R in `svn log file:///path/repo | grep ^r | grep dude | cut -d' ' -f1 | cut -dr -f2`; do svn ps svn:log --revprop -r $R "`svn pg svn:log --revprop -r $R file:///path/repo; perl -e 'print ".\n";' | fromdos`" file:///path/repo; done
2011-03-24 08:29:15
User: theist
Functions: cut grep ps
Tags: svn
0

Let's supose some moron used some m$ shit to commit to a later svnsynced repo. On a svn sync all his message logs cause a svnsync: Error setting property 'log': this commands finds all its contributions and fix all his commit logs

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 axu | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'
ps -C apache o pid= | sed 's/^/-p /' | xargs strace
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace
2011-03-14 21:45:22
User: px
Functions: awk grep ps xargs
5

This one-liner will use strace to attach to all of the currently running apache processes output and piped from the initial "ps auxw" command into some awk.

pss() { ps -eo pid,args | sed '/'"$1"'/!d;/sed/d' ; }
2011-03-14 15:51:49
User: vando
Functions: ps sed
-2

I know you can use pidof but with this you can know the specific PID with his command arguments (useful if you're running various proccess with same application)

ps -eo pmem,pid,comm --no-headers | sort -k1 -rn | head -10
2011-03-11 04:51:35
User: dexterhu
Functions: head ps sort
0

Pros: the format is very simple, there is no need to show every columns, and full command with args

the first column is memory consumption %

the second column is pid

the third is just the command (without full arguments, most application's arguments are too long)

You can decide which application to kill then.

ps ax | egrep "*.exe|*exe]" | awk '{ print $1 }' | xargs kill
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

ps -p $$
2011-02-05 16:22:17
User: psykotron
Functions: ps
3

short, sweet, and works after sudoing a new shell.

ps -o comm= -p $$
2011-02-05 11:54:42
User: depesz
Functions: ps
0

First version was "ps uw -p $$", but current "ps -o comm= -p $$" just gives shell name

ps ho command $$
ps -ef | grep c\\ommand
ps -o user,%cpu,%mem,command
2010-12-08 10:35:25
Functions: ps
Tags: ps
0

Using ps options rather than filtering.

ps aux | awk '{print($1" "$3" "$4" "$11);}' | grep -v "0.0"
2010-12-08 09:59:39
User: cas_alexi
Functions: awk grep ps
1

mac os x:

ps aux | awk '{print($1" "$3" "$4" "$11);}' | grep -v "0,0"

linux:

ps aux | awk '{print($1" "$3" "$4" "$11);}' | grep -v "0.0"

ps -eo %cpu,args | grep -m1 PROCESS | awk '{print $1}'
ps -eo args,%cpu | grep -m1 PROCESS | tr 'a-z-' ' ' | awk '{print $1}'
ps -o etime `pidof firefox` |grep -v ELAPSED | sed 's/\s*//g' | sed "s/\(.*\)-\(.*\):\(.*\):\(.*\)/\1d \2h/; s/\(.*\):\(.*\):\(.*\)/\1h \2m/;s/\(.*\):\(.*\)/\1m \2s/"
ps -o pid,lwp,lstart --pid 797 -L
2010-11-24 17:04:08
User: jkharness87
Functions: ps
1

This command will list all threads started by a particular pid along with the start time of each thread. This is very valuable when diagnosing thread leaks.

ps -eorss,args | sort -nr | pr -TW$COLUMNS | head
ps -o euid,egid --ppid `netstat --inet --inet6 -pln|awk '/:80 / { split($7,tmp, "/"); print tmp[1]; }'`|sort |uniq|grep -v EUID
2010-11-18 21:22:29
User: chx
Functions: awk grep ps sort
-1

This command allows you to find the effective uid and gid of the Apache process regardless of process name (which can be apache2 or httpd depending on distro).

ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS
ps ax -L -o pid,tid,psr,pcpu,args | sort -nr -k4| head -15 | cut -c 1-90
ps uw --ppid $PID
ps axo pid,ppid | awk "{ if ( \$2 == $PID ) { print \$1 }}")