Commands using top (20)

  • This command starts screen with 'htop', 'nethogs' and 'iotop' in split-screen. You have to have these three commands (of course) and specify the interface for nethogs - mine is wlan0, I could have acquired the interface from the default route extending the command but this way is simpler. htop is a wonderful top replacement with many interactive commands and configuration options. nethogs is a program which tells which processes are using the most bandwidth. iotop tells which processes are using the most I/O. The command creates a temporary "screenrc" file which it uses for doing the triple-monitoring. You can see several examples of screenrc files here:

    tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile
    Patola · 2009-08-03 10:14:02 5
  • top accecpts a comma separated list of PIDs.

    top -p $(pgrep -d , foo)
    michelsberg · 2012-06-27 20:59:09 0
  • pgrep foo may return several pids for process foobar footy01 etc. like this: 11427 12576 12577 sed puts "-p " in front and we pass a list to top: top -p 11427 -p 12576 -p 12577

    top $(pgrep foo | sed 's|^|-p |g')
    michelsberg · 2012-06-14 15:13:00 0

  • 4
    top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'
    jcgam69 · 2009-02-19 21:14:46 9

  • 3
    top -b -n 1 | sed 1,6d
    mlsmaycon · 2012-03-01 13:27:55 0
  • Like command 10870, but no need for sed

    top '-p' $(pgrep -d ' -p ' foo)
    __ · 2012-06-27 18:32:03 3
  • running top command in batch mode. it is usefull if you want to redirect the output in a file. Show Sample Output

    top -b -n 1
    r00t4u · 2010-01-24 16:17:30 1
  • This version is precise and requires one second to collect statistics. Check sample output for a more generic version and also a remote computer invocation variant. It doesn't work with the busybox version of the 'top' command but can be adjusted Show Sample Output

    top -bn2|awk -F, '/Cpu/{if (NR>4){print 100-gensub(/.([^ ]+).*/,"\\1","g",$4)}}'
    ichbins · 2014-04-18 17:48:05 1
  • 1. Start a process, such as 'top' command 2. # suspend process {ctrl-Z} 3. # background process bg 4. # list all backgrounded jobs jobs 5. # bring it back to foreground fg

    top; ctrl-z; bg; jobs; fg
    djangofan · 2015-10-14 17:33:25 2
  • An advanced possibility to count the lines of code like in #8394 Show Sample Output

    find . -type f -name '*.php' | xargs cat | sed -re ':top /\/\*.*\*\// { s/\/\*.*\*\///g ; t top }; /\/\*/ { N ; b top }' | awk '$0 !~ /^[\t[:space:]]*($|(\/\/)|(#))/' | wc -l
    andrehgw · 2011-05-05 06:12:34 25
  • Show only specific process id's using Top Show Sample Output

    top -p `pidof apache2 | awk '{gsub(/[ ]/,",");print}'`
    hbalagtas · 2011-07-28 20:13:36 0
  • You can also use different process using comma: top -p `pgrep pidgin`, `pgrep python` but you have to make sure the process exists or you'll get an error Show Sample Output

    top -p `pgrep pidgin`
    cesarbustios · 2011-11-23 20:35:53 0
  • Get the current cpu % usage on your system. Show Sample Output

    top -n2 -d 0.5 | grep ^Cpu | sed 's/[[:alpha:]%]*//g' | awk 'NR == 2 {printf("%.2f\n",100-$5)}'
    wizzra · 2012-09-06 12:56:26 1
  • Monitoring system in one line : DISK : disk space MEM: memory ( mem , swap, Total) CPU : all information about cpu activity LOAD : load average Show Sample Output

    echo "DISK:";df -Pl | grep -v "Filesystem" | awk '{print $5,$6}' ; echo "MEM:" ; free -mto | awk '{ print $1,$2,$3,$4 }'; echo "CPU:"; top -b -d1 -n1 | grep Cpu | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}';echo "LOAD:"; cat /proc/loadavg
    injez · 2014-09-29 12:43:52 15
  • This command greps the full name of processes. If you have processes with parameters(which you can see by pressing key 'c' in top) - this is the case

    top -p $(pgrep -f -d , foo)
    sedpro · 2015-03-03 17:18:54 1
  • Display the top processes sorted by memory usage. This is mostly useful because it's easy to remember and can give me a quick 'top' view of a group of servers when used over pssh. (Though I'd recommend |head -10 to minimize the output). Show Sample Output

    top -b -o +%MEM |head -17
    dak1n1 · 2016-03-16 22:14:34 3
  • I found Flash eating one of my CPUs after resume, the command above will help with that. For optional kicks you can put it into a script in /etc/pm/sleep.d/ (aspect in #swhack wrote this for me)

    top -bn 1 | awk '{if($1 ~ /^[0-9]+$/ && $9 > 97) {print $1;exit}}'|xargs kill
    chx · 2010-06-02 13:51:40 1
  • top

    usage: top -hv | -bcisSHM -d delay -n iterations [-u user | -U user] -p pid [,pid ...] Show Sample Output

    atgf0127 · 2011-04-14 06:59:06 0
  • Of course, the httpd can be replaced with any other process name Show Sample Output

    top -b -n 1 |grep httpd|wc -l
    dotanmazor · 2010-07-25 08:40:03 0
  • A simple but effective replacement for ps aux. I used to waste my time running ps over and over; top is the way to go. It also allows complex sorting options. Press q to exit "nicely" (Ctrl + C is always an option, of course). Note that the list updates each second, resorting in the process; if you're trying to grab a specific PID, you might be better off with ps. htop Alternatively, htop is available, though it may not come pre-installed. htop is slightly more interactive than top and includes color coding, visuals, and a nice interface for selecting and then killing processes. (Thanks to bwoodacre for this great tool.) Show Sample Output

    Zenexer · 2009-03-18 00:03:42 7

What's this? 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

Rename .JPG to .jpg recursively
This command is useful for renaming a clipart, pic gallery or your photo collection. It will only change the big caps to small ones (on the extension).

Transcode .flac to .wav with gstreamer
Takes all .flac directories, feeds them into a simple transcode pipeline to spit out .wavs with the same name (but correct extension).

Backup of a partition
Clone a partion with tar.

Show all LISTENing and open server connections, with port number and process name/pid

Rsync files with spaces
Using the double dash before the source and target makes the command work fine with weird filenames.

Define words and phrases with google.
This function takes a word or a phrase as arguments and then fetches definitions using Google's "define" syntax. The "nl" and perl portion isn't strictly necessary. It just makes the output a bit more readable, but this also works: $define(){ local y="$@";curl -sA"Opera" "${y// /+}"|grep -Po '(?/dev/null;}

online MAC address lookup

Find broken symlinks
To understand why this is the equivalent of "find -L /path/to/search -type l, see or look at

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Print a row of 50 hyphens

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.


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: