n 绝对路径:路径的写法『必定由根目录 / 写起』,例如: /usr/share/doc 。shell
n 相对路径:路径的写法『不是由 / 写起』,例如由 /usr/share/doc 要到 /usr/share/man 底下时,能够写成:『cd ../man』这就是相对路径的写法啦!相对路径意指『相对于目前工做目录的路径!』less
. 表明此层目录ide .. 表明上一层目录spa - 表明前一个工做目录unix ~ 表明『目前用户身份』所在的家目录component ~account 表明 account 这个用户的家目录(account是个帐号名称)orm |
1.cd -Change the current directory to dir视频
[root@localhost 桌面]# cd /tmp/rem
2. pwd - print name of current/working directory
mkdir [OPTION]... DIRECTORY...
[root@localhost tmp]# mkdir aaa
drwxr-xr-x. 2 root root 4096 2月 27 19:34 aaa
[root@localhost tmp]# mkdir -p bbb/ccc
drwxr-xr-x. 2 root root 4096 2月 27 19:34 aaa
drwxr-xr-x. 3 root root 4096 2月 27 19:35 bbb
drwxr-xr-x. 2 root root 4096 2月 27 19:35 ccc
[root@localhost tmp]# mkdir -m 777 ddd
drwxr-xr-x. 2 root root 4096 2月 27 19:34 aaa
drwxr-xr-x. 3 root root 4096 2月 27 19:35 bbb
drwxrwxrwx. 2 root root 4096 2月 27 19:39 ddd
4.rmdir - remove empty directories
rmdir [OPTION]... DIRECTORY...
[root@localhost tmp]# rmdir ddd
[root@localhost tmp]# rmdir -p bbb/ccc/
1.ls - list directory contents
drwxr-xr-x. 2 root root 4096 2月 27 19:34 aaa
. aaa .esd-1000 .ICE-unix .X0-lock .XIM-unix
.. .esd-0 .font-unix .Test-unix .X11-unix
aaa .esd-0 .esd-1000 .font-unix .ICE-unix .Test-unix .X0-lock .X11-unix .XIM-unix
drwxrwxrwt. 10 root root 4096 2月 27 19:43 .
145499 drwxr-xr-x. 2 root root 4096 2月 27 19:34 aaa
2.cp - copy files and directories
cp [OPTION]... SOURCE... DIRECTORY
[root@localhost tmp]# cp bbb bbb.cp
[root@localhost tmp]# cp bbb bbb.cp
-rw-rw-rw-. 1 root root 0 2月 27 19:51 bbb
[calf@localhost tmp]$ cp bbb bbb.calf #正常复制
-rw-rw-rw-. 1 root root 0 2月 27 19:51 bbb
-rw-rw-r--. 1 calf calf 0 2月 27 20:06 bbb.calf
[calf@localhost tmp]$ cp -p bbb bbb.p #保留属性的复制
-rw-rw-rw-. 1 root root 0 2月 27 19:51 bbb
-rw-rw-r--. 1 calf calf 0 2月 27 20:06 bbb.calf
-rw-rw-rw-. 1 calf calf 0 2月 27 19:51 bbb.p
[root@localhost tmp]# cp /etc/passwd /etc/shadow /etc/group .
[root@localhost tmp]# ls #复制3个文件到当前目录
3.rm - remove files or directories
aaa bbb bbb.a bbb.calf bbb.cp bbb.p
[root@localhost tmp]# rm bbb.p
[root@localhost tmp]# rm -f bbb.cp
[root@localhost tmp]# rm -rf * #删除当前目录下所有文件
[root@localhost ~]# rm -rf /tmp/* #删除/tmp目录下所有文件
[root@localhost tmp]# rm -aaa #删除失败
Try 'rm ./-aaa' to remove the file "-aaa".
Try 'rm --help' for more information.
[root@localhost tmp]# rm ./-aaa #删除成功
mv [OPTION]... SOURCE... DIRECTORY
[root@localhost tmp]# mv /root/aaa .
#移动/root/aaa到当前目录
[root@localhost tmp]# mv aaa bbb
[root@localhost tmp]# mv /root/aaa /root/ccc .
#移动多个文件到当前目录
5.basename - strip directory and suffix from filenames
[root@localhost tmp]# basename /etc/sysconfig/network
6.dirname - strip last component from file name
[root@localhost tmp]# dirname /etc/sysconfig/network
[root@localhost tmp]# file test
[root@localhost tmp]# file /bin/cd
/bin/cd: POSIX shell script, ASCII text executable
[root@localhost tmp]# file /var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db: data
1.cat - concatenate files and print on the standard output
[root@localhost tmp]# cat /etc/passwd
[root@localhost tmp]# cat -n /etc/passwd #显示行号
[root@localhost tmp]# cat -r /etc/passwd
#倒序的倒序输出文本内容
2.tac - concatenate and print files in reverse
[root@localhost tmp]# tac /etc/passwd #倒序输出文本内容
[root@localhost tmp]# nl /etc/passwd
1.more - file perusal filter for crt viewing
[root@localhost tmp]# more /etc/passwd
[root@localhost tmp]# less /etc/passwd
1.head - output the first part of files
[root@localhost tmp]# head /etc/passwd
#显示前10行内容,默认
[root@localhost tmp]# head -n 5 /etc/passwd #显示前5行内容
[root@localhost tmp]# head -n +5 /etc/passwd #显示前5行内容
[root@localhost tmp]# head -n -5 /etc/passwd
#显示倒数第5行以前的内容
2.tail - output the last part of files
[root@localhost tmp]# tail /etc/passwd #显示最后10行,默认
[root@localhost tmp]# tail -n 5 /etc/passwd #显示最后5行
[root@localhost tmp]# tail -n -5 /etc/passwd #显示最后5行
[root@localhost tmp]# tail -n +5 /etc/passwd #从第5行开始显示
注意:head的最后一个例子与tail的最后一个例子的区别。
[root@localhost tmp]# tail -f /var/log/messages
#若是message的内容继续增长,tail将继续输出增长的内容。