(三)目录的相关操作:cd、pwd、mkdir、rmdir
cd(变换目录)
. 代表此层目录
.. 代表上一层目录
- 代表前一个工作目录
~ 代表【目前使用者身份】所在的家目录
[root@localhost /]# cd ~ //回到家目录/root目录 [root@localhost ~]# cd //未加路径,回到自己家目录 [root@localhost ~]# cd .. //返回上一级目录 [root@localhost /]# cd - //回到之前的目录 /root [root@localhost ~]#
pwd(显示目前所在的目录)
写法: pwd [-P] -P:显示出确实的路径,而非使用连结(link)路径
[root@localhost ~]# pwd //显示当前目录 /root [root@localhost ~]# cd /var/mail //进入到 /var/mail [root@localhost mail]# pwd /var/mail [root@localhost mail]# pwd -P //显示完整路径 /var/spool/mail [root@localhost mail]#
mkdir(建立新目录)
写法:mkdir [-mp]目录名称
-m:设定档案的权限
-p:帮助你直接将所需要的目录递归建立起来
[root@localhost tmp]# mkdir test //创建一个test文件 mkdir: 无法创建目录"test": 文件已存在 [root@localhost tmp]# ls -l 总用量 4 srwxrwxrwx. 1 root root 0 8月 10 21:37 fcoemon.dcbd.1242 srwxrwxrwx. 1 root root 0 8月 11 19:44 fcoemon.dcbd.1521 drwxr--r--. 2 root root 4096 8月 11 03:37 test -rw-------. 1 root root 0 8月 10 21:07 yum.log [root@localhost tmp]# mkdir test1/test2/test3 mkdir: 无法创建目录"test1/test2/test3": 没有那个文件或目录 [root@localhost tmp]# mkdir -p test1/test2/test3 //加了-p参数,可以自行建立多层目录 [root@localhost tmp]# mkdir -m 711 test2 //给test2目录赋权 [root@localhost tmp]# ls -l 总用量 12 srwxrwxrwx. 1 root root 0 8月 10 21:37 fcoemon.dcbd.1242 srwxrwxrwx. 1 root root 0 8月 11 19:44 fcoemon.dcbd.1521 drwxr--r--. 2 root root 4096 8月 11 03:37 test drwxr-xr-x. 3 root root 4096 8月 11 20:30 test1 drwx--x--x. 2 root root 4096 8月 11 20:30 test2 -rw-------. 1 root root 0 8月 10 21:07 yum.log [root@localhost tmp]#
rmdir(删除[空]的目录)
写法:rmdir [-p] 目录名称 -p:连同上层空的目录也一起删除
1 [root@localhost tmp]# mkdir -p qq1/qq2/qq3/qq4 2 [root@localhost tmp]# ls -l 3 总用量 4 4 srwxrwxrwx. 1 root root 0 8月 10 21:37 fcoemon.dcbd.1242 5 srwxrwxrwx. 1 root root 0 8月 11 19:44 fcoemon.dcbd.1521 6 drwxr-xr-x. 3 root root 4096 8月 11 22:21 qq1 7 -rw-------. 1 root root 0 8月 10 21:07 yum.log 8 [root@localhost tmp]# cd qq1 9 [root@localhost qq1]# ls -l 10 总用量 4 11 drwxr-xr-x. 3 root root 4096 8月 11 22:21 qq2 12 [root@localhost qq1]# cd qq2/ 13 [root@localhost qq2]# ls -l 14 总用量 4 15 drwxr-xr-x. 3 root root 4096 8月 11 22:21 qq3 16 [root@localhost qq2]# cd qq3/ 17 [root@localhost qq3]# ls -l 18 总用量 4 19 drwxr-xr-x. 2 root root 4096 8月 11 22:21 qq4 20 [root@localhost ~]# cd /tmp 21 [root@localhost tmp]# rmdir -p qq1/qq2/qq3/qq4 22 [root@localhost tmp]# ls -l 23 总用量 0 24 srwxrwxrwx. 1 root root 0 8月 10 21:37 fcoemon.dcbd.1242 25 srwxrwxrwx. 1 root root 0 8月 11 19:44 fcoemon.dcbd.1521 26 -rw-------. 1 root root 0 8月 10 21:07 yum.log 27 [root@localhost tmp]#


浙公网安备 33010602011771号