1、创建测试数据

[root@centos7 test2]# touch a.txt b.txt c.txt; mkdir test01 test02 test03
[root@centos7 test2]# ls
a.txt  b.txt  c.txt  test01  test02  test03

 

2、删除所有文件

[root@centos7 test2]# ls --file-type
a.txt  b.txt  c.txt  test01/  test02/  test03/
[root@centos7 test2]# ls --file-type | grep -v "/$"
a.txt
b.txt
c.txt
[root@centos7 test2]# ls --file-type | grep -v "/$" | xargs rm -f
[root@centos7 test2]# ls
test01  test02  test03

 

3、删除所有的目录文件

[root@centos7 test2]# touch a.txt b.txt c.txt
[root@centos7 test2]# ls
a.txt  b.txt  c.txt  test01  test02  test03
[root@centos7 test2]# ls --file-type
a.txt  b.txt  c.txt  test01/  test02/  test03/
[root@centos7 test2]# ls --file-type | grep "/$"
test01/
test02/
test03/
[root@centos7 test2]# ls --file-type | grep "/$" | xargs rm -rf
[root@centos7 test2]# ls
a.txt  b.txt  c.txt

 

相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2022-01-29
  • 2022-01-06
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-16
  • 2021-12-01
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案