Argument list too long
2015-01-12 19:30
337 查看
文章出处:http://bencane.com/2011/07/13/argument-list-too-long/
If you've been an administrator for long enough eventually you will have run into an issue like so.
This can be a confusing issue at first if you've never run into it. The work around is pretty easy but first lets examine why you got this error.
The reason you see Argument list too long is because
when you run your command you are passing it too many arguments.
In this case (which is the most common time you will see this) we tried to rm all of the files in my directory which had 300,000 files in it; that was a few too many arguments for rm.
Even though you typed
When the * is interpreted by bash it becomes
Within the kernel there is a limit to how many arguments you can pass to a command. This is there to prevent misuse of the system by processes that may want to go a little too wild.
Now lets get to the quick workarounds.
This is a pretty easy option, Using a for loop every line of output from ls executes an rm.
This will take the output of ls and send it to the command xargs which will then breakup the output and run multiple rm commands with smaller sets of arguments.
You could also use find with the -exec flag but this can be a little dangerous, if you don't have the -maxdepth option find will also delete files in sub-directories. You may or may not want that.
With that said in certain situations Option 2 and 1 are also dangerous so be careful whenever you are performing file options like the above.
If you've been an administrator for long enough eventually you will have run into an issue like so.
[bcane@bcane toomany]$ rm * bash: /bin/rm: Argument list too long
This can be a confusing issue at first if you've never run into it. The work around is pretty easy but first lets examine why you got this error.
The reason you see Argument list too long is because
when you run your command you are passing it too many arguments.
In this case (which is the most common time you will see this) we tried to rm all of the files in my directory which had 300,000 files in it; that was a few too many arguments for rm.
Even though you typed
[bcane@bcane toomany]$ rm *
When the * is interpreted by bash it becomes
[bcane@bcane toomany]$ rm file1 file2 file3 file4 file5 [files6 - file299999] file300000
Within the kernel there is a limit to how many arguments you can pass to a command. This is there to prevent misuse of the system by processes that may want to go a little too wild.
Now lets get to the quick workarounds.
Option 1:
[bcane@bcane toomany]$ for x in `ls`; do rm $x; done
This is a pretty easy option, Using a for loop every line of output from ls executes an rm.
Option 2:
[bcane@bcane toomany]$ ls | xargs rm
This will take the output of ls and send it to the command xargs which will then breakup the output and run multiple rm commands with smaller sets of arguments.
Option 3:
[bcane@bcane toomany]$ find ./ -maxdepth 1 -type f -exec rm {} \;
You could also use find with the -exec flag but this can be a little dangerous, if you don't have the -maxdepth option find will also delete files in sub-directories. You may or may not want that.
With that said in certain situations Option 2 and 1 are also dangerous so be careful whenever you are performing file options like the above.
相关文章推荐
- "/bin/rm: argument list too long" 问题解决
- /bin/rm: Argument list too long的解决
- rm: argument list too long 的处理方法
- [已解决]Argument list too long如何处理?
- Argument list too long
- Argument list too long的解决方法
- Checking Dependencies Argument list too long: recursive header expansion failed at
- rm 时argument list too long
- sh: /bin/cp: Argument list too long
- "Argument list too long": Beyond Arguments and Limitations
- Argument list too long error for rm, cp, mv commands
- /bin/cat: Argument list too long
- -bash: /usr/bin/find: Argument list too long 报错以及linux timestamp为13位的处理方法
- 文件夹超过1万个压缩文件时,Argument list too long问题的解决
- sudo: unable to execute /bin/rm: Argument list too long
- linux sh: /bin/cp: Argument list too long 问题解决
- Argument list too long: recursive header expansion failed at
- bash /usr/bin/find argument list too long
- Argument list too long分析
- Argument list too long的解决方法