📄 system.html
字号:
></TABLE></DIV></DD><DT><ANAME="WALLREF"></A><BCLASS="COMMAND">wall</B></DT><DD><P>This is an acronym for <SPANCLASS="QUOTE">"<AHREF="communications.html#WRITEREF">write</A> all"</SPAN>, i.e., sending a message to all users at every terminal logged into the network. It is primarily a system administrator's tool, useful, for example, when warning everyone that the system will shortly go down due to a problem (see <AHREF="here-docs.html#EX70">Example 17-1</A>).</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>wall System going down for maintenance in 5 minutes!</B></TT> <TTCLASS="COMPUTEROUTPUT">Broadcast message from bozo (pts/1) Sun Jul 8 13:53:27 2001... System going down for maintenance in 5 minutes!</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>If write access to a particular terminal has been disabled with <BCLASS="COMMAND">mesg</B>, then <BCLASS="COMMAND">wall</B> cannot send a message to it.</P></TD></TR></TABLE></DIV></DD></DL></DIV><DIVCLASS="VARIABLELIST"><P><B><ANAME="STATISTICSSYS1"></A>Information and Statistics</B></P><DL><DT><BCLASS="COMMAND">uname</B></DT><DD><P>Output system specifications (OS, kernel version, etc.) to <TTCLASS="FILENAME">stdout</TT>. Invoked with the <TTCLASS="OPTION">-a</TT> option, gives verbose system info (see <AHREF="moreadv.html#EX41">Example 12-5</A>). The <TTCLASS="OPTION">-s</TT> option shows only the OS type.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>uname -a</B></TT> <TTCLASS="COMPUTEROUTPUT">Linux localhost.localdomain 2.2.15-2.5.0 #1 Sat Feb 5 00:13:43 EST 2000 i686 unknown</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>uname -s</B></TT> <TTCLASS="COMPUTEROUTPUT">Linux</TT></PRE></TD></TR></TABLE></DD><DT><BCLASS="COMMAND">arch</B></DT><DD><P>Show system architecture. Equivalent to <BCLASS="COMMAND">uname -m</B>. See <AHREF="testbranch.html#CASECMD">Example 10-26</A>.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>arch</B></TT> <TTCLASS="COMPUTEROUTPUT">i686</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>uname -m</B></TT> <TTCLASS="COMPUTEROUTPUT">i686</TT></PRE></TD></TR></TABLE></DD><DT><BCLASS="COMMAND">lastcomm</B></DT><DD><P>Gives information about previous commands, as stored in the <TTCLASS="FILENAME">/var/account/pacct</TT> file. Command name and user name can be specified by options. This is one of the GNU accounting utilities.</P></DD><DT><ANAME="LASTLOGREF"></A><BCLASS="COMMAND">lastlog</B></DT><DD><P>List the last login time of all system users. This references the <TTCLASS="FILENAME">/var/log/lastlog</TT> file.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>lastlog</B></TT> <TTCLASS="COMPUTEROUTPUT">root tty1 Fri Dec 7 18:43:21 -0700 2001 bin **Never logged in** daemon **Never logged in** ... bozo tty1 Sat Dec 8 21:14:29 -0700 2001</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>lastlog | grep root</B></TT> <TTCLASS="COMPUTEROUTPUT">root tty1 Fri Dec 7 18:43:21 -0700 2001</TT> </PRE></TD></TR></TABLE> </P><DIVCLASS="CAUTION"><TABLECLASS="CAUTION"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/caution.png"HSPACE="5"ALT="Caution"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>This command will fail if the user invoking it does not have read permission for the <TTCLASS="FILENAME">/var/log/lastlog</TT> file.</P></TD></TR></TABLE></DIV></DD><DT><BCLASS="COMMAND">lsof</B></DT><DD><P>List open files. This command outputs a detailed table of all currently open files and gives information about their owner, size, the processes associated with them, and more. Of course, <BCLASS="COMMAND">lsof</B> may be piped to <AHREF="textproc.html#GREPREF">grep</A> and/or <AHREF="awk.html#AWKREF">awk</A> to parse and analyze its results.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>lsof</B></TT> <TTCLASS="COMPUTEROUTPUT">COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME init 1 root mem REG 3,5 30748 30303 /sbin/init init 1 root mem REG 3,5 73120 8069 /lib/ld-2.1.3.so init 1 root mem REG 3,5 931668 8075 /lib/libc-2.1.3.so cardmgr 213 root mem REG 3,5 36956 30357 /sbin/cardmgr ...</TT> </PRE></TD></TR></TABLE> </P></DD><DT><BCLASS="COMMAND">strace</B></DT><DD><P>Diagnostic and debugging tool for tracing system calls and signals. The simplest way of invoking it is <BCLASS="COMMAND">strace COMMAND</B>.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>strace df</B></TT> <TTCLASS="COMPUTEROUTPUT">execve("/bin/df", ["df"], [/* 45 vars */]) = 0 uname({sys="Linux", node="bozo.localdomain", ...}) = 0 brk(0) = 0x804f5e4 ...</TT> </PRE></TD></TR></TABLE> </P><P>This is the Linux equivalent of the Solaris <BCLASS="COMMAND">truss</B> command.</P></DD><DT><ANAME="NMAPREF"></A><BCLASS="COMMAND">nmap</B></DT><DD><P>Network port scanner. This command scans a server to locate open ports and the services associated with those ports. It is an important security tool for locking down a network against hacking attempts.</P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #!/bin/bash 2 3 SERVER=$HOST # localhost.localdomain (127.0.0.1). 4 PORT_NUMBER=25 # SMTP port. 5 6 nmap $SERVER | grep -w "$PORT_NUMBER" # Is that particular port open? 7 # grep -w matches whole words only, 8 #+ so this wouldn't match port 1025, for example. 9 10 exit 0 11 12 # 25/tcp open smtp</PRE></TD></TR></TABLE></P></DD><DT><BCLASS="COMMAND">nc</B></DT><DD><P>The <BCLASS="COMMAND">nc</B> (<ICLASS="EMPHASIS">netcat</I>) utility is a complete toolkit for connecting to and listening to TCP and UDP ports. It is useful as a diagnostic and testing tool and as a component in simple script-based HTTP clients and servers.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>nc localhost.localdomain 25</B></TT> <TTCLASS="COMPUTEROUTPUT">220 localhost.localdomain ESMTP Sendmail 8.13.1/8.13.1; Thu, 31 Mar 2005 15:41:35 -0700</TT></PRE></TD></TR></TABLE> </P><DIVCLASS="EXAMPLE"><HR><ANAME="ISCAN"></A><P><B>Example 13-5. Checking a remote server for <ICLASS="EMPHASIS">identd</I></B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #! /bin/sh 2 ## Duplicate DaveG's ident-scan thingie using netcat. Oooh, he'll be p*ssed. 3 ## Args: target port [port port port ...] 4 ## Hose stdout _and_ stderr together. 5 ## 6 ## Advantages: runs slower than ident-scan, giving remote inetd less cause 7 ##+ for alarm, and only hits the few known daemon ports you specify. 8 ## Disadvantages: requires numeric-only port args, the output sleazitude, 9 ##+ and won't work for r-services when coming from high source ports. 10 # Script author: Hobbit <hobbit@avian.org> 11 # Used in ABS Guide with permission. 12 13 # --------------------------------------------------- 14 E_BADARGS=65 # Need at least two args. 15 TWO_WINKS=2 # How long to sleep. 16 THREE_WINKS=3 17 IDPORT=113 # Authentication "tap ident" port. 18 RAND1=999 19 RAND2=31337 20 TIMEOUT0=9 21 TIMEOUT1=8 22 TIMEOUT2=4 23 # --------------------------------------------------- 24 25 case "${2}" in 26 "" ) echo "Need HOST and at least one PORT." ; exit $E_BADARGS ;; 27 esac 28 29 # Ping 'em once and see if they *are* running identd. 30 nc -z -w $TIMEOUT0 "$1" $IDPORT || { echo "Oops, $1 isn't running identd." ; exit 0 ; } 31 # -z scans for listening daemons. 32 # -w $TIMEOUT = How long to try to connect. 33 34 # Generate a randomish base port. 35 RP=`expr $$ % $RAND1 + $RAND2` 36 37 TRG="$1" 38 shift 39 40 while test "$1" ; do 41 nc -v -w $TIMEOUT1 -p ${RP} "$TRG" ${1} < /dev/null > /dev/null & 42 PROC=$! 43 sleep $THREE_WINKS 44 echo "${1},${RP}" | nc -w $TIMEOUT2 -r "$TRG" $IDPORT 2>&1 45 sleep $TWO_WINKS 46 47 # Does this look like a lamer script or what . . . ? 48 # ABS Guide author comments: "It ain't really all that bad, 49 #+ rather clever, actually." 50 51 kill -HUP $PROC 52 RP=`expr ${RP} + 1` 53 shift 54 done 55 56 exit $? 57 58 # Notes: 59 # ----- 60 61 # Try commenting out line 30 and running this script 62 #+ with "localhost.localdomain 25" as arguments. 63 64 # For more of Hobbit's 'nc' example scripts, 65 #+ look in the documentation: 66 #+ the /usr/share/doc/nc-X.XX/scripts directory.</PRE></TD></TR></TABLE><HR></DIV><P> And, of course, there's Dr. Andrew Tridgell's notorious one-line script in the BitKeeper Affair: <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 echo clone | nc thunk.org 5000 > e2fsprogs.dat</PRE></TD></TR></TABLE> </P></DD><DT><ANAME="FREEREF"></A><BCLASS="COMMAND">free</B></DT><DD><P>Shows memory and cache usage in tabular form. The output of this command lends itself to parsing, using <AHREF="textproc.html#GREPREF">grep</A>, <AHREF="awk.html#AWKREF">awk</A> or <BCLASS="COMMAND">Perl</B>. The <BCLASS="COMMAND">procinfo</B> command shows all the information that <BCLASS="COMMAND">free</B> does, and much more.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><BCLASS="COMMAND">free</B> <TTCLASS="COMPUTEROUTPUT"> total used free shared buffers cached Mem: 30504 28624 1880 15820 1608 16376 -/+ buffers/cache: 10640 19864 Swap: 68540 3128 65412</TT></PRE></TD></TR></TABLE><P>To show unused RAM memory:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><BCLASS="COMMAND">free | grep Mem | awk '{ print $4 }'</B> <TTCLASS="COMPUTEROUTPUT">1880</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="PROCINFOREF"></A><BCLASS="COMMAND">procinfo</B></DT><DD><P>Extract and list information and statistics from the <AHREF="devproc.html#DEVPROCREF"><TTCLASS="FILENAME">/proc</TT> pseudo-filesystem</A>. This gives a very extensive and detailed listing.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>procinfo | grep Bootup</B></TT> <TTCLASS="COMPUTEROUTPUT">Bootup: Wed Mar 21 15:15:50 2001 Load average: 0.04 0.21 0.34 3/47 6829</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="LSDEVREF"></A><BCLASS="COMMAND">lsdev</B></DT><DD><P>List devices, that is, show installed hardware.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>lsdev</B></TT> <TTCLASS="COMPUTEROUTPUT">Device DMA IRQ I/O Ports ------------------------------------------------ cascade 4 2 dma 0080-008f dma1 0000-001f dma2 00c0-00df fpu 00f0-00ff ide0 14 01f0-01f7 03f6-03f6 ...</TT> </PRE></TD></TR></TABLE> </P></DD><DT><ANAME="DUREF"></A><BCLASS="COMMAND">du</B></DT><DD><P>Show (disk) file usage, recursively. Defaults to current working directory, unless otherwise specified.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -