Results 1 to 6 of 6

Thread: create a tar file from a file list

  1. #1
    Join Date
    Nov 2007
    Location
    VA
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    create a tar file from a file list

    To create a tar archive of the dot files in my /home directory. I did
    Code:
    find ./ -name ".*" > dotfiles
    and then
    Code:
    tar -czvf <filename>.tar.gz --files-from ./dotfiles
    . I also tried
    Code:
    tar -czvf <filename>.tar.gz -T ./dotfiles
    So I tried several other things, none of which worked. I can find nothing on the web. I can get it done using the exclude option, but I'd still like to know if a tar file can be created from a file containing a list of files, and if so how.

    TIA

  2. #2
    Join Date
    Sep 2008
    Location
    your profile
    Beans
    653
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: create a tar file from a file list

    find -name '.*' finds enverything on account of the working directory being .

    Try

    Code:
    find -regex '\./\.[^/]*' -exec tar -rf newarchive.tar {} \;
    The regular expression says the following:

    Match files in the current directory (./) whose names begin with a . (. has a special meaning in regular expressions so it is escaped with a backslash) followed by any combination of characters NOT containing a / - thus, for example, you will get ./.local but not ./.local/share and all the other stuff inside it you don't want to append after it has already been added by appending .local.

    Note that this will not find hidden files inside non-hidden directories in your home directory, but I doubt you want those - I could get them but I think you don't want them if they exist.

    tar -rf just appends its argument to the end of a tar archive, allowing you to use find -regex -exec as your tool (since find -regex -exec has to work one command at a time).

    Read man grep for an explanation of regular expressions.
    Intel core i5-2400, 8GB RAM, NVIDIA GeForce GTX 550 Ti

  3. #3
    Join Date
    Nov 2007
    Location
    VA
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: create a tar file from a file list

    Thanks for the reply Zorgoth. I'll try your suggestion. I can see that my post was a bit unclear. I got the files I wanted into "dotfiles" using the find command. What I'm wondering is why I can't use "dotfiles" to create the tar.

  4. #4
    Join Date
    Sep 2008
    Location
    your profile
    Beans
    653
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: create a tar file from a file list

    Well, the first thing to note is that find '.*' is definitely not going to work, as I already said; it will find every single file in your home directory. You can try using my find -regex with > instead of -exec to test your dotfile when you have the right directory names.
    Intel core i5-2400, 8GB RAM, NVIDIA GeForce GTX 550 Ti

  5. #5
    Join Date
    Sep 2008
    Location
    your profile
    Beans
    653
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: create a tar file from a file list

    I have confirmed that creating dotfile as follows:

    find -regex '\./\.[^/]*' > ./dotfile

    and executing tar as follows:

    tar -cvnf archive.tar -T dotfile

    works just fine.

    The problem was probably that your

    find -name '.*'

    created crazy contradictions and weirdnesses.
    Intel core i5-2400, 8GB RAM, NVIDIA GeForce GTX 550 Ti

  6. #6
    Join Date
    Nov 2007
    Location
    VA
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: create a tar file from a file list

    You're right. I overlooked that the first entry in my dotfile was "./". I confirmed as well that your code works. Thanks again. You saved me a few of the hairs that I have left.

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
  •