Uses of % in bash

Hello, I am trying to interpret one command and I am not able to get the get what does % symbolizes here..

find /path/to/diretory -type f -print0 | xargs -0 -i% cp -v % /path/to/new/directory

Open in new window

Please let me know how cp is taking % as the argument supplied via find using pipe. I know it works but how it works I am failed to get it. Does bash shell playing any role here or it is magic of xargs command? Thanks!
Who is Participating?
The -i argument to xargs is the "replace string". Instances of this string in the initial argument are replaced by input From std-in.

So cp % ... Is replaced by each file from the find command.

Not how I would have done it. I'd have used -exec argument to find.
By default, the -i flag to xargs uses {} as a placeholder for arguments.  It is the equivalent of -I{}

So you can specify any character you like as the placeholder, eg: %

The find statement is better written as:
find /path/to/diretory -type f  | xargs -i cp -v /path/to/new/directory

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.