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
find command to find files and concatenate them
提问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 cat
in -exec
and redirect output of find
:
使用cat
中-exec
和重定向输出find
:
find /home/downloaded/ -type f -name '*.gz' -exec cat {} \; > output
回答by Ana Santana
Use echo
in -exec
and redirect the output:
使用echo
中-exec
,并将输出重定向:
find /home/downloaded/ -name "*.gz" -exec echo {} \; > output