rm、cp、mv 命令的参数列表太长错误 [英] Argument list too long error for rm, cp, mv commands

查看:40
本文介绍了rm、cp、mv 命令的参数列表太长错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UNIX 的一个目录下有数百个 PDF.PDF 文件的名称很长(大约 60 个字符).

I have several hundred PDFs under a directory in UNIX. The names of the PDFs are really long (approx. 60 chars).

当我尝试使用以下命令一起删除所有 PDF 时:

When I try to delete all PDFs together using the following command:

rm -f *.pdf

我收到以下错误:

/bin/rm: cannot execute [Argument list too long]

这个错误的解决方法是什么?mvcp 命令是否也会出现此错误?如果是,如何解决这些命令?

What is the solution to this error? Does this error occur for mv and cp commands as well? If yes, how to solve for these commands?

推荐答案

发生这种情况的原因是因为 bash 实际上将星号扩展到每个匹配的文件,从而产生一个很长的命令行.

The reason this occurs is because bash actually expands the asterisk to every matching file, producing a very long command line.

试试这个:

find . -name "*.pdf" -print0 | xargs -0 rm

警告:这是一个递归搜索,也会在子目录中查找(和删除)文件.仅当您确定不需要确认时,才将 -f 附加到 rm 命令.

Warning: this is a recursive search and will find (and delete) files in subdirectories as well. Tack on -f to the rm command only if you are sure you don't want confirmation.

您可以执行以下操作以使命令非递归:

You can do the following to make the command non-recursive:

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

另一种选择是使用 find 的 -delete 标志:

Another option is to use find's -delete flag:

find . -name "*.pdf" -delete

这篇关于rm、cp、mv 命令的参数列表太长错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆