Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between %p and %P in find command

Tags:

find

bash

posix

I came across use of find command in an example as follows (it copies the directory structure some where)

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

I am not clear with difference between %p and %P I read the man page of find which does not says much

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

what is the difference between %p and %P

I am confused with what it means by

 %P     File's name with the name of the command line argument under which it was found removed.
like image 855
Registered User Avatar asked Mar 10 '13 17:03

Registered User


People also ask

What is %P in Linux?

The %p , in your example, prints the file including the olddir part, and %P prints it without. Pretty much exactly what the documentation says. Simple example: $ ls -R .: dir/ ./dir: file $ find dir -name file -printf '%p\n' dir/file $ find dir -name file -printf '%P\n' file. Follow this answer to receive notifications.

What is print0 in find?

From man find : "-print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses). This allows file names that contain newlines or other types of white space to be correctly interpreted by programs that process the find output.

What is the difference between '>' and in Unix?

So, what we learned is, the “>” is the output redirection operator used for overwriting files that already exist in the directory. While, the “>>” is an output operator as well, but, it appends the data of an existing file. Often, both of these operators are used together to modify files in Linux.


1 Answers

Did you even try it? The %p, in your example, prints the file including the olddir part, and %P prints it without. Pretty much exactly what the documentation says. Simple example:

$ ls -R
.:
dir/

./dir:
file
$ find dir -name file -printf '%p\n'
dir/file
$ find dir -name file -printf '%P\n'
file
like image 172
Carl Norum Avatar answered Nov 07 '22 14:11

Carl Norum