Linux下出现bash: /bin/xx: 参数列表过长

jupiter
2021-12-30 / 1 评论 / 969 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年12月30日,已超过820天没有更新,若内容或图片失效,请留言反馈。

1.现象描述

当目录下文件过多时,执行类似如下命令会出现bash: /bin/xx: 参数列表过长的错误

# 列出当前目的下的文件到txt
ls * >>../all.txt
# 删除符合某种条件的文件
rm *.txt
# 对于remove、cp、move等同样适用。

2.解决方案

使用xargs+find配合进行解决。举例如下:

# ls
find . -name "*"|xargs ls >>../all.txt
find . -type f -name "*"|xargs ls >>../all.txt
# rm
find . -name "*.log"|xargs rm -rf "*.log"
# 对于remove、cp、move等同样适用。

参考资料

  1. Linux那点事-xargs命令详解
  2. bash: /bin/ls: 参数列表过长
  3. bash: /bin/rm: 参数列表过长
0

评论 (1)

打卡
取消
  1. 头像
    Nanndy
    Windows 10 · Google Chrome

    ::aru:shy2::

    回复