bash find 命令来查找文件并连接它们

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25083335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:00:26  来源:igfitidea点击:

find command to find files and concatenate them

linuxbashfindcat

提问by JSR

I am trying to find all the files of type *.gz and cat them to total.gz and I think I am quite close on this.

我正在尝试查找 *.gz 类型的所有文件并将它们分类为 total.gz,我认为我对此非常接近。

This is the command I am using to list all *.gz

这是我用来列出所有 *.gz 的命令

find /home/downloaded/. -maxdepth 3 -type d ( ! -name . ) -exec bash -c "ls -ltr '{}' " \

找到/home/downloaded/。-maxdepth 3 -type d ( ! -name . ) -exec bash -c "ls -ltr '{}' " \

How to modify it so that it will concatenate all of them and write to ~/total.gz

如何修改它以便将它们连接起来并写入 ~/total.gz

Update: directory structure under downloaded is as follows

更新:下载下的目录结构如下

/downloaded/wllogs/303/07252014/SysteOut.gz
/downloaded/wllogs/301/07252014/SystemOut_13.gz
/downloaded/wllogs/302/07252014/SystemOut_14.gz

回答by hek2mgl

Use catin -execand redirect output of find:

使用cat-exec和重定向输出find

find /home/downloaded/ -type f -name '*.gz' -exec cat {} \; > output

回答by Ana Santana

Use echoin -execand redirect the output:

使用echo-exec,并将输出重定向:

find /home/downloaded/ -name "*.gz" -exec echo {} \; > output