tar -cvzf archive.tar.gz .* 

Template * does not work

How to archive only files / directories with names starting with a dot?

  • Quote: ".*" - PinkTux
  • @PinkTux, doesn’t work - user203925
  • Maybe ... \.* ? - don Rumata pm
  • @donRumata, the same thing ... - user203925
  • Strangely, I started to archive the hamster even without quotes, strictly according to the mask :) - PinkTux

1 answer 1

like this:

 $ find -maxdepth 1 -regex './\..*' | tar -cvzf archive.tar.gz -T - 

if you are not satisfied with the prefix ./ before the names of files / directories, then a little longer:

 $ find -maxdepth 1 -regex './\..*' -printf '%P\n' | tar -cvzf archive.tar.gz -T - 

possible without -regex :

 $ find -maxdepth 1 -mindepth 1 -name .\* | tar -cvzf archive.tar.gz -T - $ find -maxdepth 1 -mindepth 1 -name .\* -printf '%P\n' | tar -cvzf archive.tar.gz -T - 

or you can find without it:

 $ tar -cvzf archive.tar.gz .??* 

but files / directories with the name consisting of two characters will not fall under the mask. type .1 . then so

 $ tar -cvzf archive.tar.gz .[^.]* 
  • no find is good at all) - user203925
  • @ssfn, note that under the mask .??* files / directories with the name consisting of two characters will not fall. - aleksandr barakin