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
Bash Unix复杂目录问题_Bash_Unix_Grep_Cat - Fatal编程技术网

Bash Unix复杂目录问题

Bash Unix复杂目录问题,bash,unix,grep,cat,Bash,Unix,Grep,Cat,我有一个名为Server的主文件夹,它有15(1…f)worker文件夹,在每个worker(1…f)文件夹中都有slave(1…f)子文件夹。在每个slave子文件夹中,大约有2000个文件 图解视图: /服务器 /1 ----> 0 1 2 3 4 5 6 7 8 9 a b c d e f /2 ----> 0 1 2 3 4 5 6 7 8 9 a b c d e f /3 ----> 0 1 2

我有一个名为
Server
的主文件夹,它有
15(1…f)
worker
文件夹,在每个
worker(1…f)
文件夹中都有
slave(1…f)
子文件夹。在每个
slave
子文件夹中,大约有2000个文件

图解视图:

/服务器

/1  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/2  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/3  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/4  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/5  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/6  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/7  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/8  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/9  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/a  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/b  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/c  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/d  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/e  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
/f  ----> 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
我需要
grep
一次将所有文件夹中的文件中名为“router”的特定字符串写入一个文件/
cat
文件夹中的所有文件并写入一个文件

我试过猫

#cat **/* > new_file.txt 
我得到了
bash:/bin/cat:参数列表太长的响应

我试过grep

#grep -e "router" **/* > new_file.txt
再一次,我得到了
bash:/bin/cat:Argument列表太长的响应


我知道这是一个复杂的目录问题。这不能更改,因为数据是从联机资源获取的。有人能帮我找到从文件夹中带有字符串“router”
的行,并将其重定向到一个新文件吗

使用
find
而不是
grep

find . -name "*" -type f -exec grep "router" {} \; > new_file.txt
它将在(
)目录中找到每个文件(
“*”
),然后为每个文件找到
grep“router”

问候


克劳迪奥

>
代替
来避免overwriting@ritesht93f您可以在循环中插入命令,如
for
while
yes,否则您不需要使用
>
谢谢@Claudio。使用“查找”很好。不管怎样,很酷!