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 - 207 results
ps -u<user>
psg() { ps aux | grep "[${1[1]}]${1[2,-1]}"; }
2009-09-07 04:37:11
User: jedahan
Functions: grep ps
-5

alias ps?='psg' for maximum hawtness. Works in bash or zsh.

ps -ef | awk '/process-name/ && !/awk/ {print}'
2009-08-19 11:22:09
User: dopeman
Functions: awk ps
1

This does the same thing as many of the 'grep' based alternatives but allows a more finite control over the output. For example if you only wanted the process ID you could change the command:

ps -ef | awk '/mingetty/ && !/awk/ {print $2}'

If you wanted to kill the returned PID's:

ps -ef | awk '/mingetty/ && !/awk/ {print $2}' | xargs -i kill {}
command ps -Hacl -F S -A f
2009-08-19 07:08:19
User: AskApache
Functions: command ps
8

I don't truly enjoy many commands more than this one, which I alias to be ps1.. Cool to be able to see the heirarchy and makes it clearer what need to be killed, and whats really going on.

ps aux | grep [c]ommandname
ps -C command
2009-08-14 15:30:42
User: recursiverse
Functions: ps
5

preferred way to query ps for a specific process name (not supported with all flavors of ps, but will work on just about any linux afaik)

ps aux | grep [p]rocess-name
2009-08-13 05:44:45
User: olorin
Functions: grep ps
62

As an alternative to using an additional grep -v grep you can use a simple regular expression in the search pattern (first letter is something out of the single letter list ;-)) to drop the grep command itself.

ps aux | grep process-name | grep -v "grep"
ps -A
2009-08-11 16:52:59
User: xraj
Functions: ps
-13

list all the processes

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

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
4

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
-4

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.:)

----

killhim.sh

----

#!/bin/bash

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
4

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
37

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
3

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
4

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
-7

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