二周第一次课(12月18日)
2.6 相对和绝对路径
2.7 cd命令
2.8 创建和删除目录mkdir/rmdir
2.9 rm命令
相对和绝对路径:
(根./)下的文件目录是绝对路径:
[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33
/etc/sysconfig/network-scripts/ifcfg-ens33
(当前目录下的文件目录)是相对路径:
[root@localhost ~]# pwd
/root
[root@localhost ~]# ls .ssh/authorized_keys
.ssh/authorized_keys
命令:
#pwd 查看当前所在的目录
#cd >> change directory 切换到指定目录
#histiory 查看使用过的命令
#!tree 查找上次使用这个命令
(cd) 命令:
# cd 回到用户家目录
# cd - 切换到上次访问的目录
# cd ~ 回到用户目录 (~)表示家目录
# cd ..切换到上级目录
[root@localhost /]# cd
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /etc/sysconfig/
[root@localhost sysconfig]# cd -
/root
[root@localhost ~]# cd -
/etc/sysconfig
[root@localhost ~]# cd ~
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /etc/sysconfig//network-scripts/
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@localhost network-scripts]# cd ..
[root@localhost sysconfig]# pwd
/etc/sysconfig
[root@localhost sysconfig]# cd ..
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd ..
[root@localhost /]# pwd
/
创建和删除目录mkdir/rmdir
(mkdir)创建
#mkdir >> make directory
#mkdir 创建目录
# mkdir -p /tmp/adkee/1/2
(-p)一次创建多个目录参数
[root@localhost ~]# mkdir /tmp/adkee
[root@localhost ~]# ls -ld /tmp/adkee
drwxr-xr-x 2 root root 6 12月 18 11:25 /tmp/adkee
[root@localhost ~]# date
2017年 12月 18日 星期一 11:29:04 CST
[root@localhost ~]# mkdir -p /tmp/adkee/1/2
[root@localhost ~]# ls -l /tmp/adkee
总用量 0
drwxr-xr-x 3 root root 15 12月 18 11:31 1
[root@localhost ~]# ls -l /tmp/adkee/1
总用量 0
drwxr-xr-x 2 root root 6 12月 18 11:31 2
(rmdir)删除
#rmdir >> remove directory
#rmdir (删除空的目录)
# rmdir -p /tmp/adkee/1/2
(-p)一次删除多个空的目录参数(目录是空的都删除)
[root@localhost ~]# rmdir /tmp/adkee/2
rmdir: 删除 "/tmp/adkee/2" 失败: 目录非空
[root@localhost ~]# rmdir /tmp/adkee/2/3
rmdir: 删除 "/tmp/adkee/2/3" 失败: 目录非空
[root@localhost ~]# rmdir /tmp/adkee/2/3/4
[root@localhost ~]# touch /tmp/adkee/2/3/1.txt
[root@localhost ~]# ls /tmp/adkee/2/3/
1.txt
[root@localhost ~]# tree /tmp/adkee/
/tmp/adkee/
├── 1
│ └── 2
└── 2
└── 3
└── 1.txt
4 directories, 1 file
[root@localhost ~]# rmdir /tmp/adkee/2/3
rmdir: 删除 "/tmp/adkee/2/3" 失败: 目录非空
[root@localhost ~]# rmdir /tmp/adkee/2/3/1.txt
rmdir: 删除 "/tmp/adkee/2/3/1.txt" 失败: 不是目录
[root@localhost ~]# rmdir -p /tmp/adkee/1/2
rmdir: 删除目录 "/tmp/adkee" 失败: 目录非空
[root@localhost ~]# tree /tmp/adkee/
/tmp/adkee/
└── 2
└── 3
└── 1.txt
2 directories, 1 file
(rm)命令:
#rm >> remove
#rm >> 删除文件和非空的目录
#em >> (-f强制) (-r删除目录,)
(-rf不提示直接文件和目录)
(*)当前目录下所以文件
[root@localhost ~]# rm /tmp/adkee/2/3/1.txt
rm:是否删除普通空文件 "/tmp/adkee/2/3/1.txt"?y
[root@localhost ~]# tree /tmp/adkee/
/tmp/adkee/
└── 2
└── 3
2 directories, 0 files
[root@localhost ~]# rm /tmp/adkee/2/3/*.txt
rm:是否删除普通空文件 "/tmp/adkee/2/3/1.txt"?n
rm:是否删除普通空文件 "/tmp/adkee/2/3/2.txt"?n
[root@localhost ~]# rm /tmp/adkee/2/3/
1.txt 2.txt
[root@localhost ~]# rm /tmp/adkee/2/3/*.txt
rm:是否删除普通空文件 "/tmp/adkee/2/3/1.txt"?n
rm:是否删除普通空文件 "/tmp/adkee/2/3/2.txt"?n
[root@localhost ~]# rm -f /tmp/adkee/2/3/*.txt
[root@localhost ~]# !tree
tree /tmp/adkee/
/tmp/adkee/
└── 2
└── 3
2 directories, 0 files
[root@localhost ~]# rm -f /tmp/adkee/2/3/
rm: 无法删除"/tmp/adkee/2/3/": 是一个目录
[root@localhost ~]# rm -r /tmp/adkee/2/3/
rm:是否删除目录 "/tmp/adkee/2/3/"?n
[root@localhost ~]# rm /tmp/adkee/2/3/
rm: 无法删除"/tmp/adkee/2/3/": 是一个目录
[root@localhost ~]# rm -r /tmp/adkee/2/3/
rm:是否进入目录"/tmp/adkee/2/3/"? y
rm:是否删除普通空文件 "/tmp/adkee/2/3/1.txt"?y
rm:是否删除普通空文件 "/tmp/adkee/2/3/2.txt"?y
rm:是否删除目录 "/tmp/adkee/2/3/"?y
[root@localhost ~]# rm -rf /tmp/adkee/2
[root@localhost ~]# !tree
tree /tmp/adkee/
/tmp/adkee/
0 directories, 0 files
[root@localhost ~]# !mkdir
mkdir -pv /tmp/adkee/2/3/4
mkdir: 已创建目录 "/tmp/adkee/2"
mkdir: 已创建目录 "/tmp/adkee/2/3"
mkdir: 已创建目录 "/tmp/adkee/2/3/4"
[root@localhost ~]# mkdir -pv /tmp/adkee/2/3/
[root@localhost ~]# !tree
tree /tmp/adkee/
/tmp/adkee/
└── 2
└── 3
└── 4
3 directories, 0 files
[root@localhost ~]# !touch
touch /tmp/adkee/2/3/2.txt
[root@localhost ~]# touch /tmp/adkee/2/3/1.txt
[root@localhost ~]# touch /tmp/adkee/2/1.txt
[root@localhost ~]# !tree
tree /tmp/adkee/
/tmp/adkee/
└── 2
├── 1.txt
└── 3
├── 1.txt
├── 2.txt
└── 4
3 directories, 3 files
[root@localhost ~]# rm -rfv /tmp/adkee/2/3
已删除目录:"/tmp/adkee/2/3/4"
已删除"/tmp/adkee/2/3/2.txt"
已删除"/tmp/adkee/2/3/1.txt"
已删除目录:"/tmp/adkee/2/3"
[root@localhost ~]# !tree
tree /tmp/adkee/
/tmp/adkee/
└── 2
└── 1.txt
1 directory, 1 file