how to make tar exclude hidden directories
Asked Answered
J

1

41

When I want to exclude directories when taring, I typically use syntax like this:

tar -zcf /backup/backup.tar.gz --exclude="/home/someuser/.ssh" /home/someuser

How can I modify this to exclude all hidden directories, for example, in addition to .ssh/, I also want to exclude .vnc/, .wine/, etc.

Jurado answered 10/12, 2013 at 6:41 Comment(0)
L
75

You can use --exclude=".*"

$ tar -czvf test.tgz test/
test/
test/seen
test/.hidden
$ tar --exclude=".*" -czvf test.tgz test/
test/
test/seen

Be careful if you are taring the current directory, since it will also be excluded by this pattern matching.

$ cd test
$ tar --exclude=".*" -czvf test.tgz ./
$ tar -czvf test.tgz ./
./
./seen
./.hidden

Then you need to use --exclude='.[^/]*' as described elsewhere

$ tar --exclude='.[^/]*' -czvf test.tgz ./
./
./seen
Lifeanddeath answered 7/1, 2015 at 14:56 Comment(2)
Or just using --exclude=".+", and setting the path to be "."Viand
It seems --exculde=".*" is now positional and needs to go first and otherwise has no effect: tar --exclude=".*" -czvf test.tgz directory_to_be_archivedWachter

© 2022 - 2024 — McMap. All rights reserved.