unable to execute /bin/mv: Argument list too long
四种解决”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用户/系统管理员, 有些时候你会遇到以下错误提示:
[user@localhost foo]$ mv * ../foo2
bash: /bin/mv: Argument list too long
“Argument list too long”参数列表过长错误经常发生在用户在一行简单命令中提供了过多的参数而导致,经常在ls *, cp *, rm * 等中出现。
根据问题的原因以下提供了四种方法,可以根据自己的情况酌情选用
方法1 : 将文件群手动划分为比较小的组合
e.g 1:
[user@localhost foo]$ mv [a-l]* ../foo2
[user@localhost foo]$ mv [m-z]* ../foo2
这是最基本的方法,只是简单的使参数数量符合要求,这种方法应用范围有限,只适用于文件列表中的名字分布比较均匀,另外这也是个初级用户可以考虑的解决方案,不过需要很多重复命令和对文件名分布的观察与猜测。
方法2 : 使用find命令
e.g 2:
[user@localhost foo]$ find $foo -type f -name '*' -exec mv {}$foo2/. \;
方法2通过find命令,将文件清单输出到mv命令,使其一次处理一个,这样就完全避免了过量参数的存在,另外通过不同的参数,可以指定除了名称以外的时间戳,权限,以及inode等匹配模式。
方法2的缺点在于比较耗费时间。
方法3 : 创建shell函数
e.g 3.1:
function huge_mv ()
{whileread line1; do
mv foo/$line1 ../foo2
done
}
ls -1 foo/ | huge_mv
写一个shell函数并不涉及到某种程度的复杂性, 这种方法比方法1和方法2相比更加灵活。
下面我们来扩展一下例3.1 :
e.g 3.2:
function huge_mv ()
{whileread line1; do
md5sum foo/$line1 >> ~/md5sums
ls -l foo/$line1 >> ~/backup_list
mv foo/$line1 ../foo2
done
}
ls -1 foo/ | huge_mv
相比例3.1,例3.2生成了文件的md校验散列文件和名字备份,符合给自己留条后路的哲学。
另外可以根据自己的需要无限制的扩展功能。
方法4 : 终极解决方案,重新编译内核
首先使用这个方案之前要谨慎,因为涉及到修改内核源代码,在生产环境中还是要斟酌一下并做好测试。
另外,这个方法是从根本上解决的,一劳永逸的
这也是开放源码的好处之一
首先在内核源码中找到 include/linux/binfmts.h文件 ,搜索到以下字段:
/*
* MAX_ARG_PAGES defines the number of pages allocated for arguments
* and envelope for the new program. 32 should suffice, this gives
* a maximum env+arg of 128kB w/4KB pages!
*/
#define MAX_ARG_PAGES 32
修改 MAX_ARG_PAGES数值为 64 或者更高即可完善的解决参数受限问题。
然后 重新编译并启用新内核即可。
unable to execute /bin/mv: Argument list too long的更多相关文章
- Ubuntu下修改权限时出现"unable to execute /bin/chmod: Argument list too long"
Ubuntu14.04下修改权限时出现"unable to execute /bin/chmod: Argument list too long" ,大概意思是卧槽,你这参数也 ...
- CentOS中输入yum报错:sudo: unable to execute /bin/yum: No such file or directory
今天尝试更新了下虚拟机CentOS中的python版本后. 运行“yum”命令,就报错:“sudo: unable to execute /bin/yum: No such file or direc ...
- E0264 Unable to execute '"/usr/bin/codesign" ...'
E0264 Unable to execute '"/usr/bin/codesign" ...' http://docwiki.embarcadero.com/RADStudio ...
- 安装vmtools Error: Unable to execute "/usr/bin/vmware-uninstall-tools.pl.
Error: Unable to execute "/usr/bin/vmware-uninstall-tools.pl. 安装vmware tools错误解决办法 很多朋友都在用vmwar ...
- Unable to execute dex: GC overhead limit exceeded
Android打包时下面的错误: Unable to execute dex: GC overhead limit exceeded GC overhead limit exceeded 解决的方法: ...
- /bin/rm: Argument list too long解決方法
rm.cp.mv是unix下面常用到的檔案處理指令,當我們需要刪除大量的log檔案,如果檔案數太多就會出現此訊息[/bin/rm: Argument list too long]解決方式如下: 例如要 ...
- 【转】Unable to execute dex: Java heap space 解决方案(如何为eclipse.int 添加内存)
原文网址:http://blog.csdn.net/zengyangtech/article/details/7003379 欢迎转载,转载请注明 http://blog.csdn.net/zengy ...
- 【Android】Tips for Android developer: “Conversion to Dalvik format failed: Unable to execute dex: null”
Androiddeveloper, I have met a strange problem when I want use a third party jar, it remained me tha ...
- 模拟器 Unable to execute simctl install Error 117
ios 模拟器 Unable to execute '"/usr/bin/xcrun" simctl install "/Users/tt/PAServer/scrat ...
随机推荐
- Thymeleaf(一)---引入js/css文件
th:href="@{/static/css/style.css}" th:src="@{/static/js/thymeleaf.js}" index.htm ...
- System.Reflection.ReflectionTypeLoadException
引用了一个第三方dll, 此dll经过混淆,但是未签名. 然后,主程序无法反射了, 取消主程序的签名后正常反射.
- linux内核链表的实现
.\linux-2.6.22.6_vscode\include\linux\list.h #ifndef _LINUX_LIST_H#define _LINUX_LIST_H #ifdef __KER ...
- HihoCoder第十周:后序遍历
也就在大二学数据结构的时候知道了树的前序遍历.后序遍历.中序遍历.之后就忘了,在之后就是大四研究生老师考我,我当时还不知道,真够丢人的.自此之后,知道了如何通过其中两个得到第三个,但是也没有编程实现过 ...
- 【ABP】从零开始学习ABP_入门介绍
本文介绍自己入坑ABP的过程,一些ABP的相关文章.QQ群,以及ABP Zero示例项目的运行. 背景 作为一个半路出家学习编程的新人,之前工作中也断断续续写过一些代码,但底层核心一直没机会学习,所以 ...
- dede开启会员功能
登陆后台,找到菜单里面的系统基本参数设置>会员设置>开启会员功能,选择“是”,保存即可
- linux下操作oracle
ps -ef|grep ora #查看oracle状态 lsnrctl status #查看监听的状态 lsnrctl start |stop |reload #启动|停止|重启 监听 登录oracl ...
- OIer常见问题与错误总结
作为一名OIer,无论是一名刚入门的蒟蒻,还是叱诧风云的神犇,相信都会难免去犯一些错误(废话不犯错误岂不是都满分了(ノへ ̄.).在这里总结了一些OIer常见易犯的错误,与大家共勉. 1.正常错误 可能 ...
- POJ 3096:Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6258 Accepted: 407 ...
- Atomic系列类整体介绍
本博客系列是学习并发编程过程中的记录总结.由于文章比较多,写的时间也比较散,所以我整理了个目录贴(传送门),方便查阅. 并发编程系列博客传送门 本文是转载文章,原文请见此博客,文章主要对java.ut ...