Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在unix中用特定单词对文件名为的所有文件进行分类_Unix_Command Line_Command_Cat - Fatal编程技术网

如何在unix中用特定单词对文件名为的所有文件进行分类

如何在unix中用特定单词对文件名为的所有文件进行分类,unix,command-line,command,cat,Unix,Command Line,Command,Cat,我在一个目录中有一堆文件,我想做的是: cat a-12-08.json b-12-08_others.json b-12-08-mian.json >> new.json 但是有太多的文件,有没有任何命令我可以用来猫所有文件名为“12-08”的文件 我找到了下面的解决方案。以下是答案: cat *12-08* >> new.json 答案如下: cat *12-08* >> new.json 使用通配符名称: cat *12-08* >>n

我在一个目录中有一堆文件,我想做的是:

cat a-12-08.json b-12-08_others.json b-12-08-mian.json >> new.json
但是有太多的文件,有没有任何命令我可以用来猫所有文件名为“12-08”的文件

我找到了下面的解决方案。

以下是答案:

cat *12-08* >> new.json
答案如下:

cat *12-08* >> new.json
使用通配符名称:

cat *12-08* >>new.json
只要没有太多文件超过命令行的最大长度(在我选中的Linux系统上为2MB),这将起作用。

使用通配符名称:

cat *12-08* >>new.json

只要没有太多文件超过命令行的最大长度(在我检查过的Linux系统上为2MB),这将起作用。

您可以使用
find
来执行要存档的操作:

find . -type f -name '*12-08*' -exec sh -c 'grep "one" {} && cat {} >> /tmp/output.txt' \;

通过这种方式,您可以
cat
包含您要查找的单词的文件您可以使用
find
执行您要存档的操作:

find . -type f -name '*12-08*' -exec sh -c 'grep "one" {} && cat {} >> /tmp/output.txt' \;
这样,您就可以
cat
包含您要查找的单词的文件