您的位置:首页 > 其它

[9月12日任务]相对和绝对路径、目录的创建和删除、cd和rm命令 3ff8

2018-09-12 11:29 471 查看
9月12日任务

2.6 相对和绝对路径

2.7 cd命令

2.8 创建和删除目录mkdir/rmdir

2.9 rm命令

绝对/相对路径

绝对路径:从根目录/开始的完整路径表示

相对路径:相对于当前所在目录位置的路径表示

使用pwd可以查看当前所在的目录(绝对路径表示)

[root@centos64-01 ~]# ls       # ls命令 --> 相对路径表示
anaconda-ks.cfg
[root@centos64-01 ~]# ls /root/anaconda-ks.cfg   # ls命令 --> 绝对路径表示
/root/anaconda-ks.cfg
[root@centos64-01 ~]# cat /etc/hostname
centos64-01
[root@centos64-01 ~]# pwd    # 查看当前路径
/root
[root@centos64-01 ~]#


cd命令

切换当前工作目录

cd - 切换到上次所在目录

cd .. 切换到父目录

cd ~ 切换到用户家目录

cd DIR 切换到目录(绝对/相对路径表示)

[root@centos64-01 ~]# cd /etc/sysconfig/   # 切换到指定目录
[root@centos64-01 sysconfig]# cd -
/root
[root@centos64-01 ~]# cd -
/etc/sysconfig
[root@centos64-01 sysconfig]# pwd   # pwd
/etc/sysconfig
[root@centos64-01 sysconfig]# cd -   # 切换到前次工作目录,即/root
/root
[root@centos64-01 ~]# pwd
/root
[root@centos64-01 ~]# cd ~  # 切换到用户家目录,即/root
[root@centos64-01 ~]# cd ..   # 切换到父目录,这里的父目录就是/
[root@centos64-01 /]# cd ..
[root@centos64-01 /]#


创建/删除目录

mkdir创建目录

-v参数:创建目录并显示创建过程

-p参数:一次性创建多级目录

备注:系统中没有tree命令,可以使用yum进行安装:yum install -y tree

rmdir删除目录

!!不能删除包含文件的目录,只能删除空目录

-p参数:级联删除多级目录(配置-v显示详细信息)

这里有个限制,从最底层开始删除,当哪一层非空,将停止删除

[root@centos64-01 /]# mkdir /tmp/aminglinux
[root@centos64-01 /]# ls -ld /tmp/aminglinux
drwxr-xr-x. 2 root root 6 9月  12 10:50 /tmp/aminglinux
[root@centos64-01 /]# date
2018年 09月 12日 星期三 10:51:15 CST
[root@centos64-01 /]# mkdir -p /tmp/aminglinux/1/2/
[root@centos64-01 /]# ls -l /tmp/aminglinux
总用量 0
drwxr-xr-x. 3 root root 15 9月  12 10:52 1
[root@centos64-01 /]# mkdir -pv /tmp/aminglinux/2/3/4
mkdir: 已创建目录 "/tmp/aminglinux/2"
mkdir: 已创建目录 "/tmp/aminglinux/2/3"
mkdir: 已创建目录 "/tmp/aminglinux/2/3/4"
[root@centos64-01 /]# ls -l /tmp/aminglinux/1
总用量 0
drwxr-xr-x. 2 root root 6 9月  12 10:52 2
[root@centos64-01 /]# rmdir /tmp/aminglinux/2
rmdir: 删除 "/tmp/aminglinux/2" 失败: 目录非空
[root@centos64-01 /]# rmdir /tmp/aminglinux/2/3/4/
[root@centos64-01 /]# touch /tmp/aminglinux/2/3/1.txt
[root@centos64-01 /]# ls /tmp/aminglinux/2/3/
1.txt
[root@centos64-01 /]# tree /tmp/aminglinux/
/tmp/aminglinux/
├── 1
│   └── 2
└── 2
└── 3
└── 1.txt

4 directories, 1 file
[root@centos64-01 /]#


rm命令

rm -r 删除目录

rm -f 强制删除文件或目录(配合-r)

rm -i 删除时询问是否删除(默认rm即为rm -i)

rm -rf DIR --> 强制删除目录(包括其中的所有文件和目录),不会提示,所以要小心使用!!

关于删除过程:先删除最底层目录下的文件,再删除目录,然后依次执行,直至删除完毕。

!command:执行历史执行过的command开头的命令

使用history命令可以查看系统历史命令

[root@centos64-01 /]# rm remove ^C
[root@centos64-01 /]# rm /tmp/aminglinux/2/3/1.txt
rm:是否删除普通空文件 "/tmp/aminglinux/2/3/1.txt"?y
[root@centos64-01 /]# tree /tmp/aminglinux/
/tmp/aminglinux/
├── 1
│   └── 2
└── 2
└── 3

4 directories, 0 files
[root@centos64-01 /]# rm -r /tmp/aminglinux/2/3/
rm:是否删除目录 "/tmp/aminglinux/2/3/"?y
[root@centos64-01 /]# rm -rf /tmp/aminglinux/2
[root@centos64-01 /]# !tree
tree /tmp/aminglinux/
/tmp/aminglinux/
└── 1
└── 2

2 directories, 0 files
[root@centos64-01 /]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐