[[email?protected] orbit-oracle]# ls |wc -l 1185524 [[email?protected] orbit-oracle]# rm -f * -bash: /bin/rm: Argument list too long [[email?protected] orbit-oracle]# pwd /tmp/orbit-oracle [[email?protected] orbit-oracle]# ls |wc -l 1185524 [[email?protected] orbit-oracle]# ls |xargs rm -f * -bash: /usr/bin/xargs: Argument list too long [[email?protected] orbit-oracle]# ls |wc -l 1185524 [[email?protected] orbit-oracle]# find . -name "*" | xargs rm -rf ‘*‘? rm: cannot remove directory: `.‘ ^C [[email?protected] orbit-oracle]# ls |wc -l 1035696 [[email?protected] orbit-oracle]# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/xvda1 1310720 1161190 149530 89% / tmpfs 1007257 738 1006519 1% /dev/shm /dev/xvdd1 19660800 45404 19615396 1% /u01 /dev/xvdc1 9830400 12 9830388 1% /logs /dev/xvdb1 3276800 10559 3266241 1% /app [[email?protected] orbit-oracle]# find . -name "*" | xargs rm -rf ‘*‘? rm: cannot remove directory: `.‘ ^C [[email?protected] orbit-oracle]# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/xvda1 1310720 751189 559531 58% / tmpfs 1007257 738 1006519 1% /dev/shm /dev/xvdd1 19660800 45404 19615396 1% /u01 /dev/xvdc1 9830400 12 9830388 1% /logs /dev/xvdb1 3276800 10560 3266240 1% /app [[email?protected] orbit-oracle]# ls |wc -l 625698 [[email?protected] orbit-oracle]#
===============================
http://hi.baidu.com/cpuramdisk/item/5aa49ce00c0757aecf2d4f24
四种解决”Argument list too long”参数列表过长的办法
在linux中删除大量文件时,直接用rm会出现:-bash: /bin/rm: 参数列表过长,的错误。
这时可以用find命令来结合使用。
例: 1、rm * -rf 改为: find . -name "*" | xargs rm -rf ‘*‘ 就行了。
2、rm test* -rf 改为: find . -name "test*" | xargs rm -rf "test*"
?
mv时报参数列表过长,
for i in *.m;do mv $i ${i%.m};done
于是求助于google,探索过程就省略了,直接说解决方法吧:
ls dir1 | xargs -t -I {} mv {} dir2/{}
这里的一对大括号是原文给的例子里用的,后来看了参数的用法,其实那对大括号是可以用任意字符串替换的,比如:
ls dir1 | xargs -t -I asdf mv asdf dir2/asdf
效果和大括号那一版是完全一样的,就是看起来有点儿不严肃。
需要说明的是,上面xargs的第二个参数,是大写的i,读作”爱“的那个字母,不是小写的L。至于参数的含义嘛,我忘了。
?
?
?
?Linux下 报错“命令参数列表过长”,在用mv命令一次移动3万多个文件时失败了,原始命令类似这样:”mv $(ls dir1) dir2“。错误提示的中心思想是:”你这参数也太TM多了吧“。
按照LZ想法大概可以这么做:find /dir1/ -maxdepth 1 | xargs -i mv {} /dir2/ 如果参数过长,使用tar比较简单 tar -C /dir1/ -cf - . | tar -xf - -C /dir2/
?
于是求助于google,探索过程就省略了,直接说解决方法吧:
ls dir1 | xargs -t -I {} mv {} dir2/{}
这里的一对大括号是原文给的例子里用的,后来看了参数的用法,其实那对大括号是可以用任意字符串替换的,比如:
ls dir1 | xargs -t -I asdf mv asdf dir2/asdf
效果和大括号那一版是完全一样的,就是看起来有点儿不严肃。
需要说明的是,上面xargs的第二个参数,是大写的i,读作”爱“的那个字母,不是小写的L。至于参数的含义嘛,我忘了。
?
?
另外4种方法
作为一个linux用户/系统管理员,有些时候你会遇到以下错误提示:
?
[[email?protected] foo]$ mv * ../foo2
bash: /bin/mv: Argument list too long
“Argument list too long”参数列表过长错误经常发生在用户在一行简单命令中提供了过多的参数而导致,经常在ls *,cp *,rm * 等中出现。 根据问题的原因以下提供了四种方法,可以根据自己的情况酌情选用
方法1 : 将文件群手动划分为比较小的组合 e.g 1:
?
[[email?protected] foo]$ mv [a-l]* ../foo2
[[email?protected] foo]$ mv [m-z]* ../foo2
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|