Linux输出“Argument list too long”的解决方法

简介: Linux输出“Argument list too long”的解决方法
  • 原因


在Linux下使用cpmvrm等命令时,经常会碰到“Argument list too long”错误,这个主要就是因为要cp、mv、rm的文件个数太多而导致的


  • 解决方法


Argument list too long这个问题的解决主要会用到两个命令,findxargs


  1. 删除aaa目录下以.zip结尾的文件


#方法一:
find /aaa/ -name "*.zip" | xargs -i rm {}
#方法二:
find /aaa/ -name "*.zip" -exec rm {} \;
  1. 复制aaa目录下以.zip结尾的文件到bbb目录
#方法一:
find /aaa/ -name  "*.zip" | xargs -i cp {} bbb
#方法二:
find /aaa/ -name  "*.zip" -exec cp {} bbb \;
  1. 移动aaa目录下以.zip结尾的文件到bbb目录


#方法一:
find /aaa/ -name  "*.zip" | xargs -i mv {} bbb
#方法二:
find /aaa/ -name  "*.zip" -exec mv {} bbb \;


解释


find aaa/ -name "*.zip"是指在aaa文件夹下查找以.zip结尾的文件。


xargs命令是给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。而-i参数会将xargs的内容赋值给{}。


-exec参数后面是指执行其后面的命令,-exec以;为结尾,由于各个系统中分号的意义不同,因此可以使用\进行转义,最终{}会被find命令的结果替换。

目录
相关文章
|
13天前
|
缓存 资源调度 DataWorks
DataWorks操作报错合集之DataWorks节点报错:OSError: [Errno 7] Argument list too long,该怎么处理
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
24 1
|
6天前
|
Linux 开发工具
linux中出现不在 sudoers 文件中。此事将被报告的解决方法
linux中出现不在 sudoers 文件中。此事将被报告的解决方法
12 0
|
23天前
四种解决”Arg list too long”参数列表过长的办法
这些方法都可以帮助你避免因参数列表过长而导致的错误。选择方法取决于具体情况和需求。
12 0
|
2月前
|
存储 算法 Linux
深入理解Linux内存管理brk 和 sbrk 与以及使用C++ list实现内存分配器
深入理解Linux内存管理brk 和 sbrk 与以及使用C++ list实现内存分配器
43 0
|
2月前
|
Ubuntu Linux Shell
Linux的中文乱码问题解决方法
Linux的中文乱码问题解决方法
|
6月前
|
Linux
LINUX 出现 -BASH-4.2# 问题的解决方法
LINUX 出现 -BASH-4.2# 问题的解决方法
186 0
|
6月前
|
Java
IDEA-解决Command line is too long. Shorten command line for SpringBootMainApplication or also for App
IDEA-解决Command line is too long. Shorten command line for SpringBootMainApplication or also for App
61 0
|
5月前
|
存储 安全 关系型数据库
Linux 目录结构_安装Xshell6和Xftp6教程加 Xshell无法启动:要继续使用此程序........,的解决方法
Linux 目录结构_安装Xshell6和Xftp6教程加 Xshell无法启动:要继续使用此程序........,的解决方法
42 0
|
5月前
|
安全 Linux 数据安全/隐私保护
Linux 忘记密码解决方法
Linux 忘记密码解决方法
53 0
|
6月前
|
Java
IDEA-解决Command line is too long. Shorten command line for SpringBootMainApplication or also for App
IDEA-解决Command line is too long. Shorten command line for SpringBootMainApplication or also for App
44 0