[英]linux find -exec two commands and concatenate on same line
I have the following command: 我有以下命令:
find ~ -maxdepth 3 -type f -name description -exec stat -c "%n --RDD-- %z" {} \; -exec head -1 {} \;
This finds all the description files 3 folders deep ands outputs something like: 这将找到所有描述文件3个文件夹,并输出类似以下内容:
/home/user/public_html/.git/description --RDD-- 2014-12-17 17:02:09.347983909 +0000
Some description
/home/user/public_sub/.git/description --RDD-- 2014-12-17 17:02:09.347983909 +0000
Another description
I would like to concatenate the two execs and get something like: 我想串联两个执行程序,并得到类似的东西:
/home/user/public_html/.git/description --RDD-- 2014-12-17 17:02:09.347983909 +0000 --RDD-- Some description
/home/user/public_sub/.git/description --RDD-- 2014-12-17 17:02:09.347983909 +0000 --RDD-- Another description
I have been trying to get this done for the past day but cannot figure out a how to do it past this point. 在过去的一天里,我一直在努力做到这一点,但是到目前为止,我还无法弄清楚该如何做。
You can use --printf
in stat
to avoid printing newline like this: 您可以在stat
使用--printf
来避免像这样打印换行符:
find ~ -maxdepth 3 -type f -name description \
-exec stat --printf="%n --RDD-- %z --ROD-- " {} \; -exec head -1 {} \;
OR else you can use bash -c
and a command line in your command: 否则,您可以在命令中使用bash -c
和命令行:
find ~ -maxdepth 3 -type f -name description -exec bash -c \
'f="$1"; stat -c "%n --RDD-- %z --ROD-- $(head -1 "$f")" "$f"' - {} \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.