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

9月12日任务html

2.6 相对和绝对路径linux

2.7 cd命令centos

2.8 建立和删除目录mkdir/rmdirbash

2.9 rm命令spa

 

绝对/相对路径

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

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

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

[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命令rem

切换当前工做目录class

  • 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 /]#
相关文章
相关标签/搜索