刪除超大量 (eg 5000+) 檔案
如果嘗試使用 rm -f * 刪除超大量檔案 (eg 5000+),有可能會得到這個結果: Argument list too long
這種情況下唯有使用 FOR 迴圈,以一個指令便可把檔案逐個刪除:
for i in $(find /home/peter -type f); do rm -f $i; done
或者照樣使用 FOR 迴圈寫一個 Shell Script,每次刪除 10 個檔案 (沒測試過, USE AT YOUR OWN RISK):
- #!/bin/sh
- FILES="";
- i=1;
- for i in $(find /home/peter -type f); do
- FILES="${FILES} $i"
- if [ $index -eq 10 ]; then
- rm -f $FILES
- i=0
- fi
- i=`expr $i + 1`
- done
No Comments »
RSS feed for comments on this post. TrackBack URL
Leave a comment
You must be logged in to post a comment.