1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 6次课(相对和绝对路径 cd命令 创建和删除目录mkdir/rmdir rm命令)

6次课(相对和绝对路径 cd命令 创建和删除目录mkdir/rmdir rm命令)

时间:2023-08-05 13:47:06

相关推荐

6次课(相对和绝对路径 cd命令 创建和删除目录mkdir/rmdir rm命令)

2.6 相对和绝对路径

绝对路径: 路径写法一定是由跟目录“/”写起的。不管在那个路径下都能通过绝对路径找到文件从根开始例如

#ls /etc/sysconfig/network-scripts/ifcfg-ens33

相对路径: 路径的写法不是由跟目录“/”写起的。相对当前的目录。例如

#ls network-scripts/ifcfg-ens33

pwd命令查看所在目录的位置

2.7 cd命令

cd - 表示上次所在的目录例如:

[root@hanshuo-10 ~]# cd /etc/sysconfig $用进入sysconfig目录

[root@hanshuo-10 sysconfig]# cd - $在sysconfig目录下使用cd -

/root $第一次使用cd -后所在目录

[root@hanshuo-10 ~]# cd - $在/root里再次使用cd -

/etc/sysconfig $第二次使用cd -后所在的目录

[root@hanshuo-10 sysconfig]# pwd $ 查看所在的目录

/etc/sysconfig

cd 用来改变用户所在目录的,如果后面什么都不跟,就直接进入当前用户的根目录下例如:

[root@hanshuo-10 ~]# cd /etc $用cd进入etc目录

[root@hanshuo-10 etc]# cd ¥在etc目录下直接输入cd

[root@hanshuo-10 ~]# #进入跟目录

cd .. 进入上一级目录,例如:

[root@hanshuo-10 ~]# cd /etc/sysconfig/network-scripts/ $ 用cd进入/etc/sysconfig/network-scripts/

[root@hanshuo-10 network-scripts]# cd .. $用cd ..进入上一级目录

[root@hanshuo-10 sysconfig]# pwd $查看目录所在

/etc/sysconfig $所在的目录

2.8 创建和删除目录mkdir/rmdir

mkdir是make directory的缩写,该命令用于创建目录该目录的格式为“mkdir [-p] [目录名称]”。其中-P可以连续创建目录,例如:

[root@hanshuo-10 ~]# mkdir /tmp/hanshuo1 $ 创建目录 /tmp/hanshuo1

[root@hanshuo-10 ~]# ls -ld /tmp/hanshuo1 $查看创建的/tmp/hanshuo1

drwxr-xr-x 2 root root 6 12月 18 22:09 /tmp/hanshuo1 $创建完的/tmp/hanshuo1

[root@hanshuo-10 ~]# date $查看创建时间

12月 18日 星期一 22:09:47 CST

[root@hanshuo-10 ~]# mkdir -p /tmp/hanshuo1/hanshuo2 $用-P连续创建目录/tmp/hanshuo1/hanshuo2

[root@hanshuo-10 ~]# ls -ld /tmp/hanshuo1/hanshuo2 $ 查看连续创建目录/tmp/hanshuo1/hanshuo2

drwxr-xr-x 2 root root 6 12月 18 22:10 /tmp/hanshuo1/hanshuo2 $连续创建完目录/tmp/hanshuo1/hanshuo2

rmdir用于删除空目录,后面可以是一个目录,也可以是多个目录。该命令只能删除目录不能删除文件。即使加上-P选项也只能删除一串空目录,

2.9 rm命令

rm命令常会用到,他是一个删除目录和文件的一个命令例如:

[root@hanshuo-10 ~]# mkdir -p hanshuo/hanshuo1/hanshuo2 $ 创建目录mkdir -p hanshuo/hanshuo1/hanshuo2

[root@hanshuo-10 ~]# touch hanshuo/hanshuo1/hanshuo2/1.txt $创建文件touch hanshuo/hanshuo1/hanshuo2/1.txt

[root@hanshuo-10 ~]# rm hanshuo/hanshuo1/hanshuo2/1.txt $删除文件rm hanshuo/hanshuo1/hanshuo2/1.txt

rm:是否删除普通空文件 "hanshuo/hanshuo1/hanshuo2/1.txt"?y $问是否删除文件点y是删除n不删除

[root@hanshuo-10 ~]# ls -ld hanshuo/hanshuo1/hanshuo2/1.txt $ 查看是否删除hanshuo/hanshuo1/hanshuo2/1.txt

ls: 无法访问hanshuo/hanshuo1/hanshuo2/1.txt: 没有那个文件或目录 $ 已删除

上边是询问是否删除如果加个-f就会强制删除。不会询问例如:

[root@hanshuo-10 ~]# touch hanshuo/hanshuo1/hanshuo2/1.txt $创建 hanshuo/hanshuo1/hanshuo2/1.txt

[root@hanshuo-10 ~]# rm -f hanshuo/hanshuo1/hanshuo2/1.txt $删除hanshuo/hanshuo1/hanshuo2/1.txt

root@hanshuo-10 ~]# ls -ld hanshuo/hansuo1/hanshuo2/1.txt $查看是否删除hanshuo/hanshuo1/hanshuo2/1.txt

ls: 无法访问hanshuo/hansuo1/hanshuo2/1.txt: 没有那个文件或目录 $没有了 已删除

上例中,是删除文件的如果删除目录会报错,即使加上-f也会报错.使用命令rm删除目录时加个-r选项,就可以删除,-rf可以删除目录和文件例如:

[root@hanshuo-10 ~]# rm -f hanshuo $删除hanshuo目录

rm: 无法删除"hanshuo": 是一个目录 $无法删除目录

[root@hanshuo-10 ~]# rm -rf hanshuo $加个-rf 就可以删除目录和文件

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。