Tarring up JUST the dotfiles
Want to tar up only the dotfiles (hidden files/dirs) in your home directory?
or (thanks to mosk0bit)
The astute will notice the “J” and the “xz”. J tells tar to compress with xz compression (formerly lzma) which is significantly better than gzip especially with the type of files you will expect to have in your hidden directories. If J is not available in your version of tar, use z instead.
Neither of these solutions are absolutely perfect, but they are at least simple. For the perfect score, see slava_dp’s comment:
http://blog.tpa.me.uk/2009/09/29/tarring-up-just-the-dotfiles/#comment-478
Perhaps, a simpler way is:
tar cvJf filename.tar.xz .??*
@mosk0bit
Thanks. Didn’t know about that one.
I’ve been looking for a firm solution to the dotfile selection problem for a while.
ls .??* fails on a file named .a
ls .[^.]* fails on a file named ..file
ls -A | egrep ‘^\.’ will fail if a file name contains a linebreak or other funky characters (yes it can).
The only proper solution (as per #bash@freenode guys) is this:
set +o histexpand #disables special “!” interpretation
shopt -s extglob #enables extended bash globs
echo .!(|.) #gives you all your dotfiles, excluding “.” and “..”, and without mangling anything.