Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2012
    Posts
    1

    Unanswered: Programming newbie -help

    Hi I am trying to learn shell script and i ran into an issue.

    I am trying to read a file with few directories and tar them up.
    I used a while loop but i end up overwriting tar file with only the last directory in the file being tared .

    cat test.txt |
    (
    while read line
    do
    tar -czPf backup.tar.gz $line
    done
    )

    If test.txt has test1, backup1, goo1

    I end up having only goo1 in the tar

    how do i get all 3 directories in the tar?

    Thanks for your help in advance

  2. #2
    Join Date
    Jan 2004
    Location
    Issy les Moulineaux, France
    Posts
    24
    Hi,
    tar -c create a new archive.
    You should use tar -A to append to an existing archive, but it can't be done to add to a compressed archive.

    Instead, you can use the following:

    Code:
    tar -czPf backup.tar.gz  $(cat test.txt)
    Regards,
    Eric

Posting Permissions

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