{"title": "\u89e3\u51b3Bash Argument list too long\u7684\u95ee\u9898", "update_time": "2015-01-26 23:41:53", "tags": "bash", "pid": "322", "icon": "linux.png"}
Bash可以对命令行中的`*`进行展开,展开为具体的文件或目录列表。 但当目录下的文件或目录过多的时, Bash展开*的时候会报错`Argument list too long`。下面是我总结的2个解决方法 ### 使用find命令 ``` #比如删除目录下的大量.tmp文件 find . -name "*.tmp" -exec rm -f {} \+ ``` ### 使用find + xargs (针对需要重定向的场景,一般用find 的exec足矣) ``` #比如将大量的.txt文件 重定向到一个文件中 find . -name "*.txt" | xargs cat > mynew.txt ```