linux find-exec两个命令并在同一行上连接
我有以下命令:linux find-exec两个命令并在同一行上连接,linux,shell,centos,Linux,Shell,Centos,我有以下命令: 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/publ
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
我想将两位执行官连接起来,得到如下结果:
/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"' - {} \;
在帮助中没有发现指纹。非常感谢。