How to make tar exclude hidden directories

When I want to exclude directories when taring, I usually use the syntax as follows:

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

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

+18
hidden tar
source share
1 answer

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 browsing the current directory, as 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 
+36
source share

All Articles