参数列表太长错误rm命令

时间:2014-01-30 08:12:51

标签: linux rm

我有一个基于Linux的服务器,我使用它来做一些文件管理,并为我的其他多个服务器提供服务。

基本上这个服务器(比如server1)从其他服务器获取输入为.mp3文件,并转换为其他文件格式(.wav,.txt和.xml),并将请求的响应发送给其他服务器。

在一段时间内,我的这个文件夹(Say / Somepath / MyInputFolder)现在有了我要删除的GB数据。

我尝试了rm -r *命令,但它说:

Argument list too long

我还尝试rm -r *.mp3rm -r *.txt分别删除这些文件,但它也会出现同样的错误。

我也试过这个SO question并阅读此link

我尝试了上述SO问题的解决方案并将错误视为警告。

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.

我怎样才能实现这个目标?

5 个答案:

答案 0 :(得分:3)

正如您对链接的答案的评论中所述,您需要将-maxdepth直接放在路径之后。像这样:

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

答案 1 :(得分:3)

ls | tail -10000 | xargs rm -rf

多次执行。

答案 2 :(得分:2)

我也有同样的例外。我有超过1个文件。 这是您需要重复运行的命令

$ rm -f ls|tail -10000

执行了10次。

答案 3 :(得分:2)

已经回答了这个问题,但我想补充一下这个问题。

find有自己的-delete选项,可以删除找到的文件。所以你可以这样做:

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

如果您有兴趣阅读有关此问题的更多信息,我建议this link

答案 4 :(得分:0)

你可以这样试试:

for m in * do; rm "$m"; done
相关问题