繁体   English   中英

linux find -exec两个命令并连接在同一行

[英]linux find -exec two commands and concatenate on same line

我有以下命令:

find ~ -maxdepth 3 -type f -name description -exec stat -c "%n --RDD-- %z" {} \; -exec head -1 {} \;

这将找到所有描述文件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

我想串联两个执行程序,并得到类似的东西:

/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

在过去的一天里,我一直在努力做到这一点,但是到目前为止,我还无法弄清楚该如何做。

您可以在stat使用--printf来避免像这样打印换行符:

find ~ -maxdepth 3 -type f -name description \
      -exec stat --printf="%n --RDD-- %z --ROD-- " {} \; -exec head -1 {} \;

否则,您可以在命令中使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM