find命令中%p和%P之间的区别是什么

时间:2013-03-10 17:01:53

标签: bash find posix

我在一个例子中遇到了如下使用find命令(它将目录结构复制到某处)

 find olddir -name script.sh -printf "%p\0" -printf "newdir/%P\0" | xargs -0L2 cp -n

我不清楚%p和%P之间的差异 我阅读了发现的手册,其中没有多说

 %p     File's name.
 %P     File's name with the name of the command line argument under which it was found removed.

%p和%P之间有什么区别

我对它的含义感到困惑

 %P     File's name with the name of the command line argument under which it was found removed.

1 个答案:

答案 0 :(得分:6)

你有没有尝试过?在您的示例中,%p打印包含olddir部分的文件,而%P不打印它。几乎就是文档所说的内容。简单的例子:

$ ls -R
.:
dir/

./dir:
file
$ find dir -name file -printf '%p\n'
dir/file
$ find dir -name file -printf '%P\n'
file