Grep return“在命令上指定的参数太多”任何工作 [英] Grep return "Too many argument specified on command" Any work around

查看:131
本文介绍了Grep return“在命令上指定的参数太多”任何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

文件名格式为

  20110101000000.txt 

YYYYMMDDHHIISS.txt



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

  grep -l 20110101 * 

我尝试了这个并返回错误。
我尝试PHP花了很长的时间,这就是为什么我使用shell脚本。我不明白为什么shell还没有给出结果
任何建议请!!

解决方案

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

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


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

The filename pattern will be

20110101000000.txt

YYYYMMDDHHIISS.txt

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*    

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"

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 return“在命令上指定的参数太多”任何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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