2.centos 7清空文件和文件夾


1.清空文件

  測試文件:a.txt

  1)方法一,[root@centos test]# > a.txt  

[root@centos test]# cat a.txt 
1hjbfao
hjkl23o
ujl1nsd
[root@centos test]# > a.txt 
[root@centos test]# cat a.txt 
[root@centos test]# 

  2)方法二,  [root@centos test]# echo "" >a.txt

[root@centos test]# cat a.txt 
1hjbfao
hjkl23o
ujl1nsd
[root@centos test]# echo "" >a.txt 
[root@centos test]# cat a.txt 
[root@centos test]# 

  3)方法三,[root@centos test]# cat /dev/null > a.txt  

[root@centos test]# cat a.txt 
1hjbfao
hjkl23o
ujl1nsd
[root@centos test]# cat /dev/null > a.txt 
[root@centos test]# cat a.txt 
[root@centos test]# 

2.清空文件夾

  在目錄要刪除的目錄下面執行 rm -rf *  

[root@centos test01]# ll
total 4
-rw-r--r--. 1 root root  0 Aug 26 23:36 a.txt
-rw-r--r--. 1 root root 24 Aug 26 23:36 b.txt
[root@centos test01]# cd ..
[root@centos ~]# rm -rf test01/*
[root@centos ~]# ls test01/
[root@centos ~]#

 


免責聲明!

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



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