📄 system.html
字号:
<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="FIRSTTERM">hostid</I>.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="SARREF"></A><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><ANAME="READELFREF"></A><BCLASS="COMMAND">readelf</B></DT><DD><P>Show information and statistics about a designated <ICLASS="FIRSTTERM">elf</I> binary. This is part of the <ICLASS="FIRSTTERM">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><ANAME="SIZEREF"></A><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><ANAME="LOGGERREF"></A><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 <ICLASS="FIRSTTERM">root</I> to invoke <BCLASS="COMMAND">logger</B>.</P><P> <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>.</P><P><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 6 # ... 7 # Jul 7 20:48:58 localhost ./test.sh[1712]: Logging at line 3.</PRE></TD></TR></TABLE> </P></DD><DT><ANAME="LOGROTATEREF"></A><BCLASS="COMMAND">logrotate</B></DT><DD><P>This utility manages the system log files, rotating, compressing, deleting, and/or e-mailing them, as appropriate. This keeps the <TTCLASS="FILENAME">/var/log</TT> from getting cluttered with old log files. Usually <AHREF="system.html#CRONREF">cron</A> runs <BCLASS="COMMAND">logrotate</B> on a daily basis.</P><P>Adding an appropriate entry to <TTCLASS="FILENAME">/etc/logrotate.conf</TT> makes it possible to manage personal log files, as well as system-wide ones.</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>Stefano Falsetto has created <AHREF="http://www.gnu.org/software/rottlog/"TARGET="_top">rottlog</A>, which he considers to be an improved version of <BCLASS="COMMAND">logrotate</B>.</P></TD></TR></TABLE></DIV></DD></DL></DIV><DIVCLASS="VARIABLELIST"><P><B><ANAME="JOBCONTROLSYS1"></A>Job Control</B></P><DL><DT><ANAME="PPSSREF"></A><BCLASS="COMMAND">ps</B></DT><DD><P><TTCLASS="REPLACEABLE"><I>P</I></TT>rocess <TTCLASS="REPLACEABLE"><I>S</I></TT>tatistics: lists currently executing processes by owner and PID (process ID). This is usually invoked with <TTCLASS="OPTION">ax</TT> or <TTCLASS="OPTION">aux</TT> options, and may be piped to <AHREF="textproc.html#GREPREF">grep</A> or <AHREF="sedawk.html#SEDREF">sed</A> to search for a specific process (see <AHREF="internal.html#EX44">Example 14-13</A> and <AHREF="procref1.html#PIDID">Example 27-2</A>).</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B> ps ax | grep sendmail</B></TT> <TTCLASS="COMPUTEROUTPUT">295 ? S 0:00 sendmail: accepting connections on port 25</TT></PRE></TD></TR></TABLE><P>To display system processes in graphical <SPANCLASS="QUOTE">"tree"</SPAN> format: <BCLASS="COMMAND">ps afjx</B> or <BCLASS="COMMAND">ps ax --forest</B>.</P></DD><DT><ANAME="PGREPREF"></A><BCLASS="COMMAND">pgrep</B>, <ANAME="PKILLREF"></A><BCLASS="COMMAND">pkill</B></DT><DD><P>Combining the <BCLASS="COMMAND">ps</B> command with <AHREF="textproc.html#GREPREF">grep</A> or <AHREF="internal.html#KILLREF">kill</A>.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>ps a | grep mingetty</B></TT> <TTCLASS="COMPUTEROUTPUT">2212 tty2 Ss+ 0:00 /sbin/mingetty tty2 2213 tty3 Ss+ 0:00 /sbin/mingetty tty3 2214 tty4 Ss+ 0:00 /sbin/mingetty tty4 2215 tty5 Ss+ 0:00 /sbin/mingetty tty5 2216 tty6 Ss+ 0:00 /sbin/mingetty tty6 4849 pts/2 S+ 0:00 grep mingetty</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>pgrep mingetty</B></TT> <TTCLASS="COMPUTEROUTPUT">2212 mingetty 2213 mingetty 2214 mingetty 2215 mingetty 2216 mingetty</TT> </PRE></TD></TR></TABLE> </P><P>Compare the action of <BCLASS="COMMAND">pkill</B> with <AHREF="internal.html#KILLALLREF">killall</A>.</P></DD><DT><ANAME="PSTREEREF"></A><BCLASS="COMMAND">pstree</B></DT><DD><P>Lists currently executing processes in <SPANCLASS="QUOTE">"tree"</SPAN> format. The <TTCLASS="OPTION">-p</TT> option shows the PIDs, as well as the process names.</P></DD><DT><ANAME="TOPREF"></A><BCLASS="COMMAND">top</B></DT><DD><P>Continuously updated display of most cpu-intensive processes. The <TTCLASS="OPTION">-b</TT> option displays in text mode, so that the output may be parsed or accessed from a script.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>top -b</B></TT> <TTCLASS="COMPUTEROUTPUT"> 8:30pm up 3 min, 3 users, load average: 0.49, 0.32, 0.13 45 processes: 44 sleeping, 1 running, 0 zombie, 0 stopped CPU states: 13.6% user, 7.3% system, 0.0% nice, 78.9% idle Mem: 78396K av, 65468K used, 12928K free, 0K shrd, 2352K buff Swap: 157208K av, 0K used, 157208K free 37244K cached PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 848 bozo 17 0 996 996 800 R 5.6 1.2 0:00 top 1 root 8 0 512 512 444 S 0.0 0.6 0:04 init 2 root 9 0 0 0 0 SW 0.0 0.0 0:00 keventd ...</TT> </PRE></TD></TR></TABLE> </P></DD><DT><ANAME="NICEREF"></A><BCLASS="COMMAND">nice</B></DT><DD><P><ANAME="NICE2REF"></A></P><P>Run a background job with an altered priority. Priorities run from 19 (lowest) to -20 (highest). Only <ICLASS="FIRSTTERM">root</I> may set the negative (higher) priorities. Related commands are <BCLASS="COMMAND">renice</B> and <BCLASS="COMMAND">snice</B>, which change the priority of a running process or processes, and <BCLASS="COMMAND">skill</B>, which sends a <AHREF="internal.html#KILLREF">kill</A> signal to a process or processes.</P></DD><DT><ANAME="NOHUPREF"></A><BCLASS="COMMAND">nohup</B></DT><DD><P>Keeps a command running even after user logs off. The command will run as a foreground process unless followed by <SPANCLASS="TOKEN">&</SPAN>. If you use <BCLASS="COMMAND">nohup</B> within a script, consider coupling it with a <AHREF="internal.html#WAITREF">wait</A> to avoid creating an <ICLASS="FIRSTTERM">orphan</I> or <AHREF="internal.html#ZOMBIEREF">zombie</A> process.</P></DD><DT><ANAME="PIDOFREF"></A><BCLASS="COMMAND">pidof</B></DT><DD><P>Identifies <I
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -