?文件处理命令 文件命名规则 1)除了/之外,所有的字符都合法。 2)有些字符最好不用,如空格符、制表符、退格符和字符@#$()-等。 3)避免使用.作为普通文件名的第一个字符。 4)大
文件命名规则1)除了/ 之外,所有的字符都合法。2)有些字符最好不用,如空格符、制表符、退格符和字符@ # $ & ( ) - 等。3)避免使用. 作为普通文件名的第一个字符。4)大小写敏感。
命令格式命令格式:命令 -选项 参数例: ls -la /etc说明:1)当有多个选项时,可以写在一起。 2)两个特殊的目录. 和.. ,分别代表当前目录和当前目录的父目录。

文件处理命令:ls命令名称:ls命令英文原意:list命令所在路径:/bin/ls执行权限:所有用户功能描述:显示目录文件语法:ls 选项[-ald] [文件或目录]-a 显示所有文件,包括隐藏文件-l 详细信息显示-d 查看目录属性



dr-xr-xr-x. 2 root root 4096 Jun 10 04:20 bin
2硬链接数root所有者root所属组4096 目录及子目录大小Jun 10 04:20目录创建时间或最后修改时间bin目录名
文件处理命令:cd命令名称:cd命令英文原意:change directory命令所在路径:shell内置命令执行权限:所有用户语法:cd [目录]功能描述:切换目录范例: $ cd / 切换到根目录 $ cd .. 回到上一级目录
文件处理命令:pwd命令名称:pwd命令英文原意:print working directory命令所在路径:/bin/pwd执行权限:所有用户语法:pwd功能描述:显示当前所在的工作目录范例:$ pwd/etc/rc5.d

文件处理命令:mkdir命令名称:mkdir命令英文原意:make directories命令所在路径:/bin/mkdir执行权限:所有用户语法:mkdir [目录名]功能描述:创建新目录范例: $ mkdir newdir
文件处理命令:touch命令名称:touch命令所在路径:/bin/touch执行权限:所有用户语法:touch [文件名]功能描述:修改文件时间戳,如果文件不存在则创建空文件范例: $ touch newfile

文件处理命令:cp命令名称:cp命令英文原意:copy命令所在路径:/bin/cp执行权限:所有用户语法:cp -R [源文件或目录] [目的目录]-R 复制目录功能描述:复制文件或目录范例:$ cp file1 file2 dir1将文件file1、file2复制到目录dir1$ cp -R dir1 dir2将dir1下的所有文件及子目录复制到dir2


文件处理命令:mv命令名称:mv命令英文原意:move命令所在路径:/bin/mv执行权限:所有用户语法:mv [源文件或目录] [目的目录]功能描述:移动文件、更名范例:$ mv file1 file3将当前目录下文件file1更名为file3$ mv file2 dir2将文件file2移动到目录dir2下

文件处理命令:rm命令名称:rm命令英文原意:remove命令所在路径:/bin/rm执行权限:所有用户语法:rm -r [文件或目录]-r 删除目录功能描述:删除文件范例:$ rm file3删除文件file3$ rm -r dir1删除目录dir1

文件处理命令:cat命令名称:cat命令英文原意:concatenate and display files命令所在路径:/bin/cat执行权限:所有用户语法:cat [文件名]功能描述:显示文件内容范例: $ cat /etc/issue$ cat /etc/services

文件处理命令:more命令名称:more命令所在路径:/bin/more执行权限:所有用户语法:more [文件名](空格) 或f 显示下一页(Enter) 显示下一行q或Q 退出功能描述:分页显示文件内容范例: $ more /etc/services


文件处理指令:head指令名称:head指令所在路径:/bin/head执行权限:All User语法:head -num [文件名]-num 显示文件的前num行功能描述:查看文件的前几行范例:$ head -20 /etc/services

文件处理指令:tail指令名称:tail指令所在路径:/bin/tail执行权限:All User语法:tail -num [文件名]-num 显示文件的后num行-f 动态显示文件内容功能描述:查看文件的后几行范例: $ tail -30 /etc/services

文件处理命令:ln命令名称:ln命令英文原意:link命令所在路径:/bin/ln执行权限:所有用户语法:ln -s [源文件] [目标文件]-s 创建软链接功能描述:产生链接文件范例:$ ln -s /etc/issue /issue.soft创建文件/etc/issue的软链接/issue.soft$ ln /etc/issue /issue.hard创建文件/etc/issue的硬链接/issue.hard



? 权限管理命令
权限管理命令:chmod命令名称:chmod命令英文原意:change the permissions mode of a file命令所在路径:/bin/chmod执行权限:所有用户语法:chmod [{ugo}{+-=}{rwx}] [文件或目录][mode=421 ] [文件或目录]功能描述:改变文件或目录权限范例:$ chmod g+w file1赋予文件file1所属组写权限$ chmod 777 dir1设定目录dir1为所有用户具有全部权限







权限管理命令:chown命令名称:chown命令英文原意:change file ownership命令所在路径:/bin/chown执行权限:所有用户语法:chown [用户] [文件或目录]功能描述:改变文件或目录的所有者范例:$ chown nobody file1改变文件file1的所有者为nobody

权限管理命令:chgrp命令名称:chgrp命令英文原意:change file group ownership命令所在路径:/bin/chgrp执行权限:所有用户语法:chgrp [用户组] [文件或目录]功能描述:改变文件或目录的所属组范例:$ chgrp adm file1改变文件file1的所属组为adm

权限管理命令:umask命令名称:umask命令所在路径:/bin/umask执行权限:所有用户语法:umask [-S]-S 以rwx形式显示新建文件或目录缺省权限功能描述:显示、设置文件的缺省权限范例: $ umask$ umask -S

? 若用户建立为”文件”则默认“没有可执行(x)项目”,即只有rw这两个项目,也就是最大为666分,默认属性如下:
-rw-rw-rw-
? 若用户建立为”目录”,则由于x与是否可以进入此目录有关,因此默认为所有权限均开放,即为777分,默认属性如下:
drwxrwxrwx
umask指定的是“该默认值需要减掉的权限”。因为r、w、x分别是4、2、1,所以。也就是说,当要去掉能写的权限,就是输入2,而如果要去掉能读的权限,也就是4,那么要去掉读与写的权限,也就是6,而要去掉执行与写入的权限,也就是3。

? 文件搜索命令
文件搜索命令:which命令名称:which命令所在路径:/usr/bin/which执行权限:所有用户语法:which [命令名称]功能描述:显示系统命令所在目录范例:$ which ls

文件搜索命令:find命令名称:find命令所在路径:/usr/bin/find执行权限:所有用户语法:find [搜索路径] [搜寻关键字]功能描述:查找文件或目录范例:$ find /etc -name init在目录/etc中查找文件init









文件搜索指令:locate指令名称:locate指令英文原义:list files in databases指令所在路径:/usr/bin/locate执行权限:All User语法:locate [搜索关键字]功能描述:寻找文件或目录范例: $ locate file列出所有跟file相关的文件

文件搜索指令:updatedb指令名称:updatedb指令英文原义:update the slocate database指令所在路径:/usr/bin/updatedb执行权限:root语法:updatedb功能描述:建立整个系统目录文件的数据库范例:# updatedb

文件搜索命令:grep命令名称:grep命令所在路径:/bin/grep执行权限:所有用户语法:grep [指定字串] [源文件]功能描述:在文件中搜寻字串匹配的行并输出范例:# grep ftp /etc/services

? 帮助命令
帮助命令:man命令名称:man命令英文原意:manual命令所在路径:/usr/bin/man执行权限:所有用户语法:man [命令或配置文件]功能描述:获得帮助信息范例: $ man ls查看ls命令的帮助信息



man passwd 查询passwd命令的帮助信息等价于man 1 passwd


查询/etc/passwd配置文件的帮助信息可以使用man 5 passwd

帮助指令:info指令名称:info指令英文原义:information指令所在路径:/usr/bin/info执行权限:All User语法:info [任何关键字]功能描述:获得帮助信息范例: $ info ls查看ls指令的帮助信息

帮助指令:whatis指令名称:whatis apropos makewhatis指令英文原义:search the whatis database for strings指令所在路径:/usr/bin/whatis apropos/usr/sbin/makewhatis执行权限:All User, All User,root语法:whatis apropos [任何关键字]功能描述:获得索引的简短说明信息范例: $ whatis ls



# makewhatis建立whatis和apropos搜索使用的数据库,当使用这两个命令发生错误时,就是whatis database没有建立
help 查询shell内置命令帮助


? 压缩解压命令压缩解压命令:gzip命令名称:gzip命令英文原意:GNU zip命令所在路径:/bin/gzip执行权限:所有用户语法:gzip 选项[文件]功能描述:压缩文件压缩后文件格式:.gz

压缩解压命令:gunzip命令名称:gunzip命令英文原意:GNU unzip命令所在路径:/bin/gunzip执行权限:所有用户语法:gunzip 选项[压缩文件]功能描述:解压缩.gz的压缩文件范例: $ gunzip file1.gz

压缩解压命令:tar命令名称:tar命令所在路径:/bin/tar执行权限:所有用户语法:tar 选项[cvf] [目录]-c 产生.tar打包文件-v 显示详细信息-f 指定压缩后的文件名-z 打包同时压缩功能描述:打包目录压缩后文件格式:.tar.gz范例:$ tar -zcvf dir1.tar.gz dir1将目录dir1压缩成一个打包并压缩的文件


压缩解压命令:zip命令名称:zip命令所在路径:/usr/bin/zip执行权限:所有用户语法:zip 选项[-r] [压缩后文件名称] [文件或目录]-r 压缩目录功能描述:压缩文件或目录压缩后文件格式:.zip范例:$ zip services.zip /etc/services压缩文件$ zip -r test.zip /test压缩目录

压缩解压命令:unzip命令名称:unzip命令所在路径:/usr/bin/unzip执行权限:所有用户语法:unzip [压缩文件]功能描述:解压.zip的压缩文件范例:$ unzip test.zip
压缩解压命令:bzip2命令名称:bzip2命令所在路径:/usr/bin/bzip2执行权限:所有用户语法: bzip2 选项[-k] [文件]-k 产生压缩文件后保留原文件功能描述:压缩文件压缩后文件格式:.bz2范例:$ bzip2 -k file1
压缩解压命令:bunzip2命令名称:bunzip2命令所在路径:/usr/bin/bunzip2执行权限:所有用户语法: bunzip2 选项[-k] [压缩文件]-k 解压缩后保留原文件功能描述:解压缩范例:$ bunzip2 -k file1.bz2

? 网络通信命令网络通信指令:write指令名称:write指令所在路径:/usr/bin/write执行权限:All User语法:write <用户名>功能描述:向另外一个用户发信息,以Ctrl+D作为结束范例: $ write webmaster

网络通信指令:wall指令名称:wall指令所在路径:/usr/bin/wall执行权限:All User语法:wall [message] [文件名]功能描述:向所有用户广播信息范例: $ wall Happy New Year!

网络通信命令:ping命令名称:ping命令所在路径:/usr/sbin/ping执行权限:root语法:ping 选项IP地址功能描述:测试网络连通性范例: # ping 192.168.1.1

网络通信命令:ifconfig命令名称:ifconfig命令所在路径:/usr/sbin/ifconfig执行权限:root语法:ifconfig 选项[-a] [网卡设备标识]-a 显示所有网卡信息功能描述:查看网络设置信息范例:# ifconfig -a

? 系统关机命令
系统关机命令:shutdown命令名称:shutdown命令所在路径:/usr/sbin/shutdown执行权限:root语法:shutdown功能描述:关机范例:# shutdown -h now

系统关机命令:reboot命令名称:reboot命令所在路径:/usr/sbin/reboot执行权限:root语法:reboot功能描述:重启系统范例:# reboot

? Shell应用技巧
? 命令别名命令补齐命令补齐允许用户输入文件名起始的若干个字母后,按<Tab>键补齐文件名。命令历史命令历史允许用户浏览先前输入的命令并重新调用它们,用history命令可以显示命令列表,按方向键↑和↓可查找以前执行过的命令。


? 输入/输出重定向同标准I/O一样,Shell对于每一个进程预先定义3个文件描述字(0、1、2)。分别对应于:0 (STDIN)标准输入;1 (STDOUT)标准输出;2 (STDERR)标准错误输出。>或>> 输出重定向范例:ls -l /tmp > /tmp.msg>>追加信息date >> /tmp.msg



? 管道管道:将一个命令的输出传送给另一个命令,作为另一个命令的输入。使用方法:命令1|命令2|命令3……|命令n范例:? ls -l /etc | more


? 命令连接符;用;间隔的各命令按顺序依次执行。




END