2.6绝对路径和相对路径
1.绝对路径
从根开始的路径都是绝对路径。
用pwd命令查看当前的目录
[[email protected] ~]# pwd
/root
2相对路经
相对于你所在位置的路径。也就是相对当前目录。
例如:以下文件路径为相对路径,相对于root下的文件路径
[[email protected] ~]#.ssh/authorized_keys
.ssh/authorized_keys
[[email protected] ~]#cd /etc/sysconfig/
[[email protected] sysconfig]# lsnetwork-scripts/ifcfg-ens33
Network-scripts/ifcfg-ens33
[[email protected] sysconfig]# pwd
/etc/sysconfig
[[email protected] sysconfig]# cd /tmp
[[email protected] tmp]# pwd
/tmp
Cd就是change directory
2.7 cd命令
1. cd –
例如:
[[email protected] sysconfig]# cd –
/root
[[email protected] ~]#cd –
/etc/sysconfig/
[[email protected] sysconfig]#pwd
/etc/sysconfig
2.cd ~
相当于/root
例如:
[[email protected] sysconfig]#cd ~
[[email protected] ~]#
[[email protected] sysconfig]# cd /tmp
[[email protected] tmp]# cd ~
[[email protected] ~]#
3. cd ..
进入到上一级目录
例如:
[[email protected] ~]#cd ..
[[email protected] /]cd /etc/sysconfig
[[email protected] sysconfig]#cd ..
[[email protected] etc]#
2.8创建和删除目录mkdir rmdir
1. 创建目录mkdir(makedirectory)
例如:
[[email protected] ~]#mkdir /tmp/centos7
[[email protected] ~]# ls -l /tmp/centos7
总用量0
[[email protected] ~]#ls –l/tmp/
在centos7目录下能一下把子目录都建立的命令如下:(在mkdir后加上-p)
[[email protected] ~]#mkdir –p /tmp/centos7/1/2
[[email protected] tmp]# ls -l /tmp/centos7
总用量 0
drwxr-xr-x. 3 root root 15 6月 4 21:09 1
[[email protected] tmp]# ls -l /tmp/centos7/1
总用量 0
drwxr-xr-x. 2 root root 6 6月 4 21:09 2
创建目录时能看到创建目录的过程的命令(在mkdir 后加-pv):
[[email protected] ~]#mkdir –pv /tmp/centos7/2/3/4
mkdir: 已创建目录 "/tmp/centos7/2"
mkdir: 已创建目录 "/tmp/centos7/2/3"
mkdir: 已创建目录 "/tmp/centos7/2/3/4"
2. 删除目录(rmdir==remove directory)
只能删除空目录
[[email protected] tmp]# rmdir/tmp/centos7/2/3/4
[[email protected] tmp]# ls -l/tmp/centos7/2/3
总用量 0
[[email protected] tmp]# ls -ld/tmp/centos7/2/3
drwxr-xr-x. 2 root root 6 6月 4 21:28 /tmp/centos7/2/3
[[email protected] tmp]# ls -ld/tmp/centos7/2/3/4
ls: 无法访问/tmp/centos7/2/3/4: 没有那个文件或目录
Touch用来创建一个空白文件的。
例如:
[[email protected] tmp]# touch/tmp/centos7/2/3/1.txt
[[email protected] tmp]# tree /tmp/centos7
/tmp/centos7
├── 1
│ └── 2
└── 2
└── 3
└── 1.txt
4 directories, 1 file
级联删除空目录:rmdir-p
[[email protected] tmp]# rmdir -p/tmp/centos7/1/2
rmdir: 删除目录 "/tmp/centos7" 失败: 目录非空
[[email protected] tmp]# tree /tmp/centos7
/tmp/centos7
└── 2
└── 3
└── 1.txt
2 directories, 1 file
2.9 rm命令(remove)
1. rm可以删除文件,也可以删除非空的目录
[[email protected] tmp]# rm/tmp/centos7/2/3/1.txt
rm:是否删除普通空文件"/tmp/centos7/2/3/1.txt"?y
[[email protected] tmp]# tree /tmp/centos7
/tmp/centos7
└── 2
└── 3
1.1 rm -f:强制删除文件,没有问题确认。
[[email protected] tmp]# touch /tmp/centos7/2/3/2.txt
[[email protected] tmp]# tree /tmp/centos7
/tmp/centos7
└── 2
└── 3
├── 1.txt
└── 2.txt
2 directories, 2 files
[[email protected] tmp]# rm/tmp/centos7/2/3/*.txt
rm:是否删除普通空文件"/tmp/centos7/2/3/1.txt"?n
rm:是否删除普通空文件"/tmp/centos7/2/3/2.txt"?n
[[email protected] tmp]# rm -f/tmp/centos7/2/3/*.txt
[[email protected] tmp]# tree /tmp/centos7
/tmp/centos7
└── 2
└── 3
2 directories, 0 files
*History命令:查看历史命令记录
*!tree命令(找到最近一次tree命令)
[[email protected] tmp]#!tree
tree /tmp/centos7
/tmp/centos7
└── 2
└── 3
2 directories, 0 files
1.2 rm –r (删除非空目录和文件)
[[email protected] tmp]# rm -r/tmp/centos7/2/3
rm:是否进入目录"/tmp/centos7/2/3"?y
rm:是否删除普通空文件"/tmp/centos7/2/3/1.txt"?y
rm:是否删除目录"/tmp/centos7/2/3"?y
[[email protected] tmp]# tree /tmp/centos7
/tmp/centos7
└── 2
1 directory, 0 files
*rm –rf (强制删除非空目录和文件)
[[email protected] tmp]# rm -rf/tmp/centos7/2/3
[[email protected] tmp]# tree /tmp/centos7
/tmp/centos7
└── 2
1 directory, 0 files
*rm -rfv强制删除非空目录和文件并可以看到删除过程
[[email protected] tmp]# rm -rfv/tmp/centos7/2/3
已删除"/tmp/centos7/2/3/1.txt"
已删除目录:"/tmp/centos7/2/3"
如果再次执行已删除文件的命令,会出现如下效果:
[[email protected] tmp]# rm -rfv/tmp/centos7/2/3
[[email protected] tmp]# rm -rv/tmp/centos7/2/3
rm: 无法删除"/tmp/centos7/2/3": 没有那个文件或目录