linux系統中只刪除所有文件或只刪除所有目錄


 

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM