2014-01-30 54 views
1

我有一個基於Linux的服務器,我使用它來做一些文件管理並服務於我的多個其他服務器。參數列表太長錯誤rm命令

基本上這個服務器(服務器1說)取輸入作爲從其他服務器.MP3文件,並將其轉換爲其他文件格式(.WAV,.txt和.XML),併發送至其他服務器的詢問響應。

在一段時間內,我的這個文件夾(Say/Somepath/MyInputFolder)現在已經有數據需要刪除。

我試過rm -r *命令,但它說:

Argument list too long 

我也試過rm -r *.mp3rm -r *.txt單獨刪除這些文件,但它給出了同樣的錯誤。

我也試過這個SO question並閱讀了這個link

我試着解決上面這個問題,並得到了錯誤警告。

find . -name "*.txt" -maxdepth 1 -print0 | xargs -0 rm 
find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments. 

我該如何做到這一點?

+0

也嘗試過這個鏈接中提到的參數http://en.kioskea.net/faq/1086-unable-to-delete-file-argument-list-too-long – Aditya

回答

3

正如您在所鏈接的答案的評論中已經指出的那樣,您需要將-maxdepth直接放在路徑後面。像這樣:

find . -maxdepth 1 -name "*.txt" -print0 | xargs -0 rm 
2

我也有同樣的例外。我有超過1lakh文件。 這裏是你需要-f ls|tail -10000

執行10次重複運行

$ RM命令。

+0

聰明的技巧! – Diego

2
ls | tail -10000 | xargs rm -rf 

執行次數更多。

2

這已被回答,但我想補充一點,這些會遇到這個問題。

find有它自己的-delete選項,它將刪除它找到的文件。因此,你可以簡單地做:

find -maxdepth 1 -name "*.txt" -delete 

如果你有興趣閱讀更多關於這個問題,我建議this link

+0

感謝Ramy,+1爲您努力解決此問題。 :) – Aditya