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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With