Why does tar –exclude=“.*” create an empty archive

tarwildcards

Everything I read says that to exclude .svn and .htaccess and other hidden files when creating a tar archive, use the --exclude=".*" pattern.

When I try, I get an empty archive. When I leave out the --exclude long option everything gets archived.

Here's the full command I'm using:

tar -czvf ../_migrate/archive_2012-05-07.tgz --exclude=".*" ./*

I've also tried this variant, with no difference in results:

tar -czvf ../_migrate/archive_2012-05-07.tgz --exclude=".?*" ./*

Best Answer

You appear to be using GNU tar. Pattern matching in GNU tar works on the entire path, and does not stop at / characters. Since you are using ./ for your file list, that means every single file will match ./* which also matches .?*. I'd try something like --exclude='.[^/]*' perhaps.

Related Question