Commands tagged top (14)

  • top accecpts a comma separated list of PIDs.

    top -p $(pgrep -d , foo)
    michelsberg · 2012-06-27 20:59:09 0
  • 'top' has fancy layout modes where you can have several windows with different things displayed. You can configure a layout and then save it with 'W'. It will then be restored every time you run top. E.g. to have two colored windows, one sorted by CPU usage, the other by memory usage, run top top then press the keys <A> <z> <a> <-> <a> <z> <a> <-> <a> and then as you don?t want to repeat this the next time: <W>

    <Shift + W>
    hfs · 2009-09-23 13:51:22 3
  • 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
  • One of my favorite ways to impress newbies (and old hats) to the power of the shell, is to give them an incredibly colorful and amazing version of the top command that runs once upon login, just like running fortune on login. It's pretty sweet believe me, just add this one-liner to your ~/.bash_profile -- and of course you can set the height to be anything, from 1 line to 1000! G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G Doesn't take more than the below toprc file I've added below, and you get all 4 top windows showing output at the same time.. each with a different color scheme, and each showing different info. Each window would normally take up 1/4th of your screen when run like that - TOP is designed as a full screen program. But here's where you might learn something new today on this great site.. By using the stty command to change the terminals internal understanding of the size of your terminal window, you force top to also think that way as well. # save the correct settings to G var. G=$(stty -g) # change the number of rows to half the actual amount, or 50 otherwise stty rows $((${LINES:-50}/2)) # run top non-interactively for 1 second, the output stays on the screen (half at least) top -n1 # reset the terminal back to the correct values, and clean up after yourself stty $G;unset G This trick from my [ bash_profile ], though the online version will be updated soon. Just think what else you could run like this! Note 1: I had to edit the toprc file out due to this site can't handle that (uploads/including code). So you can grab it from [ my site ] Note 2: I had to come back and edit again because the links weren't being correctly parsed Show Sample Output

    G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G
    AskApache · 2010-04-22 18:52:49 1
  • Like command 10870, but no need for sed

    top '-p' $(pgrep -d ' -p ' foo)
    __ · 2012-06-27 18:32:03 3
  • It displays the top 10 processes sorted by memory usage Show Sample Output

    ps aux | sort -rk 4,4 | head -n 10
    x3mboy · 2019-09-26 16:37:33 6
  • Top 10 Memory Processes (reduced output to applications and %usage only) Show Sample Output

    ps aux | sort -rk 4,4 | head -n 10 | awk '{print $4,$11}'
    n0a110w · 2019-10-20 22:52:55 26
  • This is useful if you use a shell with a lot of other users. You will be able to run "topu" to see your running processes instead of the complete 'top -u username'. Read more on alias:

    echo "alias topu='top -u USERNAME'" >> ~/.bash_aliases && source .bashrc
    TheLugal · 2011-07-07 08:24:06 0
  • 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 0
  • It repeats a command, such as free, every five seconds and highlights the differences

    watch -n 5 -d '/bin/free -m'
    mikhail · 2021-12-22 22:28:59 18
  • 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

  • 0
    function ptop(){ `ps -ef | grep $* | awk 'BEGIN{printf "top "}{printf "-p" $2 " " }'` }
    xcwen · 2012-09-13 02:43:57 0
  • This is a alternate command I like to use instead of TOP or HTOP to see what are the processes which are taking up the most memory on a system. It shows the username, process ID, CPU usage, Memory usage, thread ID, Number of threads associated with parent process, Resident Set Size, Virtual Memory Size, start time of the process, and command arguments. Then it's sorted by memory and showing the top 10 with head. This of course can be changed to suit you needs. I have a small system which is why Firefox is taking so much resources. Show Sample Output

    watch -n .8 'ps -eaLo uname,pid,pcpu,pmem,lwp,nlwp,rss,vsz,start_time,args --sort -pmem| head -10'
    ubercoo · 2016-05-11 01:05:53 1

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

Selecting a random file/folder of a folder
Also looks in subfolders

Kill all processes that don't belong to root/force logoff
explanation: grep -- displays process ids -v -- negates the matching, displays all but what is specified in the other options -u -- specifies the user to display, or in this case negate The process loops through all PIDs that are found by pgrep, then orders a forced kill to the processes in numerical order, effectively killing the parent processes first including the shells in use which will force the users to logout. Tested on Slackware Linux 12.2 and Slackware-current

Add fade in/out to first & last 25 frames of a video
Replace vid.mp4 with the path to your original video file, and out.mp4 to the path where you want to save the new file. To view the output first before saving, remove "-consumer avformat:out.mp4" from the end. Documentation for mlt framework and melt command can be found here:

Install pip with Proxy
Installs pip packages defining a proxy

Silently deletes lines containing a specific string in a bunch of files
This command will find all occurrences of one or more patterns in a collection of files and will delete every line matching the patterns in every file

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Numeric zero padding file rename
rename file name with fixed length nomeric format pattern

Inserts the results of an autocompletion in the command line
Pressing ESC then * will insert in the command line the results of the autocompletion. It's hard to explain but if you look the sample output or do $ echo ESC * you will understand quickly. By the way, few reminders about ESC : - Hold ESC does the same thing as tab tab - 'ESC .' inserts the last argument of last command (can be done many times in order to get the last argument of all previous commands)

Makes the permissions of file2 the same as file1
Also works with: $chgrp --reference file1 file2 $chown --reference file1 file2

make, or run a script, everytime a file in a directory is modified

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: