1

I'm using this command to archive all PHP files:

find -name "*.php" | sudo tar -zcpvf my-archive.tar.gz -T -

It works great, except that the output is like this:

./file1.php
./file2.php
./file3.php

Instead of:

file1.php
file2.php
file3.php

How do I need to modify my command so that ./ is not included in my archive?

1

The most versatile tool to control the output of find is its own -printf feature. It has the %P sequence whose function is

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


find -name '*.php' -printf "%P\n"

is the same as

find ./ -name '*.php' -printf "%P\n"

so ./ is removed from the beginning of each line

  • Perfect answer, thank you. I mistakenly thought it had to do something with the tar command but it was actually the find command. – GTS Joe Mar 13 '16 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.