📄 system.html
字号:
><BCLASS="COMMAND">du -ach</B> <TTCLASS="COMPUTEROUTPUT">1.0k ./wi.sh 1.0k ./tst.sh 1.0k ./random.file 6.0k . 6.0k total</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="DFREF"></A><BCLASS="COMMAND">df</B></DT><DD><P>Shows filesystem usage in tabular form.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><BCLASS="COMMAND">df</B> <TTCLASS="COMPUTEROUTPUT">Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda5 273262 92607 166547 36% / /dev/hda8 222525 123951 87085 59% /home /dev/hda7 1408796 1075744 261488 80% /usr</TT></PRE></TD></TR></TABLE></DD><DT><BCLASS="COMMAND">dmesg</B></DT><DD><P>Lists all system bootup messages to <TTCLASS="FILENAME">stdout</TT>. Handy for debugging and ascertaining which device drivers were installed and which system interrupts in use. The output of <BCLASS="COMMAND">dmesg</B> may, of course, be parsed with <AHREF="textproc.html#GREPREF">grep</A>, <AHREF="sedawk.html#SEDREF">sed</A>, or <AHREF="awk.html#AWKREF">awk</A> from within a script.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>dmesg | grep hda</B></TT> <TTCLASS="COMPUTEROUTPUT">Kernel command line: ro root=/dev/hda2 hda: IBM-DLGA-23080, ATA DISK drive hda: 6015744 sectors (3080 MB) w/96KiB Cache, CHS=746/128/63 hda: hda1 hda2 hda3 < hda5 hda6 hda7 > hda4</TT> </PRE></TD></TR></TABLE> </P></DD><DT><BCLASS="COMMAND">stat</B></DT><DD><P>Gives detailed and verbose <ICLASS="EMPHASIS">stat</I>istics on a given file (even a directory or device file) or set of files.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>stat test.cru</B></TT> <TTCLASS="COMPUTEROUTPUT"> File: "test.cru" Size: 49970 Allocated Blocks: 100 Filetype: Regular File Mode: (0664/-rw-rw-r--) Uid: ( 501/ bozo) Gid: ( 501/ bozo) Device: 3,8 Inode: 18185 Links: 1 Access: Sat Jun 2 16:40:24 2001 Modify: Sat Jun 2 16:40:24 2001 Change: Sat Jun 2 16:40:24 2001</TT> </PRE></TD></TR></TABLE> </P><P>If the target file does not exist, <BCLASS="COMMAND">stat</B> returns an error message.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>stat nonexistent-file</B></TT> <TTCLASS="COMPUTEROUTPUT">nonexistent-file: No such file or directory</TT> </PRE></TD></TR></TABLE> </P></DD><DT><ANAME="VMSTATREF"></A><BCLASS="COMMAND">vmstat</B></DT><DD><P>Display virtual memory statistics.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>vmstat</B></TT> <TTCLASS="COMPUTEROUTPUT"> 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 11040 2636 38952 0 0 33 7 271 88 8 3 89</TT> </PRE></TD></TR></TABLE> </P></DD><DT><BCLASS="COMMAND">netstat</B></DT><DD><P>Show current network statistics and information, such as routing tables and active connections. This utility accesses information in <TTCLASS="FILENAME">/proc/net</TT> (<AHREF="devproc.html">Chapter 27</A>). See <AHREF="procref1.html#CONSTAT">Example 27-3</A>.</P><P><BCLASS="COMMAND">netstat -r</B> is equivalent to <AHREF="system.html#ROUTEREF">route</A>.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>netstat</B></TT> <TTCLASS="COMPUTEROUTPUT">Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 11 [ ] DGRAM 906 /dev/log unix 3 [ ] STREAM CONNECTED 4514 /tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 4513 . . .</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="UPTIMEREF"></A><BCLASS="COMMAND">uptime</B></DT><DD><P>Shows how long the system has been running, along with associated statistics.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>uptime</B></TT> <TTCLASS="COMPUTEROUTPUT">10:28pm up 1:57, 3 users, load average: 0.17, 0.34, 0.27</TT></PRE></TD></TR></TABLE><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>A <ICLASS="FIRSTTERM">load average</I> of 1 or less indicates that the system handles processes immediately. A load average greater than 1 means that processes are being queued. When the load average gets above 3, then system performance is significantly degraded.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="HNAMEREF"></A><BCLASS="COMMAND">hostname</B></DT><DD><P>Lists the system's host name. This command sets the host name in an <TTCLASS="FILENAME">/etc/rc.d</TT> setup script (<TTCLASS="FILENAME">/etc/rc.d/rc.sysinit</TT> or similar). It is equivalent to <BCLASS="COMMAND">uname -n</B>, and a counterpart to the <AHREF="variables2.html#HOSTNAMEREF">$HOSTNAME</A> internal variable.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>hostname</B></TT> <TTCLASS="COMPUTEROUTPUT">localhost.localdomain</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>echo $HOSTNAME</B></TT> <TTCLASS="COMPUTEROUTPUT">localhost.localdomain</TT></PRE></TD></TR></TABLE><P>Similar to the <BCLASS="COMMAND">hostname</B> command are the <BCLASS="COMMAND">domainname</B>, <BCLASS="COMMAND">dnsdomainname</B>, <BCLASS="COMMAND">nisdomainname</B>, and <BCLASS="COMMAND">ypdomainname</B> commands. Use these to display or set the system DNS or NIS/YP domain name. Various options to <BCLASS="COMMAND">hostname</B> also perform these functions.</P></DD><DT><ANAME="HOSTIDREF"></A><BCLASS="COMMAND">hostid</B></DT><DD><P>Echo a 32-bit hexadecimal numerical identifier for the host machine.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>hostid</B></TT> <TTCLASS="COMPUTEROUTPUT">7f0100</TT></PRE></TD></TR></TABLE> </P><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>This command allegedly fetches a <SPANCLASS="QUOTE">"unique"</SPAN> serial number for a particular system. Certain product registration procedures use this number to brand a particular user license. Unfortunately, <BCLASS="COMMAND">hostid</B> only returns the machine network address in hexadecimal, with pairs of bytes transposed.</P><P>The network address of a typical non-networked Linux machine, is found in <TTCLASS="FILENAME">/etc/hosts</TT>.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>cat /etc/hosts</B></TT> <TTCLASS="COMPUTEROUTPUT">127.0.0.1 localhost.localdomain localhost</TT></PRE></TD></TR></TABLE> </P><P>As it happens, transposing the bytes of <TTCLASS="USERINPUT"><B>127.0.0.1</B></TT>, we get <TTCLASS="USERINPUT"><B>0.127.1.0</B></TT>, which translates in hex to <TTCLASS="USERINPUT"><B>007f0100</B></TT>, the exact equivalent of what <BCLASS="COMMAND">hostid</B> returns, above. There exist only a few million other Linux machines with this identical <ICLASS="EMPHASIS">hostid</I>.</P></TD></TR></TABLE></DIV></DD><DT><BCLASS="COMMAND">sar</B></DT><DD><P>Invoking <BCLASS="COMMAND">sar</B> (System Activity Reporter) gives a very detailed rundown on system statistics. The Santa Cruz Operation (<SPANCLASS="QUOTE">"Old"</SPAN> SCO) released <BCLASS="COMMAND">sar</B> as Open Source in June, 1999.</P><P>This command is not part of the base Linux distribution, but may be obtained as part of the<AHREF="http://perso.wanadoo.fr/sebastien.godard/"TARGET="_top"> sysstat utilities</A> package, written by <AHREF="mailto:sebastien.godard@wanadoo.fr"TARGET="_top">Sebastien Godard</A>.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>sar</B></TT> <TTCLASS="COMPUTEROUTPUT">Linux 2.4.9 (brooks.seringas.fr) 09/26/0310:30:00 CPU %user %nice %system %iowait %idle10:40:00 all 2.21 10.90 65.48 0.00 21.4110:50:00 all 3.36 0.00 72.36 0.00 24.2811:00:00 all 1.12 0.00 80.77 0.00 18.11Average: all 2.23 3.63 72.87 0.00 21.2714:32:30 LINUX RESTART15:00:00 CPU %user %nice %system %iowait %idle15:10:00 all 8.59 2.40 17.47 0.00 71.5415:20:00 all 4.07 1.00 11.95 0.00 82.9815:30:00 all 0.79 2.94 7.56 0.00 88.71Average: all 6.33 1.70 14.71 0.00 77.26</TT> </PRE></TD></TR></TABLE></DD><DT><BCLASS="COMMAND">readelf</B></DT><DD><P>Show information and statistics about a designated <ICLASS="EMPHASIS">elf</I> binary. This is part of the <ICLASS="EMPHASIS">binutils</I> package.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>readelf -h /bin/bash</B></TT> <TTCLASS="COMPUTEROUTPUT">ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) . . .</TT></PRE></TD></TR></TABLE></DD><DT><BCLASS="COMMAND">size</B></DT><DD><P>The <BCLASS="COMMAND">size [/path/to/binary]</B> command gives the segment sizes of a binary executable or archive file. This is mainly of use to programmers.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>size /bin/bash</B></TT> <TTCLASS="COMPUTEROUTPUT"> text data bss dec hex filename 495971 22496 17392 535859 82d33 /bin/bash</TT> </PRE></TD></TR></TABLE> </P></DD></DL></DIV><DIVCLASS="VARIABLELIST"><P><B><ANAME="SYSLOG1"></A>System Logs</B></P><DL><DT><BCLASS="COMMAND">logger</B></DT><DD><P>Appends a user-generated message to the system log (<TTCLASS="FILENAME">/var/log/messages</TT>). You do not have to be root to invoke <BCLASS="COMMAND">logger</B>. <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 logger Experiencing instability in network connection at 23:10, 05/21. 2 # Now, do a 'tail /var/log/messages'.</PRE></TD></TR></TABLE></P><P>By embedding a <BCLASS="COMMAND">logger</B> command in a script, it is possible to write debugging information to <TTCLASS="FILENAME">/var/log/messages</TT>. <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 logger -t $0 -i Logging at line "$LINENO". 2 # The "-t" option specifies the tag for the logger entry. 3 # The "-i" option records the process ID. 4 5 # tail /var/log/message
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -