Commands using ps (300)

  • ps returns all running processes which are then sorted by the 4th field in numerical order and the top 10 are sent to STDOUT. Show Sample Output


    107
    ps aux | sort -nk +4 | tail
    root · 2009-01-23 17:12:33 299
  • 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. Show Sample Output


    72
    ps aux | grep [p]rocess-name
    olorin · 2009-08-13 05:44:45 53
  • 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".


    45
    ps awwfux | less -S
    ToyKeeper · 2009-07-04 09:39:28 15
  • awk is evil! Show Sample Output


    22
    ps hax -o user | sort | uniq -c
    buzzy · 2010-04-29 10:43:03 15
  • ps and grep is a dangerous combination -- grep tries to match everything on each line (thus the all too common: grep -v grep hack). ps -C doesn't use grep, it uses the process table for an exact match. Thus, you'll get an accurate list with: ps -fC sh rather finding every process with sh somewhere on the line. Show Sample Output


    14
    ps -fC PROCESSNAME
    pooderbill · 2015-04-20 13:09:44 17
  • you can also pipe it to "tail" command to show 10 most memory using processes. Show Sample Output


    13
    ps aux --sort=%mem,%cpu
    mrwill · 2009-10-10 22:48:51 9
  • Trick to avoid the form: grep process | grep - v grep Show Sample Output


    13
    ps axu | grep [a]pache2
    ebah80 · 2012-12-15 19:37:19 34
  • The trick here is to use the brackets [ ] around any one of the characters of the grep string. This uses the fact that [?] is a character class of one letter and will be removed when parsed by the shell. This is useful when you want to parse the output of grep or use the return value in an if-statement without having its own process causing it to erroneously return TRUE. Show Sample Output


    12
    ps aux | grep "[s]ome_text"
    SiegeX · 2009-02-17 02:10:50 18
  • 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. Show Sample Output


    12
    ps -eo pid,lstart,cmd
    kruspemsv · 2013-06-17 12:52:53 16
  • Surround the first letter of what you are grepping with square brackets and you won't have to spawn a second instance of grep -v. You could also use an alias like this (albeit with sed): alias psgrep='ps aux | grep $(echo $1 | sed "s/^\(.\)/[\1]/g")'


    10
    ps aux | grep [h]ttpd
    abcde · 2009-02-10 02:59:20 18
  • This command is useful when you want to know what process is responsible for a certain GUI application and what command you need to issue to launch it in terminal. Show Sample Output


    9
    xprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
    jackhab · 2009-02-16 07:55:19 88

  • 9
    ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed "/^ 0.0 /d"
    fbparis · 2009-03-07 16:47:10 21
  • 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. Show Sample Output


    8
    command ps -Hacl -F S -A f
    AskApache · 2009-08-19 07:08:19 10
  • The original version gives an error, here is the correct output


    7
    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]) }'
    georgz · 2009-10-29 12:49:01 11
  • 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. Show Sample Output


    7
    ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace
    px · 2011-03-14 21:45:22 35

  • 6
    ps -o %mem= -C firefox-bin | sed -s 's/\..*/%/'
    susannakaukinen · 2009-03-06 21:09:26 13
  • 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) Show Sample Output


    6
    ps -C command
    recursiverse · 2009-08-14 15:30:42 6
  • enumerates the number of processes for each user. ps BSD format is used here , for standard Unix format use : ps -eLf |awk '{$1} {++P[$1]} END {for(a in P) if (a !="UID") print a,P[a]}' Show Sample Output


    6
    ps aux |awk '{$1} {++P[$1]} END {for(a in P) if (a !="USER") print a,P[a]}'
    benyounes · 2010-04-28 15:25:18 4
  • faster ;) but your idea is really cool


    6
    ps -ef | grep c\\ommand
    ioggstream · 2011-01-04 11:43:14 5
  • # Delete all containers docker rm $(docker ps -a -q) # Delete all images docker rmi $(docker images -q)


    6
    sudo docker rm $(docker ps -a -q); sudo docker rmi $(docker images -q)
    lpalgarvio · 2015-05-20 12:34:40 34
  • Shows a tree view of parent to child processes in the output of ps (linux). Similar output can be achieved with pstree (also linux) or ptree (Solaris). Show Sample Output


    5
    ps auxf
    systemj · 2009-02-05 18:07:16 19
  • works well in crontab.


    5
    ps -C program_name || { program_name & }
    grokskookum · 2009-09-24 03:35:39 3
  • This command loops over all of the processes in a system and creates an associative array in awk with the process name as the key and the sum of the RSS as the value. The associative array has the effect of summing a parent process and all of it's children. It then prints the top ten processes sorted by size. Show Sample Output


    5
    ps axo rss,comm,pid | awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10
    d34dh0r53 · 2010-03-03 16:41:05 6
  • This will save your open windows to a file (~/.windows). To start those applications: cat ~/.windows | while read line; do $line &; done Should work on any EWMH/NetWM compatible X Window Manager. If you use DWM or another Window Manager not using EWMH or NetWM try this: xwininfo -root -children | grep '^ ' | grep -v children | grep -v '<unknown>' | sed -n 's/^ *\(0x[0-9a-f]*\) .*/\1/p' | uniq | while read line; do xprop -id $line _NET_WM_PID | sed -n 's/.* = \([0-9]*\)$/\1/p'; done | uniq -u | grep -v '^$' | while read line; do ps -o cmd= $line; done > ~/.windows Show Sample Output


    5
    wmctrl -l -p | while read line; do ps -o cmd= "$(echo "$line" | awk '$0=$3')"; done > ~/.windows
    matthewbauer · 2010-07-04 22:11:24 6
  • STARTED Mon Oct 18 04:02:01 2010 Show Sample Output


    5
    ps -o lstart <pid>
    nottings · 2010-10-18 17:09:02 5
  •  1 2 3 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

Remove trailing space in vi

Create a false directory structure for testing your commands
This will make a false directory with the same file names as whatever directory you choose. This is wise to use when testing scripts that alter contents, filenames, or move files. I wrote this after an OOPS I made when renaming a directory of JPGs, PNGs, PSDs that were mixed. I recommend this as I lost over 2000 vacation pictures and some graphics I designed for software and web sites. :( NOTE: This only creates name copies, that data itself is not copied.

Convert seconds to human-readable format
This example, for example, produces the output, "Fri Feb 13 15:26:30 EST 2009"

Printout a list of field numbers (awk index) from a CSV file with headers as first line.
Useful to identify the field number in big CSV files with large number of fields. The index is the reference to use in processing with commands like 'cut' or 'awk' involved.

tcpdump sniff pop3,imap,smtp and http

Remove security limitations from PDF documents using ghostscript (for Windows)
#4345 also works under windows

list files recursively by size

Display calendar with specific national holidays and week numbers
NB when you run this gcal command in your shell, holidays are highlighted but this highlighting does not show in the sample output (above). To find full details on gcal options: gcal --long-help | less Example for United States, Pennsylvania: gcal -K -q US_PA 2009 # display holidays in USA/Pennsylvania for 2009 (with week numbers) Example for Hong Kong: gcal -K -q HK 2009 # display holidays in Hong Kong for 2009 (with week numbers)

create a temporary file in a command line call
Sometimes you have a script that needs and inputfile for execution. If you don't want to create one because it may contain only one line you can use the `

Delete recursively only empty folders on present dir


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: