【Linux】——刪除目錄下的檔案的常用方法
阿新 • • 發佈:2019-01-14
使用rm -rf 目錄名字 命令即可
-r 就是向下遞迴,不管有多少級目錄,一併刪除
-f 就是直接強行刪除,不作任何提示的意思
注意:-f 一定要慎重
刪除當前目錄下的檔案
1、最經典的方法,刪除當前目錄下的所有型別的檔案
rm -f *
2、用find命令查詢普通檔案並刪除or用find命令的處理動作將其刪除
find . -type f -delete 或者 find . -type f -exec rm -f {} \;
3、刪除全部普通檔案
rm-f `find . -type f`
刪除指定目錄下的檔案
1\、最經典的方法,刪除指定目錄下的所有型別的檔案
rm -f 指定目錄*
2.、用find命令查詢指定目錄下的所有普通檔案並刪除or用find命令的處理動作將其刪除
find 指定目錄 -type f -delete或find 指定目錄 -type f -exec rm -f {} \;
4、刪除指定目錄下的全部普通檔案
rm-f `find 指定目錄 -type f`
也就是說,大多情況下:
方法一: rm file # 直接刪除
方法二: rm -i file # 刪前提示
方法三: rm -f file # 強制刪除
方法四: rm -rf /dir # 遞迴刪除
方法五 使用find命令結合-exec命令來刪除
find /tmp -type f -exec rm -rf {} \`;
方法六: 使用find命令結合xargs命令來刪除
find /tmp -type f | xargs rm -rf