bash - find 命令中的 %p 和 %P 有什么区别

标签 bash find posix

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

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

我不清楚 %p 和 %P 之间的区别 我读了 find 的手册页,里面说的不多

 %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.

最佳答案

你试过吗?在您的示例中,%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

关于bash - find 命令中的 %p 和 %P 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15324932/

相关文章:

java - 如何在 freeBSD sh 的命令行中获取 java 进程的进程 ID

linux - 在 Makefile 中使用变量操作

javascript - 在多级对象中查找键

c - 父子进程间通信 - 保持管道打开可以吗?

regex - 如何使用 sed 打印匹配模式

mysql - Bash 和 MySQL 变量错误

c - 十六进制查找和替换

javascript - 在深层 javascript 数组中设置对象的属性值

c - POSIX 信号量/线程无法正常工作?

PHP - 杀死由 pcntl_fork 启动的子进程