Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tar exclude not working

Tags:

linux

bash

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/*.

like image 921
Rose Perrone Avatar asked Sep 03 '14 22:09

Rose Perrone


2 Answers

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.

like image 138
Niels Keurentjes Avatar answered Oct 10 '22 08:10

Niels Keurentjes


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.

like image 21
Florian Avatar answered Oct 10 '22 08:10

Florian