Detailed description on how to customize and save the top output information
Last Update:2014-05-20
Source: Internet
Author: User
For more information about the importance and usage of top commands, see how to save the output information of top commands. The method for saving the output of the top command to a file is: top-n1b>topinfo.txt. this is not curious, but the output... for more information about the importance and usage of top commands, see how to save the output information of top commands. The method for saving the output of the top command to a file is: top-n1b> topinfo.txt, which is not curious, but the output information format is default. [Root @ localhost ~] # Top-n1b> topinfo.txt [root @ localhost ~] # Cat topinfo.txt top-14:14:18 up, 3 users, load average: 0.00, 0.02, 0.44 Tasks: 70 total, 1 running, 69 sleeping, 0 stopped, 0 zombieCpu (s ): 2.4% us, 2.7% sy, 0.1% ni, 94.1% id, 0.4% wa, 0.0% hi, 0.3% si, 0.0% stMem: 1035140 k total, 903792 k used, 131348 k free, 236160 k buffersSwap: 2097144 k total, 0 k used, 2097144 k free, 545312 k cached pid user pr ni virt res shr s % CPU % mem time + COMMAND 1 root 15 0 2072 588 504 S 0.0 0.1. 97 init 2 root RT-5 0 0 0 S 0.0 0: 00. 00 migration/0 3 root 39 19 0 0 0 S 0.0 0: 00. 07 ksoftirqd/0 4 root RT-5 0 0 0 S 0.0 0.0. 01 watchdog/0 5 root 10-5 0 0 0 S 0.0 0: 00. 20 events/0 6 root 10-5 0 0 0 S 0.0 0: 00. 00 khelper 7 root 12-5 0 0 0 S 0.0 0.0. 05 kthread 10 root 10-5 0 0 0 S 0.0 0.0. 65 kblockd/0 11 root 20-5 0 0 0 S 0.0 0.0 0: 00.00 kacpid 179 root 18-5 0 0 0 S 0.0 0: 00. 00 cqueue/0 182 root 10-5 0 0 0 S 0.0 0: 00. 00 khubd 184 root 19-5 0 0 0 S 0.0 0: 00. 00 kseriod 249 root 15 0 0 0 S 0.0 0.0. 10 pdflush 250 root 20-5 0 0 0 S 0.0 0: 00. 00 kswapd0 251 root 20-5 0 0 0 S 0.0 0: 00. 00 aio/0 473 root 11-5 0 0 0 S 0.0 0: 00. 00 kpsmoused 497 root 16-5 0 0 0 S 0.0 0: 00. 00 ata/0 498 root 16-5 0 0 0 S 0.0 0.0. 00 ata_aux 509 root 10-5 0 0 0 S 0.0 0.0. 08 mpt_poll_0 510 root 20-5 0 0 0 S 0.0 0: 00. 00 scsi_eh_0 513 root 20-5 0 0 S 0.0 0.0. 00 kstriped 522 root 20-5 0 0 S 0.0 0.0. 00 ksnapd 533 root 10-5 0 0 0 S 0.0 0 07. 86 kjournald 564 root 11-5 0 0 0 S 0.0 0: 00. 00 kauditd 597 root 21-4 3080 1640 492 S 0.0 0: 00. 60 udevd 1290 root 20-5 0 0 0 S 0. 0 0.0. 00 kgameportd 2170 root 20-5 0 0 0 S 0.0 0: 00. 00 kmpathd/0 2171 root 20-5 0 0 0 S 0.0 0: 00. 00 kmpath_handlerd 2195 root 10-5 0 0 0 S 0.0 0.0. 00 kjournald 2416 root 18 0 2168 512 S 396 0.0. 23 mcstransd 2648 root 15 0 2316 712 S 412 0.0. 07 dhclient 2805 root 16 0 11584 9952 S 240 0.0. 01 restorecond 2819 root 18 0 1728 576 480 S 0.0 0: 00. 03 s Yslogd 2822 root 15 0 1680 392 S 328 0.0. 00 klogd 2861 running 18 0 12996 1072 S 844 0.0. 04 audio-daemon 2907 root 24 0 12728 1356 604 S 0.0 0: 02. 66 pcscd 2921 haldaemo 15 0 6464 4536 1688 S 0.0 0: 03. 72 hald 2922 root 18 0 3156 1076 S 916 0.0. 00 hald-runner 2930 haldaemo 18 0 2020 812 716 S 0.0 0: 00. 00 hald-addon-acpi 2943 haldaemo 15 0 2020 820 720 S 0.0 0: 0 0.00 hald-addon-keyb 2952 root 18 0 1976 768 684 S 0.0. 22 hald-addon-stor 2985 root 25 0 1916 452 372 S 0.0 0: 00. 00 hidd 3010 root 18 0 103 m 792 544 S 0.0 0: 00. 04 tgtd 3011 root 18 0 3304 340 S 140 0.0. 18 tgtd 3049 root 24 0 5140 764 S 520 0.0. 00 hpiod 3054 root 15 0 13444 4808 S 1020 0.0. 16 python 3072 root 15 0 7068 1064 S 668 0.0. 01sshd 3193 Root 15 0 1900 472 392 S 0.0 0.0. 00 gpm 3207 root 18 0 5296 1184 S 648 0.0. 11 crond 3221 root 18 0 14436 2216 S 1420 0.0. 01 smbd 3224 root 15 0 9408 1368 S 912 0.0. 28 nmbd 3265 root 18 0 14436 1076 S 280 0.0. 00 smbd 3276 root 18 0 3508 464 S 284 0.0. 00 smartd 3280 root 16 0 2892 1304 S 996 0.0. 12 login 3281 root 16 0 1664 440 384 S 0.0 0. 0 0: 00. 00 mingetty 3284 root 20 0 1664 444 S 384 0.0. 00 mingetty 3289 root 18 0 1664 444 S 384 0.0. 00 mingetty 3297 root 18 0 1664 448 S 384 0.0. 00 mingetty 3300 root 18 0 1664 448 S 384 0.0. 00 mingetty 3336 root 34 19 25664 10 m 2152 S 0.0 0: 00. 15 yum-updatesd 3338 root 34 19 2560 1184 984 S 0.0 0: 00. 32 gam_server 3339 root 17 0 4632 1492 1224 S 0.0 0.1 0: 00. 03 bash 7387 root 15 0 0 0 S 0.0 0.0. 20 pdflush 9219 root 25 0 4536 1260 S 1100 0.0. 00 mysqld_safe 9269 mysql 15 0 134 m 18 m 4488 S 0.0 0: 01. 26 mysqld 10548 root 15 0 9924 2856 S 2296 0.0. 42 sshd 10550 root 15 0 4640 1452 S 1184 0.0. 03 bash 10684 root 18 0 10084 2868 S 2296 0.0. 52 sshd 10686 root 15 0 4640 1504 S 1228 0.0. 05 bash 11432 ro Ot 15 0 2200 872 692 R 0.0 0.1. 00 top [root @ localhost ~] # How do I modify these default settings? For example, the process in the output result only contains cmd, pid, % cpu, and % mem. Script is cumbersome and cannot be implemented. for example, the stored information contains the load information of each cpu. The following is the step for modifying the default settings of top-n1b output: Step 1: execute the top command top-14:16:56 up, 3 users, load average: 0.07, 0.02, 0.38 Tasks: 70 total, 2 running, 68 sleeping, 0 stopped, 0 zombieCpu (s): 0.0% us, 0.0% sy, 0.0% ni, 99.7% id, 0.0% wa, 0.0% hi, 0.3% si, 0.0% stMem: 1035140 k total, 904040 k used, 131100 k free, 236368 k buffersSwap: 2097144 k total, 0 k used, 2097144 k free, 545320 k cached pid user pr ni virt res shr s % CPU % MEM TIME + COMMAND 11434 root 18 0 2204 988 R 804 0.3. 04 top 1 root 15 0 2072 588 S 504 0.0. 97 init 2 root RT-5 0 0 0 S 0.0 0: 00. 00 migration/0 3 root 34 19 0 0 0 S 0.0 0: 00. 07 ksoftirqd/0 4 root RT-5 0 0 0 S 0.0 0.0. 01 watchdog/0 5 root 10-5 0 0 0 S 0.0 0: 00. 20 events/0 6 root 10-5 0 0 0 S 0.0 0: 00. 00 khelper 7 root 12-5 0 0 0 S 0.0 0.0. 05 kthread 10 root 1 0-5 0 0 0 S 0.0 0.0. 65 kblockd/0 11 root 20-5 0 0 0 S 0.0 0: 00. 00 kacpid 179 root 18-5 0 0 0 S 0.0 0.0. 00 cqueue/0 182 root 10-5 0 0 0 S 0.0 0: 00. 00 khubd 184 root 19-5 0 0 0 S 0.0 0: 00. 00 kseriod 249 root 15 0 0 0 S 0.0 0.0. 10 pdflush 250 root 20-5 0 0 0 S 0.0 0: 00. 00 kswapd0 251 root 20-5 0 0 0 S 0.0 0: 00. 00 aio/0 Step 2: modify the output format. here I demonstrate: display the information of each cpu, and the process section only displays cm D, pid, % cpu, % mem. Press 1 top-14:19:11 up, 3 users, load average: 0.00, 0.01, 0.32 Tasks: 70 total, 1 running, 69 sleeping, 0 stopped, 0 zombieCpu0: 0.1% us, 0.1% sy, 0.0% ni, 99.4% id, 0.0% wa, 0.1% hi, 0.2% si, 0.0% stMem: 1035140 k total, 904164 k used, 130976 k free, 236552 k buffersSwap: 2097144 k total, 0 k used, 2097144 k free, 545320 k cached pid user pr ni virt res shr s % CPU % mem time + COMMAND 11434 root 18 0 2204 988 804 R 0.3 0.1 0: 00. 22 top 1 root 15 0 2072 588 S 504 0.0. 97 init 2 root RT-5 0 0 0 S 0.0 0: 00. 00 migration/0 3 root 34 19 0 0 0 S 0.0 0: 00. 07 ksoftirqd/0 4 root RT-5 0 0 0 S 0.0 0.0. 01 watchdog/0 5 root 10-5 0 0 0 S 0.0 0: 00. 20 events/0 6 root 10-5 0 0 0 S 0.0 0: 00. 00 khelper 7 root 12-5 0 0 0 S 0.0 0.0. 05 kthread 10 root 10-5 0 0 0 S 0.0 0.0. 65 kblockd/0 11 root 20-5 0 0 0 S 0.0 0: 00. 00 kacpid 179 root 18-5 0 0 0 S 0.0 0.0. 00 cqueue/0 182 root 10-5 0 0 0 S 0.0 0: 00. 00 khubd 184 root 19-5 0 0 0 S 0.0 0: 00. 00 kseriod 249 root 15 0 0 0 S 0.0 0.0. 10 pdflush 250 root 20-5 0 0 0 S 0.0 0: 00. 00 kswapd0 251 root 20-5 0 0 0 S 0.0 0: 00. 00 aio/0 press f: Current Fields: AEHIOQTWKNMbcdfgjplrsuvyzX for window 1: DefToggle fields via field letter, type any other key to return * A: PID = Process Id s: DATA = Data + Stack size (kb) 0x00100000 PF_USEDFPU (thru 2.4) * H: PR = Priority v: mcm t = Dirty Pages count * I: NI = Nice value y: WCHAN = Sleeping in Function * O: VIRT = Virtual Image (kb) z: Flags = Task Flags * Q: RES = Resident size (kb) * X: COMMAND = Command name/line * T: SHR = Shared Mem size (kb) * W: S = Process Status Flags field: * K: % CPU = CPU usage 0x00000001 PF_ALIGNWARN * N: % MEM = Memory usage (RES) 0x00000002 PF_STARTING * M: TIME + = CPU Time, hundredths 0x00000004 PF_EXITING B: PPID = Parent Process Pid 0x00000040 PF_FORKNOEXEC c: RUSER = Real user name 0x00000100 PF_SUPERPRIV d: UID = User Id 0x00000200 PF_DUMPCORE f: GROUP Name 0x00000400 PF_SIGNALED g: TTY = Controlling Tty 0x00000800 PF_MEMALLOC j: P = Last used cpu (SMP) 0x00002000 PF_FREE_PAGES (2.5) p: SWAP = Swapped size (kb) 0x00008000 debug flag (2.5) l: TIME = CPU Time 0x00024000 special threads (2.5) r: CODE = Code size (kb) 0x001D0000 special states (2.5) custom output information, by A, H, I, O, Q, T, W remove unnecessary information: top-14:22:29 up :58, 3 Users, load average: 0.00, 0.00, 0.25 Tasks: 70 total, 1 running, 69 sleeping, 0 stopped, 0 zombieCpu0: 0.1% us, 0.2% sy, 0.5% ni, 98.7% id, 0.0% wa, 0.0% hi, 0.4% si, 0.0% stMem: 1035140 k total, 905032 k used, 130108 k free, 236828 k buffersSwap: 2097144 k total, 0 k used, 2097144 k free, 545320 k cached USER % CPU % mem time + COMMAND root 0.0 0.1. 97 init root 0.0 0.0. 00 migration/0 root 0.0 0.0. 07 Ksoftirqd/0 root 0.0 0.0. 01 watchdog/0 root 0.0 0.0. 21 events/0 root 0.0 0.0. 00 khelper root 0.0 0.0. 05 kthread root 0.0 0.0. 65 kblockd/0 root 0.0 0.0. 00 kacpid root 0.0 0.0. 00 cqueue/0 root 0.0 0.0. 00 khubd root 0.0 0.0. 00 kseriod root 0.0 0.0. 10 pdflush root 0.0 0.0. 00 kswapd0 root 0.0 0.0. 00 aio/0 root 0.0 0.0. 00 kpsmoused press W to save the settings Set in ~ /. Toprc. Press q to exit the top command. now run top-n1b. try the result: [root @ localhost ~]. # Top-n1b> topinfo.txt [root @ localhost ~] # Cat topinfo.txt top-14:24:37 up, 3 users, load average: 0.00, 0.00, 0.22 Tasks: 70 total, 1 running, 69 sleeping, 0 stopped, 0 zombieCpu0: 2.4% us, 2.6% sy, 0.1% ni, 94.2% id, 0.4% wa, 0.0% hi, 0.3% si, 0.0% stMem: 1035140 k total, 905032 k used, 130108 k free, 237004 k buffersSwap: 2097144 k total, 0 k used, 2097144 k free, 545316 k cached USER % CPU % mem time + COMMAND root 0.0 0.1. 97 init root 0.0 0.0. 00 migration/0 root 0.0 0.0. 07 ksoftirqd/0 root 0.0 0.0. 01 watchdog/0 root 0.0 0.0. 21 events/0 root 0.0 0.0. 00 khelper root 0.0 0.0. 05 kthread root 0.0 0.0. 65 kblockd/0 root 0.0 0.0. 00 kacpid root 0.0 0.0. 00 cqueue/0 root 0.0 0.0. 00 khubd root 0.0 0.0. 00 kseriod root 0.0 0.0. 10 pdflush root 0.0 0.0. 00 kswapd0 root 0.0 0.0. 00 Aio/0 root 0.0 0.0. 00 kpsmoused root 0.0 0.0. 00 ata/0 root 0.0 0.0. 00 ata_aux root 0.0 0.0. 08 mpt_poll_0 root 0.0 0.0. 00 scsi_eh_0 root 0.0 0.0. 00 kstriped root 0.0 0.0. 00 ksnapd root 0.0 0.0. 93 kjournald root 0.0 0.0. 00 kauditd root 0.0 0.2. 60 udevd root 0.0 0.0. 00 kgameportd root 0.0 0.0. 00 kmpathd/0 root 0.0 0.0. 00 kmpath_handler D root 0.0 0.0. 00 kjournald root 0.0 0.0. 23 mcstransd root 0.0 0.1. 07 dhclient root 0.0 1.0. 01 restorecond root 0.0 0.1. 03 syslogd root 0.0 0.0. 00 klogd limit 0.0 0.1. 04 success-daemon root 0.0 0.1. 69 pcscd haldaemo 0.0 0.4. 74 hald root 0.0 0.1. 00 hald-runner haldaemo 0.0 0.1. 00 hald-addon-acpi haldaemo 0.0 0.1. 00 hald-addon-keyb root 0.0 0.1 0: 23. 44 hald-addon-stor root 0.0 0.0. 00 hidd root 0.0 0.1. 04 tgtd root 0.0 0.0. 18 tgtd root 0.0 0.1. 00 hpiod root 0.0 0.5. 16 python root 0.0 0.1. 01 sshd root 0.0 0.0. 00 gpm root 0.0 0.1. 11 crond root 0.0 0.2. 01 smbd root 0.0 0.1. 29 nmbd root 0.0 0.1. 00 smbd root 0.0 0.0. 00 smartd root 0.0 0.1. 12 login root 0.0 0.0. 00 mingetty r Oot 0.0 0: 00. 00 mingetty root 0.0 0.0. 00 mingetty root 0.0 0.0. 00 mingetty root 0.0 0.0. 00 mingetty root 0.0 1.0. 16 yum-updatesd root 0.0 0.1. 32 gam_server root 0.0 0.1. 03 bash root 0.0 0.0. 20 pdflush root 0.0 0.1. 00 mysqld_safe mysql 0.0 1.8. 27 mysqld root 0.0 0.3. 60 sshd root 0.0 0.1. 04 bash root 0.0 0.3. 52 sshd root 0.0 0.1. 05 Bash root 0.0 0.1. 00 top [root @ localhost ~] # This method is easier for a single machine. if it is batch deployment, you need to copy files, which is complicated.