Top Command in batch mode

top -b -n 1
running top command in batch mode. it is usefull if you want to redirect the output in a file.
Sample Output
top - 11:15:25 up 17 days,  2:38,  2 users,  load average: 0.20, 0.15, 0.14
Tasks: 123 total,   1 running, 122 sleeping,   0 stopped,   0 zombie
Cpu(s):  5.8%us,  5.5%sy,  0.0%ni, 78.0%id, 10.3%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:   1027120k total,   613892k used,   413228k free,    40684k buffers
Swap:  1542200k total,    19252k used,  1522948k free,   179532k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                  
    1 root      20   0   864   72   40 S  0.0  0.0   0:07.44 init                                                     
    2 root      15  -5     0    0    0 S  0.0  0.0   0:00.02 kthreadd                                                 
    3 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0                                              
    4 root      15  -5     0    0    0 S  0.0  0.0   0:02.38 ksoftirqd/0                                              
    5 root      15  -5     0    0    0 S  0.0  0.0   0:15.28 events/0                                                 
    6 root      15  -5     0    0    0 S  0.0  0.0   0:10.24 khelper                                                  
    7 root      15  -5     0    0    0 S  0.0  0.0   2:26.59 kblockd/0                                                
    8 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kacpid                                                   
    9 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kacpi_notify                                             
   10 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 cqueue                                                   
   11 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kseriod                                                  
   12 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kondemand/0                                              
   15 root      15  -5     0    0    0 S  0.0  0.0   4:24.59 kswapd0                                                  
   16 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 aio/0                                                    
   17 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kpsmoused                                                
   61 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 scsi_eh_0                                                
   65 root      15  -5     0    0    0 S  0.0  0.0   0:37.53 ata/0                                                    
   66 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 ata_aux                                                  
   72 root      15  -5     0    0    0 S  0.0  0.0   0:17.98 scsi_eh_1                                                
   73 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 scsi_eh_2                                                
  304 postfix   20   0 45376 2316 1796 S  0.0  0.2   0:00.04 pickup                                                   
  425 root      15  -5     0    0    0 S  0.0  0.0   2:38.72 kjournald                                                
  489 root      16  -4 12428  348  344 S  0.0  0.0   0:00.54 udevd                                                    
  919 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kauditd                                                  
  933 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kstriped                                                 
 1027 postfix   20   0 48184 3344 2196 S  0.0  0.3   0:00.06 cleanup                                                  
 1035 postfix   20   0 45596 2912 2188 S  0.0  0.3   0:00.02 local                                                    
 1268 messageb  20   0 14872  816  604 S  0.0  0.1   0:04.36 dbus-daemon                                              
 1281 root      20   0 14328  544  540 S  0.0  0.1   0:00.00 resmgrd                                                  
 1291 root      20   0  3824  460  456 S  0.0  0.0   0:00.00 acpid                                                    
 1320 root      20   0 32956 1152  944 S  0.0  0.1   0:01.18 console-kit-dae                                          
 1396 haldaemo  20   0 33128 1408 1036 S  0.0  0.1   0:03.86 hald                                                     
 1397 root      20   0 17804  588  584 S  0.0  0.1   0:00.00 hald-runner                                              
 1408 root      20   0 24056  556  552 S  0.0  0.1   0:00.00 hald-addon-inpu                                          
 1411 haldaemo  20   0 20776  624  620 S  0.0  0.1   0:00.00 hald-addon-acpi                                          
 1413 root      20   0 24060  636  560 S  0.0  0.1   0:22.00 hald-addon-stor                                          
 1419 root      20   0 24060  628  560 S  0.0  0.1   0:01.44 hald-addon-stor                                          
 1903 root      15  -5     0    0    0 S  0.0  0.0   0:00.08 cifsoplockd                                              
 1904 root      15  -5     0    0    0 S  0.0  0.0   0:00.26 cifsdnotifyd                                             
 1909 root      15  -5     0    0    0 S  0.0  0.0   4:47.62 cifsd                                                    
 2000 root      20   0 87628 3352 2524 S  0.0  0.3   0:00.00 sshd                                                     
 2006 root      20   0 23456 2536 1708 S  0.0  0.2   0:00.02 bash                                                     
 2042 root      20   0 16796 1172  852 R  0.0  0.1   0:00.00 top                                                      
 2065 root      20   0  4092  340  336 S  0.0  0.0   0:26.46 klogd                                                    
 2066 root      20   0 18892  784  608 S  0.0  0.1   0:55.01 syslog-ng                                                
 2080 bin       20   0  5904  332  328 S  0.0  0.0   0:00.00 portmap                                                  
 2089 avahi     20   0 27652 1128 1016 S  0.0  0.1   0:01.14 avahi-daemon                                             
 2152 root      20   0 10156  408  404 S  0.0  0.0   0:00.00 avahi-dnsconfd                                           
 2192 root      20   0 29768  824  716 S  0.0  0.1   0:00.54 powersaved                                               
 2195 ntp       20   0 25400  964  852 S  0.0  0.1   0:09.36 ntpd                                                     
 2199 root      20   0 64952 1316 1312 S  0.0  0.1   0:00.00 cupsd                                                    
 2204 root      20   0 62120  772  652 S  0.0  0.1   0:06.22 sshd                                                     
 2265 root      20   0 17036  984  824 S  0.0  0.1  20:07.96 vmware-guestd                                            
 2371 root      20   0 37896 1812 1692 S  0.0  0.2   0:45.59 master                                                   
 2395 postfix   20   0 39980 2012 1784 S  0.0  0.2   0:41.51 qmgr                                                     
 2425 root      20   0 52380 1628 1064 S  0.0  0.2   0:15.12 miniserv.pl                                              
 2436 root      20   0 12420  568  480 S  0.0  0.1   0:04.42 cron                                                     
 2469 zabbix    25   5  1944  188  172 S  0.0  0.0   0:00.00 zabbix_agentd                                            
 2473 zabbix    25   5  1944  316  280 S  0.0  0.0   8:51.49 zabbix_agentd                                            
 2474 zabbix    25   5  1952  428  348 S  0.0  0.0   2:03.51 zabbix_agentd                                            
 2475 zabbix    25   5  1952  416  336 S  0.0  0.0   2:05.36 zabbix_agentd                                            
 2476 zabbix    25   5  1952  416  336 S  0.0  0.0   2:03.58 zabbix_agentd                                            
 2477 zabbix    25   5  2004  292  236 S  0.0  0.0   0:01.76 zabbix_agentd                                            
 2545 root      20   0 65760 1068 1064 S  0.0  0.1   0:00.20 login                                                    
 2547 root      20   0  4316  604  600 S  0.0  0.1   0:00.10 mingetty                                                 
 2549 root      20   0  4316  584  580 S  0.0  0.1   0:00.00 mingetty                                                 
 2551 root      20   0  4316  584  580 S  0.0  0.1   0:00.00 mingetty                                                 
 2553 root      20   0  4316  584  580 S  0.0  0.1   0:00.00 mingetty                                                 
 2561 root      20   0  4316  584  580 S  0.0  0.1   0:00.00 mingetty                                                 
14332 root      20   0     0    0    0 S  0.0  0.0   0:02.20 pdflush                                                  
15764 root      20   0  392m 9.9m 5772 S  0.0  1.0   0:19.96 httpd2-prefork                                           
16237 root      20   0     0    0    0 S  0.0  0.0   0:31.00 pdflush                                                  
29756 root      20   0 23476 1440 1436 S  0.0  0.1   0:00.06 bash                                                     
32293 wwwrun    20   0  395m  16m 9640 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32294 wwwrun    20   0  408m  35m  16m S  0.0  3.6   0:00.24 httpd2-prefork                                           
32295 wwwrun    20   0  401m  27m  15m S  0.0  2.7   0:00.08 httpd2-prefork                                           
32296 wwwrun    20   0  399m  24m  13m S  0.0  2.4   0:00.24 httpd2-prefork                                           
32297 wwwrun    20   0  395m  16m 9932 S  0.0  1.6   0:00.04 httpd2-prefork                                           
32298 wwwrun    20   0  410m  51m  30m S  0.0  5.1   0:00.36 httpd2-prefork                                           
32299 wwwrun    20   0  398m  23m  14m S  0.0  2.4   0:00.14 httpd2-prefork                                           
32300 wwwrun    20   0  395m  16m 9.8m S  0.0  1.6   0:00.02 httpd2-prefork                                           
32301 wwwrun    20   0  395m  15m 9644 S  0.0  1.6   0:00.00 httpd2-prefork                                           
32302 wwwrun    20   0  395m  16m 9636 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32303 wwwrun    20   0  396m  21m  13m S  0.0  2.1   0:00.08 httpd2-prefork                                           
32304 wwwrun    20   0  395m  16m 9636 S  0.0  1.6   0:00.04 httpd2-prefork                                           
32305 wwwrun    20   0  398m  25m  16m S  0.0  2.5   0:00.16 httpd2-prefork                                           
32306 wwwrun    20   0  395m  16m 9.8m S  0.0  1.6   0:00.04 httpd2-prefork                                           
32307 wwwrun    20   0  400m  26m  15m S  0.0  2.6   0:00.08 httpd2-prefork                                           
32308 wwwrun    20   0  392m 5080  732 S  0.0  0.5   0:00.00 httpd2-prefork                                           
32309 wwwrun    20   0  396m  18m  11m S  0.0  1.8   0:00.06 httpd2-prefork                                           
32310 wwwrun    20   0  395m  15m 9636 S  0.0  1.6   0:00.00 httpd2-prefork                                           
32311 wwwrun    20   0  400m  24m  13m S  0.0  2.4   0:00.34 httpd2-prefork                                           
32312 wwwrun    20   0  396m  17m  10m S  0.0  1.7   0:00.06 httpd2-prefork                                           
32313 wwwrun    20   0  395m  16m 9992 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32314 wwwrun    20   0  399m  30m  22m S  0.0  3.0   0:00.46 httpd2-prefork                                           
32315 wwwrun    20   0  395m  16m 9640 S  0.0  1.6   0:00.04 httpd2-prefork                                           
32316 wwwrun    20   0  396m  18m  11m S  0.0  1.9   0:00.04 httpd2-prefork                                           
32317 wwwrun    20   0  400m  25m  14m S  0.0  2.5   0:00.06 httpd2-prefork                                           
32318 wwwrun    20   0  400m  26m  15m S  0.0  2.6   0:00.14 httpd2-prefork                                           
32319 wwwrun    20   0  396m  17m  10m S  0.0  1.8   0:00.08 httpd2-prefork                                           
32320 wwwrun    20   0  400m  25m  14m S  0.0  2.5   0:00.08 httpd2-prefork                                           
32321 wwwrun    20   0  392m 5476 1112 S  0.0  0.5   0:00.00 httpd2-prefork                                           
32322 wwwrun    20   0  395m  15m 9636 S  0.0  1.6   0:00.00 httpd2-prefork                                           
32323 wwwrun    20   0  399m  24m  14m S  0.0  2.5   0:00.04 httpd2-prefork                                           
32324 wwwrun    20   0  395m  16m 9636 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32325 wwwrun    20   0  399m  26m  16m S  0.0  2.7   0:00.20 httpd2-prefork                                           
32326 wwwrun    20   0  395m  16m 9636 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32327 wwwrun    20   0  397m  19m  11m S  0.0  1.9   0:00.04 httpd2-prefork                                           
32328 wwwrun    20   0  395m  16m   9m S  0.0  1.6   0:00.02 httpd2-prefork                                           
32329 wwwrun    20   0  395m  16m 9924 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32330 wwwrun    20   0  399m  23m  14m S  0.0  2.4   0:00.12 httpd2-prefork                                           
32331 wwwrun    20   0  395m  15m 9640 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32332 wwwrun    20   0  398m  26m  17m S  0.0  2.7   0:00.34 httpd2-prefork                                           
32333 wwwrun    20   0  396m  18m  11m S  0.0  1.8   0:00.02 httpd2-prefork                                           
32334 wwwrun    20   0  395m  16m 9.9m S  0.0  1.7   0:00.06 httpd2-prefork                                           
32335 wwwrun    20   0  402m  36m  25m S  0.0  3.7   0:00.74 httpd2-prefork                                           
32336 wwwrun    20   0  398m  23m  14m S  0.0  2.3   0:00.06 httpd2-prefork                                           
32337 wwwrun    20   0  395m  16m 9996 S  0.0  1.6   0:00.02 httpd2-prefork                                           
32338 wwwrun    20   0  396m  17m  10m S  0.0  1.7   0:00.02 httpd2-prefork                                           
32339 wwwrun    20   0  398m  23m  14m S  0.0  2.3   0:00.10 httpd2-prefork                                           
32340 wwwrun    20   0  395m  15m 9644 S  0.0  1.6   0:00.00 httpd2-prefork                                           
32341 wwwrun    20   0  397m  24m  16m S  0.0  2.5   0:00.12 httpd2-prefork                                           
32342 wwwrun    20   0  395m  16m 9.9m S  0.0  1.6   0:00.02 httpd2-prefork

2
By: r00t4u
2010-01-24 16:17:30
top

These Might Interest You

  • If shell escaping of the command is problematic, you can write the command to a file first: batch <somefile Or read it: read -re && echo "$REPLY" | batch Or, if your shell supports it, you can eliminate echo: read -re && batch <<<$REPLY ("man batch" lists 1.5 for me, but I don't know how widely it differs.)


    9
    echo 'some command' | batch
    kniht · 2010-07-14 03:08:31 0
  • This is a command to be used inside of MS-DOS batch files to check existence of commands as preconditions before actual batch processing can be started. If the command is found, batch script continues execution. If not, a message is printed on screen, script then waits for user pressing a key and exits. An error message of the command itself is suppressed for clarity purpose. Show Sample Output


    2
    <command> >NUL 2>&1 || ( echo <Command> not found. Please install <command> or check PATH variable! & pause & exit )
    Marco · 2011-03-07 14:27:42 2
  • Need to query hundreds of hosts with an ssh command ? Of course you'll have setup keys on all your remote HOSTs. But in the case a key is not present this command will skip that node, proceeding on to the next. -t: Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine. Also prevents unwanted stty messages being sent to console -q: Quiet mode. -o "BatchMode yes" If set to yes, passphrase/password querying will be disabled. This option is useful in scripts and other batch jobs where no user is present Show Sample Output


    1
    ssh -tq -o "BatchMode yes" $HOST <some_command> >> to_a_file
    jp · 2011-03-02 20:33:59 0
  • Crude, but works. Note for security, /data/ will be inaccessible unless your device has been *rooted*. On the other hand, if a device has been rooted, its data is now wide open to anyone with a USB cable and the above "one-liner". `adb` is one of the platform tools in the android SDK. To get SMS messages: adb pull /data/data/com.android.providers.telephony/databases/mmssms.db ; sqlite3 -batch <<EOF contacts2.db <CR> .header on <CR> .mode tabs <CR> select * from sms; <CR> EOF


    2
    adb pull /data/data/com.android.providers.contacts/databases/contacts2.db ; sqlite3 -batch <<EOF contacts2.db <CR> .header on <CR> .mode tabs <CR> select * from data; <CR> EOF
    mhs · 2012-12-26 11:35:23 0

What Others Think

very useful, thanks! +1
0disse0 · 378 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

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



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: