Rose Perrone
Rose Perrone

Reputation: 63606

tar exclude not working

What's wrong with this tar command?

$ tar --exclude='/tmp/test/exclude-me' -zcvf test.tar.gz test
  test/
  test/c.txt
  test/exclude-me/
  test/exclude-me/b.txt
  test/a.txt

As you can see, exclude-me is present when I untar the archive. I also tried --exclude=/tmp/test/exclude-me/*.

Upvotes: 6

Views: 4567

Answers (2)

Niels Keurentjes
Niels Keurentjes

Reputation: 41968

The exclude family of parameters apply to the internal relative names of the files in the tarball. The absolute path you specify will never exist within the tarball since it only has relative paths from the provided root.

Upvotes: 8

Florian
Florian

Reputation: 175

You have to omit the absolute parts of the path.

In your example you use the v-flag and the included files are listed.

The exclude pattern is matched against the entries of this list, not to the actual file paths. So you have to change your pattern to "test/exclude-me".

For some reason you also have to remove the trailing / for folders.

Upvotes: 1

Related Questions