相对和绝对路径
绝对路径
绝对路径是从根开始的
[root@lynn-05 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33
/etc/sysconfig/network-scripts/ifcfg-ens33 [root@lynn-05 ~]# ls /root/anaconda-ks.cfg /root/anaconda-ks.cfg
相对路径
相对路径是相对现在位置的路径
pwd是查看当前目录的命令
[root@lynn-05 ~]# pwd
/root [root@lynn-05 ~]# ls -a . .bash_history .bash_profile .cshrc .tcshrc .. .bash_logout .bashrc .ssh anaconda-ks.cfg [root@lynn-05 ~]# ls .bash_history .bash_history [root@lynn-05 ~]# ls .bash_profile .bash_profile
CD命令
cd 就是change directory 进入到一个目录里 不能打开文件
[root@lynn-05 /]# pwd
/ [root@lynn-05 /]# cd /etc/sysconfig [root@lynn-05 sysconfig]# pwd /etc/sysconfig [root@lynn-05 sysconfig]# cd network-scripts/ifcfg-ens33 -bash: cd: network-scripts/ifcfg-ens33: 不是目录
cd - 返回上次所在目录
[root@lynn-05 /]# pwd
/ [root@lynn-05 /]# cd /etc/sysconfig [root@lynn-05 sysconfig]# pwd /etc/sysconfig [root@lynn-05 sysconfig]# cd - / [root@lynn-05 /]# pwd / [root@lynn-05 /]# cd - /etc/sysconfig [root@lynn-05 sysconfig]# pwd /etc/sysconfig
cd 进入当前用户的家目录
[root@lynn-05 ~]# cd /etc/sysconfig
[root@lynn-05 sysconfig]# pwd /etc/sysconfig [root@lynn-05 sysconfig]# cd [root@lynn-05 ~]# pwd /root
cd .. 去到上一级目录 根目录是最上面的目录所以最终只到了根目录
[root@lynn-05 ~]# cd /etc/sysconfig/network-scripts
[root@lynn-05 network-scripts]# pwd /etc/sysconfig/network-scripts [root@lynn-05 network-scripts]# cd .. [root@lynn-05 sysconfig]# pwd /etc/sysconfig [root@lynn-05 sysconfig]# cd .. [root@lynn-05 etc]# pwd /etc [root@lynn-05 etc]# cd .. [root@lynn-05 /]# pwd / [root@lynn-05 /]# cd .. [root@lynn-05 /]# pwd / [root@lynn-05 /]#
创建目录mkdir
mkdir 就是make directory 创建目录
[root@lynn-05 /]# mkdir tmp/lynn
[root@lynn-05 /]# ls -ld /tmp/lynn drwxr-xr-x. 2 root root 6 Dec 16 22:21 /tmp/lynn
mkdir -p 创建一连串的目录
[root@lynn-05 /]# mkdir /tmp/lynn/1/2/3
mkdir: cannot create directory '/tmp/lynn/1/2/3': No such file or directory [root@lynn-05 /]# mkdir -p /tmp/lynn/1/2/3 [root@lynn-05 /]# ls /tmp/lynn 1 [root@lynn-05 /]# ls /tmp/lynn/1 2 [root@lynn-05 /]# ls /tmp/lynn/1/2 3
mkdir -pv 可视化的创建目录 这是v选项的功能
[root@lynn-05 /]# mkdir -pv /tmp/lynn/2/3/4
mkdir: created directory '/tmp/lynn/2' mkdir: created directory '/tmp/lynn/2/3' mkdir: created directory '/tmp/lynn/2/3/4'
删除目录rmdir
rmdir 就是 remove directory 删除空目录
[root@lynn-05 /]# tree /tmp/lynn
/tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 2 `-- 35 directories, 0 files
[root@lynn-05 /]# rmdir /tmp/lynn/2 rmdir: failed to remove '/tmp/lynn/2': Directory not empty [root@lynn-05 /]# rmdir /tmp/lynn/2/3 [root@lynn-05 /]# tree /tmp/lynn /tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 24 directories, 0 files
[root@lynn-05 /]# touch /tmp/lynn/2/1.txt [root@lynn-05 /]# tree /tmp/lynn /tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 2 `-- 1.txt4 directories, 1 file
[root@lynn-05 /]# rmdir /tmp/lynn/2 rmdir: failed to remove '/tmp/lynn/2': Directory not empty
rmdir -p 删除一连串空目录
[root@lynn-05 /]# tree /tmp/lynn
/tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 24 directories, 0 files
[root@lynn-05 /]# rmdir -p /tmp/lynn/1/2/3 rmdir: failed to remove directory '/tmp/lynn': Directory not empty [root@lynn-05 /]# tree /tmp/lynn /tmp/lynn `-- 21 directory, 0 files
rm命令
rm 可以删空目录也可以删文件 删目录 要加-r
[root@lynn-05 /]# tree /tmp/lynn
/tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 2 `-- 1.txt4 directories, 1 file
[root@lynn-05 /]# rm /tmp/lynn/2/1.txt rm: remove regular empty file '/tmp/lynn/2/1.txt'? y [root@lynn-05 /]# tree /tmp/lynn /tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 24 directories, 0 files
[root@lynn-05 /]# tree /tmp/lynn /tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 24 directories, 0 files
[root@lynn-05 /]# rm /tmp/lynn/1/2 rm: cannot remove '/tmp/lynn/1/2': Is a directory [root@lynn-05 /]# rm -r /tmp/lynn/1/2 rm: descend into directory '/tmp/lynn/1/2'? y rm: remove directory '/tmp/lynn/1/2/3'? y rm: remove directory '/tmp/lynn/1/2'? y [root@lynn-05 /]# tree /tmp/lynn /tmp/lynn |-- 1 `-- 22 directories, 0 files
rm -f 强制删除 不询问
[root@lynn-05 /]# tree /tmp/lynn
/tmp/lynn |-- 1 | `-- 2 | `-- 3 |-- 1.txt |-- 2 `-- 2.txt4 directories, 2 files
[root@lynn-05 /]# rm /tmp/lynn/1.txt rm: remove regular empty file '/tmp/lynn/1.txt'? y [root@lynn-05 /]# tree /tmp/lynn /tmp/lynn |-- 1 | `-- 2 | `-- 3 |-- 2 `-- 2.txt4 directories, 1 file
[root@lynn-05 /]# rm -f /tmp/lynn/2.txt [root@lynn-05 /]# tree /tmp/lynn /tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 24 directories, 0 files
history 查看历史命令
[root@lynn-05 /]# history
1 who 2 ls -la 3 hostnamectl set-hostname Lynn-01 4 init 6 5 init 0 6 ip addr 7 dhclient 8 ip addr . . . 235 touch /tmp/lynn/1.txt 236 touch /tmp/lynn/2.txt 237 tree /tmp/lynn 238 rm /tmp/lynn/1.txt 239 tree /tmp/lynn 240 rm -f /tmp/lynn/2.txt 241 tree /tmp/lynn 242 history
! 命令 执行历史命令里 最近这个命令 历史命令参照上面history
[root@lynn-05 /]# !tree
tree /tmp/lynn /tmp/lynn |-- 1 | `-- 2 | `-- 3 `-- 24 directories, 0 files
友情链接: