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 Answer 1

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

1
  • 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
    Commented Mar 13, 2016 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .