【Linux命令】bash: /usr/bin/rm: Argument list too long
问题:bash: /usr/bin/rm: Argument list too long
原因:
参考:bash: /usr/bin/rm: Argument list too long - Solution (haydenjames.io)
Over time, the storage used on Linux systems you manage will grow. As a result, you will, at some point, try to delete, move, search, or otherwise manipulate thousands of files using commands such as rm
, cp
, ls
, mv
, and so on, which are all subject to this limitation. As such, you will eventually come across the “Argument list too long” error detailed below.
“Argument list too long” indicates when a user feeds too many arguments into a single command which hits the ARG_MAX
limit. The ARG_MAX
defines the maximum length of arguments to the exec function.
An argument, also called a command-line argument, can be defined as the input given to a command, to help control that command line process. Arguments are entered into the terminal or console after typing the command. Multiple arguments can be used together; they will be processed in the order they typed, left to right.
This limit for the length of a command is imposed by the operating system. You can check the limit for maximum arguments on your Linux system using this command:
getconf ARG_MAX
Which will return something like this:
hydn@centos:~$ getconf ARG_MAX
2097152
The “argument list too long” error means that you’ve exceeded the maximum command-line length allowed for arguments in a command.
解决方案:
参考:mv argument list too long错误_bisal(Chen Liu)的博客-CSDN博客
解决方案1:
Argument list too long本质是需要处理的长度超过系统的长度,因此无法执行相关命令。
既然参数过长,直观的思路,就是减少参数,分而治之的方式,来解决这问题。
此时就可以借助find找出符合条件的文件,然后拆开执行,mv的指令,有两种执行方式,一个是xargs,另一个是-exec。
xargs指令是给其他指令传递参数的一个过滤器,也是组合多个命令的一个工具,-i会将xargs的内容赋值给{}。
-exec参数后面是指执行其后面的指令,-exec以;为结尾,由于各个系统中分号的意义不同,因此用\进行转义,即\;,{}会被find指令的结果替换。
我们采用-exec,拼接指令如下,find首先找出符合条件的文件,然后{}会替换find的结果,依次执行mv,
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2019-04-19 【测试123】性能测试之压力测试