argument list too long错误解决

简介:

xargs是给命令传递参数的一个过滤器,也是组合多个命令的一个工具。它把一个数据流分割为一些足够小的块,以方便过滤器和命令进行处理。通常情况下,xargs从管道或者stdin中读取数据,但是它也能够从文件的输出中读取数据。xargs的默认命令是echo,这意味着通过管道传递给xargs的输入将会包含换行和空白,不过通过xargs的处理,换行和空白将被空格取代。

 

1. 当你尝试用rm 删除太多的文件,你可能得到一个错误信息:/bin/rm Argument list too long. 用xargs 去避免这个问题

find ~ -name ‘*.log’ -print0 | xargs -0 rm -f

 2. 获得/etc/ 下所有*.c 结尾的文件列表,有几种不同的方法能得到相同的结果,下面的例子仅仅是示范怎么实用xargs ,在这个例子中实用 xargs将find 命令的输出传递给ls -l

# find /etc -name "*.c" | xargs ls –l

3. 假如你有一个文件包含了很多你希望下载的URL, 你能够使用xargs 下载所有链接

# cat list.txt | xargs wget –c

 4. 查找所有的jpg 文件,并且压缩它

# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz

5. 原因是:一个文件夹下文件太多,使用rm删除就会出现/bin/rm: Argument list too long错误,当然使用别的命令也是一样的错误,像ls,chmod等。

解决方法:
1:
ls | xargs -n 10 rm -fr ls
就解决了,这句解释为:输出所有的文件名(用空格分割) xargs就是将ls的输出,每10个为一组(以空格为分隔符),作为rm -rf的参数也就是说将所有文件名10个为一组,由rm -rf删除,这样就不会超过命令行的长度了.

2:find . -maxdepth 1 -name "*.sh" -type f -exec rm -f {} \;

用 find  命令在当前目录查找,然后用exec命令执行










本文转自 南非波波 51CTO博客,原文链接:http://blog.51cto.com/nanfeibobo/1641664,如需转载请自行联系原作者
目录
相关文章
|
5月前
|
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
56 0
|
8月前
|
Java 开发工具 git
解决Error running XXXApplicationCommand line is too long.报错
解决Error running XXXApplicationCommand line is too long.报错
|
9月前
|
Linux
删除大量文件和目录时报错:Argument list too long
这个目录下的文件数量我惊呆了。40W+ 的文件目录数量,直接报错了。
61 1
|
5月前
|
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
43 0
|
6月前
|
Java Spring
Command line is too long. Shorten command line for Application or also for Spring Boot default confi
Command line is too long. Shorten command line for Application or also for Spring Boot default confi
14 1
|
6月前
|
Java
【异常】SpringBoot报错Command line is too long.Shorten command line for Application or also for Applicatio
【异常】SpringBoot报错Command line is too long.Shorten command line for Application or also for Applicatio
30 0
|
7月前
|
机器学习/深度学习
CF71A Way Too Long Words(string简单模拟)
CF71A Way Too Long Words(string简单模拟)
36 0
|
7月前
|
Java
解决Command line is too long. Shorten command line for ServiceStarter or also for Application报错
解决Command line is too long. Shorten command line for ServiceStarter or also for Application报错
53 0
|
12月前
A. Way Too Long Words(无思维纯模拟)
A. Way Too Long Words(无思维纯模拟)
34 0
|
Java
IDEA 启动服务报错:Command line is too long. Shorten the command line via JAR manifest or via a classpath file and rerun 解决方案
IDEA 启动服务报错:Command line is too long. Shorten the command line via JAR manifest or via a classpath file and rerun 解决方案
1430 1