linux 目录创建与删除 centos7

[root@wyflinux tmp]# cd /tmp  # 进入/tmp 目录,选择在tmp联系目录创建
[root@wyflinux tmp]# mkdir -p ./test1/test2/test3/test4  # mkdir -p 直接创建多级目录,(递回)    
[root@wyflinux tmp]# ls -l  # 检查是否创建成功
total 4
-rw------- 1 root root  0 Aug 30 11:39 AliyunAssistClientSingleLock.lock
drwx------ 3 root root 17 Aug 30 11:47 systemd-private-a63b0f54ab64483da7ecfa94742378dd-chronyd.service-6eItYg
drwxr-xr-x 3 root root 19 Sep  4 12:33 test1    # 发现目录test1 创建成功
-rw-r--rw- 1 root root 49 Aug 31 12:44 test1.txt
[root@wyflinux tmp]# cd ./test1
[root@wyflinux test1]# ls # 进入test1看下级子目录是否创建成功
test2
[root@wyflinux test1]# cd ./test2
[root@wyflinux test2]# cd ./test3/test4
[root@wyflinux test4]# pwd
/tmp/test1/test2/test3/test4  # 使用pwd命令检查,发现多级目录创建成功
[root@wyflinux test4]# rmdir ./test4
rmdir: failed to remove './test4': No such file or directory
[root@wyflinux test4]# cd .
[root@wyflinux test4]# cd ..
[root@wyflinux test3]# rmdir ./test4 # rmdir 只能单个删除目录,目录内容需为空
[root@wyflinux test3]# ls
[root@wyflinux test3]# pwd
/tmp/test1/test2/test3
[root@wyflinux test3]# cd /root/tmp/
-bash: cd: /root/tmp/: No such file or directory
[root@wyflinux test3]# cd /tmp
[root@wyflinux tmp]# ls
AliyunAssistClientSingleLock.lock  systemd-private-a63b0f54ab64483da7ecfa94742378dd-chronyd.service-6eItYg  test1  test1.txt
[root@wyflinux tmp]# rm -rf ./test1 # 逐级删除太慢,回到tmp 目录,直接rm -rf 删除 目录/test1及其名下的所以目录和文件,注意rm -rf 要慎用,小心误删
[root@wyflinux tmp]# ls -l # 检查是否删除成功, 
total 4
-rw------- 1 root root  0 Aug 30 11:39 AliyunAssistClientSingleLock.lock
drwx------ 3 root root 17 Aug 30 11:47 systemd-private-a63b0f54ab64483da7ecfa94742378dd-chronyd.service-6eItYg
-rw-r--rw- 1 root root 49 Aug 31 12:44 test1.txt

 #未见test1 目录, 删除成功

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值