且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

grep 返回“命令中指定的参数过多";

更新时间:2022-04-15 00:46:21

$ find ./ -name '20110101*' -print0 -type f | xargs -0 grep -l "search_pattern"

你可以使用 find 和 xargs.xargs 将为 find 找到的每个文件运行 grep.您可以使用 -P 并行运行多个 grep 并使用 -n 运行每个 grep 命令调用的多个文件.find 中的 print0 参数用空字符分隔每个文件名,以避免由文件名中的任何空格引起的混淆.如果您确定不会有任何空格,您可以删除 -print0 和 -0 参数.

you can use find and xargs. xargs will run grep for each file found by find. You can use -P to run multiple grep's parallely and -n for multiple files per grep command invocation. The print0 argument in find separates each filename with a null character to avoid confusion caused by any spaces in the file name. If you are sure there will not be any spaces you can remove -print0 and -0 args.