Home > Linux, Miscellaneous, Slackware > Tarring up JUST the dotfiles

Tarring up JUST the dotfiles

September 29th, 2009 Leave a comment Go to comments

Want to tar up only the dotfiles (hidden files/dirs) in your home directory?

ls -A | egrep '^\.' | tar -cvJf filename.tar.xz -T -

or (thanks to mosk0bit)

tar -cvJf filename.tar.xz .??*

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

Be Sociable, Share!
  1. mosk0bit
    November 13th, 2009 at 21:28 | #1

    Perhaps, a simpler way is:

    tar cvJf filename.tar.xz .??*

  2. November 14th, 2009 at 10:17 | #2

    @mosk0bit
    Thanks. Didn’t know about that one.

  3. slava_dp
    November 19th, 2009 at 15:51 | #3

    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.

  4. dude
    September 25th, 2011 at 01:30 | #4

    find ./ -maxdepth 1 -mindepth 1 -name “.*” | tar cf file.tar -T -

  5. November 12th, 2011 at 21:40 | #5

    Thanks! :-)

  1. No trackbacks yet.

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).