Commands

Commands

df

[option, ] [file, ]

Report the amount of space used and available on filesystem(s).

Example: To print out the current state of the filesystems with size in megabytes, use

df -h

where Filesystem is the disk partition corresponding to the mounted filesystem. Mounted on gives the entry in /etc/fstab corresponding to the disk partition. Size, Used, and Avail are the

Filesystem  Size  Used  Avail  Capacity Mounted on
/dev/hda5  167M  45M  114M  28%  /
/dev/hda7  402M  2.9M  379M  1%  /home
/dev/hda6  1.6G  815M  703M  54%  /usr

obvious (though normally displayed by block count rather than megabytes).

graphics/tip.gif

Filesystems do fill up. The following commands may be used to present some good candidates for archiving or deletion. To list the files in descending order by size, use

du -a / | sort -rn | less

 

To list files that haven't been accessed in the last 90 days, use

find / -atime +90 -print | less

-a, --all

Also list filesystems of size 0, which are omitted by default.

-h, -human-readable

Append letters to specify units of measurement (e.g., M = megabyte, K = kilobyte).

--inodes

List inode usage information instead of block usage.

-k, --kilobytes

Print size in 1024 byte blocks.

-m, --megabytes

Print size in megabyte blocks.

--no-sync

Do not run the sync system call before getting usage data.

-P, --portability

Use the POSIX output format.

--sync

Invoke the sync system call before getting usage data.

-tFSTYPE, --type=FSTYPE

List only filesystems of type FSTYPE.

-T,--print-type

Include the filesystem type (nfs, 4.2, ufs, efs, hsfs, cdfs, pcfs) in the listing.

-xFSTYPE, --exclude-type=FSTYPE

Exclude from the listing filesystems of type FSTYPE.

-v

Ignored; for compatibility with System V versions of "df".

dmesg

[ -c ] [ -n level ] [ -s bufsize ]

This command is used to display or control the contents of the kernel ring buffer, which contains the bootup messages.

Example: To get the boot messages from your last system startup, use

dmesg | less

Example: To set your console to display messages with annoying frequency, use

dmesg -n 3

-c

Clear the contents of the ring buffer after printing.

-sbufsize

Specify the size of the buffer used to query the kernel ring buffer. Default is 8196.

-nlevel

Specify the level at which log messages are displayed to the console. Note that messages are sent to /proc/ kmsg regardless of level. Typically, this is set to 1, which filters all but panic messages.

free

[-b | -k | -m] [-o] [-s delay ] [-t] [-V]

Free gives a snapshot of the system memory. It displays information on physical memory, swap memory, shared memory, and buffers.

Example: To get the default information, use

free

Here's a display of the information you get:

  total  used  free  shared  buffers  cached
 
Mem:   95460  88832  6628  24208  33912  34968
-/+
buffers/cache:  19952  75508
Swap:  104384  0  104384

-b

Displays given in bytes.

-k

Displays given in kilobytes.

-m

Displays given in megabytes.

-o

Do not display "buffer adjusted" line.

-sseconds

Use of this option will run free continuously with a delay of the specified number of seconds.

-t

Totals included in display.

-V

Display version information.

ipcs

[ -asmq ] [ -tclup ]

ipcs

[ -smq ] -i id

ipcs

-h

Display information on shared memory segments, semaphore arrays, and message queues.

Example: To get full information from ipcs, use

ipcs

Here's a example of the display you get upon using ipcs:

------ Shared Memory Segments --------
key  shmid  owner  perms  bytes  nattch  status
 
------ Semaphore Arrays --------
key  semid  owner  perms  nsems  status
 
------ Message Queues --------
key  msqid  owner  perms  used-bytes  messages
0x00000000 0  root  700  0  0

-m

Display information on shared memory segments.

-q

Display information on message queues.

-s

Display information on semaphore arrays.

-a

Display information on everything.

-t

Output time information.

-p

Output pid information.

-c

Output creator information.

-l

Output limit information.

-u

Output summary information.

pstree

[-a] [-c] [-h] [-l] [-n] [-p] [-u] [-G|-U] [pid|user]

pstree

-V

Output the family tree of running processes. If no process id or user name is specified, the tree is rooted at init. Identical branches are merged in the display by prefixing the process name with a count.

Example: Say your xinit process has a PID of 430. To display it and all its descendants in tree form with their PIDs, use

pstree 430 -p

The output you get is as follows:

xinit(431)-+-X(432)
  `-wmaker(434)-+-wmclock(443)
  |-xterm(637)---bash(638)
  |-xterm(715)---bash(716)---pstree(2118)
  |-xterm(718)---bash(719)---top(720)
  |-xterm(721)---bash(722)---vi(2051)
  `-xterm(724)---bash(725)

-a

Include command line arguments in the display.

-c

Do not compact the identical subtrees.

-G

Graphical display. (Use vt100 line drawing characters.) Very cool.

-h

Highlight family tree of current process.

-l

Do not truncate long lines.

-n

Numeric sort by PID.

-p

Include PIDs in display.

-u

Include uid transitions in display.

-U

Graphical display. Uses UTF-8 (Unicode) graphical characters in display.

-V

Display version information.

runlevel

[utmp]

Runlevel consults the system utmp file and displays the current and previous system runlevel. A value of "N" indicates that there was no previous runlevel.

Example: To display the current and previous runlevel, use

runlevel

utmp

Specifies a utmp file to be read.

tload

[-V] [-s scale] [ -d delay ] [tty]

Displays a graph of the current system load average.

Example: To set up a window to monitor system performance with a delay of 5 seconds between updates, use

tload -d 5

-s

Specify a vertical scale for the output. A smaller value represents a larger scale.

-d

Specify a delay (in seconds) between graph updates.

top

[-] [d delay] [q] [c] [S] [s] [i]

Top displays a listing of the processes utilizing the CPU. Output may be ordered by CPU usage, memory usage or runtime. Note that top is itself a CPU-intensive task, so you might want to use it sparingly. To change options while top is running, use the s command at the prompt and specify the new options.

Example: In my experience, top is generally run without arguments. Upon typing

top

the following output is produced:

8:59am  up 3 days, 16:42,  3 users,  load average: 0.00, 0.00, 0.00
39 processes: 38 sleeping, 1 running, 0 zombie, 0 stopped
CPU states:  0.9% user,  0.0% system,  0.0% nice, 99.1% idle
Mem:  95460K av,  87380K used,  8080K free,  17648K shrd,  33748K buff
Swap: 104384K av,  0K used, 104384K free  37184K cached
 
  PID USER  PRI  NI  SIZE  RSS SHARE STAT  LIB %CPU %MEM  TIME COMMAND
 6543 root  19  0  716  716  556 R  0  0.9  0.7  0:00 top
  1 root  0  0  388  388  328 S  0  0.0  0.4  0:03 init
  2 root  0  0   0  0  0 SW  0  0.0  0.0  0:00 kflushd
  3 root  -12 -12  0  0  0 SW<  0  0.0  0.0  0:00 kswapd
  4 root  0  0  0  0  0 SW  0  0.0  0.0  0:00 md_thread
  5 root  0  0  0  0  0 SW  0  0.0  0.0  0:00 md_thread
  402 news  19  0  708  708  576 S  0  0.0  0.7  0:00 innwatch
 1287 root  0  0  796  796  656 S  0  0.0  0.8  0:00 bash
  395 root  0  0  296  296  248 S  0  0.0  0.3  0:00 mingetty
  36 root  0  0  364  364  312 S  0  0.0  0.3  0:00 kerneld
  210 bin  0  0  332  332  264 S  0  0.0  0.3  0:00 portmap
  224 root  0  0  472  472  396 S  0  0.0  0.4  0:00 syslogd
  233 root  0  0  536  536  324 S  0  0.0  0.5  0:00 klogd
  244 daemon  0  0  404  404  328 S  0  0.0  0.4  0:00 atd
  255 root  0  0  472  472  392 S  0  0.0  0.4  0:00 crond
  267 root  0  0  396  396  328 S  0  0.0  0.4  0:00 inetd
  278 root  0  0  1168 1168  580 S  0  0.0  1.2  0:00 named

-d

Use the specified delay (in seconds) between updates.

-q

Refresh constantly with no delay.

-S

Include in usage calculations the usage of the process' children.

-s

Run in secure mode.

-i

Tell top to ignore idle or zombie processes.

-c

Include the process' entire command line in the output

Summary of Display Options

uptime

How long the system has been running, plus the average number of processes ready to run in the last 1, 5, and 15 minutes.

processes

Count of the number of processes running at the last update.

CPU states

State the percentage of CPU time in user mode, system mode, niced tasks, and idle time.

Mem

Display memory statistics (total K, free K, used K, shared K, buffer K).

Swap

Display swap statistics (total K, available K, used K, cached).

PID

Display PID of the process.

PPID

Display PID of the process' parent.

UID

Display UID of the process' owner.

USER

Display the user name of the process' owner.

PRI

Display the priority of the task.

NI

Display the nice value of the task.

SIZE

Display the size of code + data + stack space, in kilobytes.

TSIZE

Display the code size of the task.

DSIZE

Display the size of data + stack space.

TRS

Display the text resident state.

SWAP

Display the size of part of task currently swapped out.

D

Display the size of dirty memory pages.

LIB

Display the size of library pages.

RSS

Display the total amount of physical memory used by the task.

SHARE

Display the amount of shared memory used by the task.

STAT

Display the state of the task (Z = zombie, S = sleeping, T = stopped).

WCHAN

Show the address or name of the kernel function task is sleeping in.

TIME

Display the total CPU time used by task since invoked.

%CPU

Display the percentage of CPU time used by task since last update.

%MEM

Display the percentage of physical memory used by the task.

COMMAND

Display the name of the command that started the task.

Once invoked, top may be used interactively. The following are supported:

<space>

Update display information immediately.

^L

Repaint the screen.

h, ?

Display help information.

k

Kill a process top will prompt for pid.

i

Ignore zombie processes and idle processes.

n, #

Show the specified number of processes.

q

Quit.

r

Renice a process.

S

Toggle cumulative mode on/off.

s

Specify new delay (in seconds) between updates.

f, F

Add specified fields to display.

o, O

Change order of displayed fields.

l

Toggle display of load average and uptime information.

m

Toggle display of memory information.

t

Toggle display of CPU state and process information.

c

Toggle display between command name/full command line.

M

Order display by memory usage.

P

Order display by CPU usage.

T

Order display by time/cumulative time.

W

Write current setup to ~/.toprc.

vmstat

[-n] [delay [ count]]

vmstat

[-V]

Display information about current processes, memory, paging, block IO, traps, and CPU activity. Output is either one-time or periodic. The first line of the display shows averages since last reboot.

Example: To get vmstat information for five seconds at one-second intervals, use

vmstati 1 5

The following is a display of the output you can get once you use vmstat 1 5:

procs  memory   swap  io  system  cpu
r b w  swpd  free  buff cache  si  so  bi  bo  in  cs  us  sy  id
0 0 0  0 12396 33976 29300  0  0  1  0  101  77  0  0  99
0 0 0  0 12396 33976 29300  0  0  0  0  103  50  0  1  99
0 0 0  0 12396 33976 29300  0  0  0  0  102  54  0  1  99
0 0 0  0 12396 33976 29300  0  0  0  0  102  43  0  1  99
0 0 0  0 12396 33976 29300  0  0  0  0  102  151  2  2  96

-n

Display the header only once (default is regular display).

delay

Specify a delay between updates (in seconds).

count

Specify the number of updates.

-V

Display version information.

The Output Explained

Procs

r:

Processes waiting for runtime.

b:

Processes in uninterruptable sleep.

w:

Processes swapped out, but otherwise runnable.

Memory

swpd:

Virtual memory used (kB).

free:

Idle memory (kB) used.

buff:

Memory used as buffers (kB).

Swap

si:

Memory swapped in from disk (kB/s).

so:

Memory swapped to disk (kB/s).

IO

bi:

Blocks sent to a block device (blocks/s).

bo:

Blocks received from a block device (blocks/s).

System

in:

Interrupts per second, including the clock.

cs:

The number of context switches per second.

CPU

us:

Display percentage user time.

sy:

Display percentage system time.

id:

Display percentage idle time.

who

[OPTION] [FILE] [am i]

Display information about the users currently logged in. With no options, the display includes login name, terminal line, login time, remote hostname, or X display.

Example: To find out who's logged in to the system, use

who

FILE

If present, who will use this as the source for users logged on rather than /etc/wtmp.

-m

Same as "who am I".

-q, -count

Display only the count of users logged on and their login names.

-s

No effect; included for compatibility.

-i, -u, -idle

Include idle time in display. "." in the idle time field means the user has been active in the last minute; "old" means they have been idle for more than 24 hours.

-H, -heading

Print a line of column headings.

-w, -T, -mesg, -message, -writable

After each login name, print a character indicating the user's message status:

+ allowing "write" messages

- disallowing "write" messages

? cannot find terminal device

 



Linux Desk Reference
Linux Desk Reference (2nd Edition)
ISBN: 0130619892
EAN: 2147483647
Year: 2000
Pages: 174
Authors: Scott Hawkins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net