目录
/proc 文件系统摘要
一些程序和机制(在此对其中的某些进行了介绍)可用于检验系统状态。同时介绍了可用于日常工作的一些实用程序,以及它们最重要的参数。
对于所介绍的每个命令,都将提供相关输出的示例。在这些示例中,第一行是命令本身(在 > 或 # 符号提示后)。使用方括号 ([...]) 表示省略,必要时对较长的行进行换行。较长的行的换行符由反斜线 (\) 表示。
# command -x -y
output line 1
output line 2
output line 3 is annoyingly long, so long that \
we have to break it
output line 3
[...]
output line 98
output line 99
这里尽量缩短对每个实用程序的说明,从而介绍尽量多的实用程序。手册页中提供了所有命令的详细信息。大多数命令还接受参数 --help,该参数将生成可能参数的简要列表。
要查看为具有进程 ID PID 的进程打开的所有文件的列表,请使用 -p。例如,要查看当前 shell 使用的所有文件,请输入:
tester@linux:~> lsof -p $$ COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME bash 5552 tester cwd DIR 3,3 1512 117619 /home/tester bash 5552 tester rtd DIR 3,3 584 2 / bash 5552 tester txt REG 3,3 498816 13047 /bin/bash bash 5552 tester mem REG 0,0 0 [heap] (stat: No such \ file or directory) bash 5552 tester mem REG 3,3 217016 115687 /var/run/nscd/passwd bash 5552 tester mem REG 3,3 208464 11867 \ /usr/lib/locale/en_GB.utf8/LC_CTYPE bash 5552 tester mem REG 3,3 882134 11868 \ /usr/lib/locale/en_GB.utf8/LC_COLLATE bash 5552 tester mem REG 3,3 1386997 8837 /lib/libc-2.3.6.so bash 5552 tester mem REG 3,3 13836 8843 /lib/libdl-2.3.6.so bash 5552 tester mem REG 3,3 290856 12204 /lib/libncurses.so.5.5 bash 5552 tester mem REG 3,3 26936 13004 /lib/libhistory.so.5.1 bash 5552 tester mem REG 3,3 190200 13006 /lib/libreadline.so.5.1 bash 5552 tester mem REG 3,3 54 11842 \ /usr/lib/locale/en_GB.utf8/LC_NUMERIC bash 5552 tester mem REG 3,3 2375 11663 \ /usr/lib/locale/en_GB.utf8/LC_TIME bash 5552 tester mem REG 3,3 290 11736 \ /usr/lib/locale/en_GB.utf8/LC_MONETARY bash 5552 tester mem REG 3,3 52 11831 \ /usr/lib/locale/en_GB.utf8/LC_MESSAGES/SYS_LC_MESSAGES bash 5552 tester mem REG 3,3 34 11862 \ /usr/lib/locale/en_GB.utf8/LC_PAPER bash 5552 tester mem REG 3,3 62 11839 \ /usr/lib/locale/en_GB.utf8/LC_NAME bash 5552 tester mem REG 3,3 127 11664 \ /usr/lib/locale/en_GB.utf8/LC_ADDRESS bash 5552 tester mem REG 3,3 56 11735 \ /usr/lib/locale/en_GB.utf8/LC_TELEPHONE bash 5552 tester mem REG 3,3 23 11866 \ /usr/lib/locale/en_GB.utf8/LC_MEASUREMENT bash 5552 tester mem REG 3,3 21544 9109 \ /usr/lib/gconv/gconv-modules.cache bash 5552 tester mem REG 3,3 366 9720 \ /usr/lib/locale/en_GB.utf8/LC_IDENTIFICATION bash 5552 tester mem REG 3,3 97165 8828 /lib/ld-2.3.6.so bash 5552 tester 0u CHR 136,5 7 /dev/pts/5 bash 5552 tester 1u CHR 136,5 7 /dev/pts/5 bash 5552 tester 2u CHR 136,5 7 /dev/pts/5 bash 5552 tester 255u CHR 136,5 7 /dev/pts/5
使用了特殊 shell 变量 $$,它的值是 shell 的进程 ID。
如果不带任何参数使用命令 lsof,它将列出当前打开的所有文件。由于有数千个打开的文件,大多数情况下不必列出所有这些文件。但是,所有文件的列表可以与搜索功能组合在一起产生有用的列表。例如,列出所有使用过的字符设备:
tester@linux:~> lsof | grep CHR bash 3838 tester 0u CHR 136,0 2 /dev/pts/0 bash 3838 tester 1u CHR 136,0 2 /dev/pts/0 bash 3838 tester 2u CHR 136,0 2 /dev/pts/0 bash 3838 tester 255u CHR 136,0 2 /dev/pts/0 bash 5552 tester 0u CHR 136,5 7 /dev/pts/5 bash 5552 tester 1u CHR 136,5 7 /dev/pts/5 bash 5552 tester 2u CHR 136,5 7 /dev/pts/5 bash 5552 tester 255u CHR 136,5 7 /dev/pts/5 X 5646 root mem CHR 1,1 1006 /dev/mem lsof 5673 tester 0u CHR 136,5 7 /dev/pts/5 lsof 5673 tester 2u CHR 136,5 7 /dev/pts/5 grep 5674 tester 1u CHR 136,5 7 /dev/pts/5 grep 5674 tester 2u CHR 136,5 7 /dev/pts/5