newbie: System Monitoring commands - du, df, ps, top, who, w, free. Date: 24-Dec-99 Author: cogNiTioN <cognition@bigfoot.com> System Monitoring Commands This file goes through some commands that can let you know what your system is doing. Using these commands you can tell what programs are running, how much memory or how many cpu cycles those programs are using, who's logged in, where from, how long they've been logged in for and more. These commands also deal with how much disk space or memory is being used. Bear in mind that this is not a detailed look at each command, it is an overview only. ------------------------------------------------------------------------- Command: du This command prints the disk usage (in Kb) of each directory and it's sub directories. By default it starts from the current directory, but supplying the name of a directory after the command will make it start from that directory. cognition@pingu:/usr/cog $ du 126 ./Mail/.archived/.pgp 18851 ./Mail/.archived 21016 ./Mail 2247 ./zip 80 ./.pgp 15 ./develop/getmail/bup 35 ./develop/getmail 36 ./develop 2300 ./.procmail ~~ <SNIPPED FULL OUTPUT OF COMMAND, FOR BREVITY> ~~ 31678 . cognition@pingu:/usr/cog $ du Mail 126 Mail/.archived/.pgp 18851 Mail/.archived 21016 Mail cognition@pingu:/usr/cog $ du /root du: /root: Permission denied As the last example shows, you can only show the disk usage for directories (or subdirectories) that you have execute permissions on. Options: (these may vary depending on version run, and there are more ;) -a (--all) Prints usage for ALL files, not just the subdirectories -b (--bytes) Prints usage in bytes rather than Kb. -s (--summarize) Prints ONLY the total usage of the directory Consult 'man du' for more details on usage ------------------------------------------------------------------------- Command: df This command tells you the amount of free space on all mounted file systems, or you can specify the name of a device you want to check, (the device has to be mounted, though). cognition@pingu:/usr/cog $ df Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hdb1 483038 358274 99816 78% / /dev/hda1 246854 14293 219812 6% /home /dev/sda4 98078 96752 1326 99% /zip cognition@pingu:/usr/cog $ df /dev/hdb1 Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hdb1 483038 358274 99816 78% / I currently have 3 file systems mounted (2 internal Hard Discs and a zip disc). The second column (labeled 1024-blocks) shows the total size (in Kb) of the corresponding file system, the third column shows how much space has been used, column four gives the remaining space and column five (Capacity) shows (as a percentage how much of the space has been used. The last column simply shows the mount point of that file system. for more information see 'man df' ------------------------------------------------------------------------- Command: ps 'ps' shows you what processes (programs) you have running (or are running with your user id). cognition@pingu:/usr/cog $ ps PID TTY STAT TIME COMMAND 32042 1 S 0:04 -bash 32068 2 S 0:04 (bash) 32168 2 S 1:07 vi admin101 32415 2 S 0:00 /bin/bash -c (ps) >/tmp/voa32168 2>&1 32416 2 R 0:00 ps It's interesting to note the second line up from the bottom; that's what vi sends out when I get it to execute a command for me. Note: When using options with ps, you do not need to include a leading '-' sign, while this is still accepted, it's use is "deprecated". A good set of options to use is 'aux'. The command 'ps aux' gives you a surplus of information about all the processes running on your system. Note you do not need to be 'root' to run 'ps aux', you can do so as a normal user and still get a full listing of processes. The output from 'ps aux' is similar to that from the 'top' command, which is covered below, except that 'ps aux' is a snap shot, and is not updated. See 'man ps' for more information. ------------------------------------------------------------------------- Command: who As Unix is a multi-user operating system, there can be more than one person using the machine at any given time. How do you find out how many users your system currently has? You ask the system, that's how. The 'who' command shows you who has logged in, where they're logged into and when they logged in. cognition@pingu:/usr/cog $ who cognitio tty1 Sep 6 14:23 cognitio tty2 Sep 6 18:01 root tty5 Sep 6 18:18 'who' can also tell you who you are, when run as 'who am i', this is the same as the command 'whoami'. For more information, including other options, see 'man who' ------------------------------------------------------------------------- Command: w The 'w' command is really the output of 'uptime', 'who' and 'ps a' combined to give a comprehensive system usage summary. To give the usage of one user, just give the user's name after the command. cognition@pingu:/usr/cog $ w 9:29pm up 45 days, 9:59, 4 users, load average: 1.06, 0.97, 0.92 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT cognitio tty1 2:23pm 1:54 6.01s 0.70s -bash cognitio tty2 6:01pm 3.00s 1:45 1:39 vi admin101 root tty5 6:18pm 36:09 4.35s 4.35s -bash cognition@pingu:/usr/cog $ w root 9:29pm up 45 days, 10:00, 4 users, load average: 1.16, 1.01, 0.93 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty5 6:18pm 36:56 4.35s 4.35s -bash Notice that most entries don't have an entry in the FROM column, this indicates that they're logged on from the console (i.e. they have physical access to the machine). See 'man w' for more details. ------------------------------------------------------------------------- Command: free 'free' shows you information about the machine's memory. This includes physical memory (RAM), swap as well as the shared memory and buffers used by the kernal. All measurements are in Kb. cognition@pingu:/usr/cog $ free total used free shared buffers cached Mem: 10672 10168 504 4912 172 3000 -/+ buffers/cache: 6996 3676 Swap: 33228 18068 15160 For more information, and a list of options, see 'man free' ------------------------------------------------------------------------- Command: top 'top' provides lots of information on the processes running, including the percentage of the cpu and the memory being consumed by that process, who 'owns' the process and it's pid (Process ID), it also shows the output of 'uptime' and a summary of memory usage, similar to 'free'. The output of 'top' is full screen, and refreshes itself frequently (or at user definable intervals). Here is a representation of the output from 'top': cognition@pingu:/usr/cog $ top 11:42pm up 45 days, 12:13, 9 users, load average: 1.66, 1.52, 1.20 66 processes: 64 sleeping, 2 running, 0 zombie, 0 stopped CPU states: 84.5% user, 36.1% system, 0.0% nice, 0.0% idle Mem: 10672K av, 10276K used, 396K free, 5660K shrd, 212K buff Swap: 33228K av, 18976K used, 14252K free 2556K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 216 root 10 0 376 324 192 S 0 32.5 3.0 13267m top 32609 cognitio 9 0 584 584 420 S 0 31.7 5.4 0:29 top 213 root 20 0 696 596 124 R 0 28.5 5.5 28197m smartbee 32612 cognitio 15 0 580 580 416 R 0 26.6 5.4 0:03 top 32469 root 1 0 208 112 88 S 0 0.7 1.0 0:15 in.telnetd 3 root -12 -12 0 0 0 SW< 0 0.1 0.0 3:19 kswapd 15 root 0 0 84 48 32 S 0 0.1 0.4 18:06 update 32468 cognitio 0 0 204 108 72 S 0 0.1 1.0 0:16 telnet 1 root 0 0 88 48 24 S 0 0.0 0.4 0:19 init 2 root 0 0 0 0 0 SW 0 0.0 0.0 1:01 kflushd 4 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 nfsiod 5 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 nfsiod 6 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 nfsiod 7 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 nfsiod 32042 cognitio 0 0 448 32 32 S 0 0.0 0.2 0:05 bash 32068 cognitio 0 0 408 0 0 SW 0 0.0 0.0 0:04 bash 32071 cognitio 0 0 456 28 28 S 0 0.0 0.2 0:06 bash For more information, see 'man top' ------------------------------------------------------------------------- See also: Linux in a Nutshell (O'Reilly) The Man pages for relevent commands Please direct any feedback relating to this file to me, via email to: <cognition@bigfoot.com> ------------------------------------------------------------------------- cogNiTioN <cognition@bigfoot.com> Copyright 1999 cogNiTioN