Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Archiving only dot directories (+sub-diectories) and files in home directory

  1. #1
    Join Date
    Feb 2008
    Location
    Denmark
    Beans
    332
    Distro
    Ubuntu 12.04 Precise Pangolin

    Archiving only dot directories (+sub-diectories) and files in home directory

    How do I backup dot directories, dot sub-directories and dot files residing in /home/user/ to an archive? Normally I would run something like the following, but that doesn't seem to work on hidden folders and files:
    Code:
    tar -czvf pictures.tar.gz ~/Pictures
    I am using Xubuntu 11.04
    Last edited by casbahdk; February 28th, 2012 at 11:56 PM.
    Peppermint OS Four - Dell Vostro 3350, Peppermint OS Three - Acer Aspire One 725 & Asus Eee PC 1015BX, Ubuntu 12.04 - home built AMD desktop,
    Military justice is to justice what military music is to music. - Groucho Marx

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,037
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    Hi casbahdk.

    Yes, if you use .* as an argument for tar, it will include . (that means all).

    Try this:
    Code:
    find  -maxdepth 1 -type d -regex './\..*' -print0 | xargs -0 tar -czvf myhidden.tar.bz
    Explanation:
    - Use 'find' to get the list of the .* directories.
    - the option -maxdepth 1 means just the directories directly located at home.
    - option -type d looks for directory names only.
    - regex is used to skip ./ and ../
    - the option -print0 is just in case there are tricky characters in the directory names (like spaces).
    - xargs take the list created by 'find' and it passes it to the command tar.

    Hope it helps, and tell us how it goes.
    Regards.

  3. #3
    Join Date
    Feb 2008
    Beans
    5,636

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    If you only want to tar dot files, you could use something like this:
    Code:
    tar -cvzf archive.tar.gz ./.[^.]*

  4. #4
    Join Date
    Feb 2008
    Location
    Denmark
    Beans
    332
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    Thanks for the quick reply. Well this bit partially works:
    Code:
    $ find  -maxdepth 1 -type d -regex './\..*' > test.txt
    I can create a test file with a list of the hidden directories, but it doesn't include the hidden files at the top level, like .bashrc and .pinerc The entire command, when used together gives me the following:
    Code:
    $ find  -maxdepth 1 -type d -regex './\..*' -print0 | xargs -0 tar -czvf hidden_bits.tar.gz
    tar: Cowardly refusing to create an empty archive
    Try `tar --help' or `tar --usage' for more information.
    Peppermint OS Four - Dell Vostro 3350, Peppermint OS Three - Acer Aspire One 725 & Asus Eee PC 1015BX, Ubuntu 12.04 - home built AMD desktop,
    Military justice is to justice what military music is to music. - Groucho Marx

  5. #5
    Join Date
    Feb 2008
    Location
    Denmark
    Beans
    332
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    Quote Originally Posted by TeoBigusGeekus View Post
    If you only want to tar dot files, you could use something like this:
    Code:
    tar -cvzf archive.tar.gz ./.[^.]*
    I get the following errors:
    Code:
    $ tar -cvzf hidden_files.tar.gz ./.[^.]*
    tar: ./.[^.]*: Cannot stat: No such file or directory
    tar: Exiting with failure status due to previous errors
    Could this be due to my working from the destination directory?
    Last edited by casbahdk; February 29th, 2012 at 12:50 AM.
    Peppermint OS Four - Dell Vostro 3350, Peppermint OS Three - Acer Aspire One 725 & Asus Eee PC 1015BX, Ubuntu 12.04 - home built AMD desktop,
    Military justice is to justice what military music is to music. - Groucho Marx

  6. #6
    Join Date
    Feb 2008
    Beans
    5,636

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    Are you sure sure there are hidden files and/or folders where you run the command?

  7. #7
    Join Date
    Feb 2008
    Location
    Denmark
    Beans
    332
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    Quote Originally Posted by TeoBigusGeekus View Post
    Are you sure sure there are hidden files and/or folders where you run the command?
    Kalispera, I am running this from the destination folder. Should I try running it from home like this:
    Code:
    $ tar -cvzf archive.tar.gz ./.[^.]* /media/cbb/newest_backup_files/home_folders_files
    ?
    Peppermint OS Four - Dell Vostro 3350, Peppermint OS Three - Acer Aspire One 725 & Asus Eee PC 1015BX, Ubuntu 12.04 - home built AMD desktop,
    Military justice is to justice what military music is to music. - Groucho Marx

  8. #8
    Join Date
    Feb 2008
    Beans
    5,636

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    cd to the folder where the dot files are and run the command.
    It works for me...
    Attached Images Attached Images

  9. #9
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,037
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    Quote Originally Posted by casbahdk View Post
    it doesn't include the hidden files at the top level
    Yes, the option '-type d' do exactly that (my mistake from reading just the beginning from your post title).

    Just remove it and 'find' will add the files to the list.

    Quote Originally Posted by casbahdk View Post
    Code:
    $ find  -maxdepth 1 -type d -regex './\..*' -print0 | xargs -0 tar -czvf hidden_bits.tar.gz
    tar: Cowardly refusing to create an empty archive
    Try `tar --help' or `tar --usage' for more information.
    In this instance it looks like the second time you are running the command in a place with no hidden directories.

    Hope it helps.
    Regards.

  10. #10
    Join Date
    Feb 2008
    Location
    Denmark
    Beans
    332
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Archiving only dot directories (+sub-diectories) and files in home directory

    Quote Originally Posted by TeoBigusGeekus View Post
    cd to the folder where the dot files are and run the command.
    It works for me...
    Yes, it worked here as well. I had to restart when I discovered I hadn't emptied the trash. No point in backing up things I don't want Efharistó.
    Peppermint OS Four - Dell Vostro 3350, Peppermint OS Three - Acer Aspire One 725 & Asus Eee PC 1015BX, Ubuntu 12.04 - home built AMD desktop,
    Military justice is to justice what military music is to music. - Groucho Marx

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •