Results 1 to 6 of 6

Thread: Tar Command

  1. #1
    Join Date
    Nov 2008
    Location
    UK
    Beans
    75
    Distro
    Ubuntu 9.10 Karmic Koala

    Tar Command

    I would like to unpack all the .tgz archives in one directory in to a another specified sub directory, I have no bash experience, and so far I have worked out I need to use the tar command, and the -C parameter to specify the directory but I just get the a:
    Code:
    tar: -C=/home/chris/tartest/sub/: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now
    error using this command:
    Code:
    tar -xvvxf -C=/home/chris/tartest/sub/ *.tar.gz
    I am using tar.gz archives to test my command and the /home/chris/tartest/sub/ as the sub directory I want the extracted file in for this test, I am executing the command in the directory where the archives are. Could someone please tell me where I am going wrong, and if possible how to correct it?

    Thanks,

    Chris

  2. #2
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Lightbulb Re: Tar Command

    Fixed command:
    Code:
    for file in *.tar.gz; do echo "Extracting $file:"; tar xvzf "$file" -C "$HOME/tartest/sub/"; done

    What it means:
    PHP Code:
    for file in *.tar.gz;     # For each file ending in .tar.gz in the current directory
    do
      echo 
    "Extracting $file:";     # Display text: 'Extracting <file>'
      
    tar xvzf "$file-"$HOME/tartest/sub/";     # Untar the file
    done 

    Untar:
    x - Extract
    v - Verbose (display info)
    z - Gzip (that's what it's compressed with '.tar.gz')
    f - Use the file:
    C - Extract it to:
    Last edited by Penguin Guy; September 17th, 2009 at 06:28 PM.

  3. #3
    Join Date
    Nov 2008
    Location
    UK
    Beans
    75
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Tar Command

    I tried running the command twice but got these errors:
    Code:
    chris@chris-desktop:~/tartest$ tar -xvf * -C=~/tartest/sub/
    tar: sub: Cannot read: Is a directory
    tar: At beginning of tape, quitting now
    tar: Error is not recoverable: exiting now
    chris@chris-desktop:~/tartest$ tar -xvf *.tar.gz -C=~/tartest/sub/
    tar: testa2.tar.gz: Not found in archive
    tar: Error exit delayed from previous errors
    chris@chris-desktop:~/tartest$

  4. #4
    wojox is offline I Ubuntu, Therefore, I Am
    Join Date
    Apr 2009
    Beans
    8,628

    Re: Tar Command

    Code:
    sudo tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

  5. #5
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Lightbulb Re: Tar Command

    Quote Originally Posted by ChrisB111 View Post
    I tried running the command twice but got these errors:
    Code:
    chris@chris-desktop:~/tartest$ tar -xvf * -C=~/tartest/sub/
    tar: sub: Cannot read: Is a directory
    tar: At beginning of tape, quitting now
    tar: Error is not recoverable: exiting now
    chris@chris-desktop:~/tartest$ tar -xvf *.tar.gz -C=~/tartest/sub/
    tar: testa2.tar.gz: Not found in archive
    tar: Error exit delayed from previous errors
    chris@chris-desktop:~/tartest$
    It turns out that tar doesn't support wildcards, try this: for file in *.tar.gz; do echo "Extracting $file:"; tar xvzf "$file" -C "$HOME/tartest/sub/"; done
    Don't run the command that wojox posted, it won't work and is potentially dangerous.
    Last edited by Penguin Guy; September 17th, 2009 at 06:34 PM.

  6. #6
    Join Date
    Nov 2008
    Location
    UK
    Beans
    75
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Tar Command

    Thanks Penguin Guy, that new command works.

    Thanks again,

    Chris

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
  •