Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
linux find-exec两个命令并在同一行上连接_Linux_Shell_Centos - Fatal编程技术网

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"' - {} \;

在帮助中没有发现指纹。非常感谢。