grep 返回“命令中指定的参数过多"; [英] grep returns "Too many argument specified on command"

查看:33
本文介绍了grep 返回“命令中指定的参数过多";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试列出我们在一个月内收到的所有文件

I am trying to list all files we received in one month

文件名模式为

20110101000000.txt

YYYYMMDDHHIISS.txt

整个目录有数百万个文件.一个月可以有最少 50000 个文件.子目录的想法仍然悬而未决.有没有办法列出大量文件名几乎相似的文件.

The entire directory is having millions of files. For one month there can be minimum 50000 files. Idea of sub directory is still pending. Is there any way to list huge number of files with file name almost similar.

grep -l 20110101*    

正在尝试此操作并返回错误.我尝试 php 花了很长时间,这就是我使用 shell 脚本的原因.我不明白为什么 shell 也没有给出结果请有任何建议!!

Am trying this and returning error. I try php it took a huge time , thats why i use shell script . I dont understand why shell also not giving a result Any suggestion please!!

推荐答案

$ 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.

这篇关于grep 返回“命令中指定的参数过多";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆