AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
  • 1.  tar command

    Posted Thu October 11, 2007 12:36 PM

    Originally posted by: SystemAdmin


    Hi all,

    Can you tell me how I can put these two lines in one command?

    1) cd /var/tmp
    2)) tar xvf /tmp/lll.tar
    something like "tar xvf source.tar destinatio_directory"

    I have tried this but it seems to be wrong.
    tar xvf /tmp/lll.tar /var/tmp

    thanks


  • 2.  Re: tar command

    Posted Thu October 11, 2007 12:44 PM

    Originally posted by: SystemAdmin


    How was the tar file created? Was it created using a full path? or were you in the directory and created with

    tar -cvf newtar.tar .

    This puts everything relative and you can unpack where you want, but the first option will only unpack in the location where it was first created.


  • 3.  Re: tar command

    Posted Thu October 11, 2007 01:07 PM

    Originally posted by: orphy


    If the tarball was created with full path, he can still get GNU tar and extract with -C <dest_dir>. That will place the files in <dest_dir> for him.
    Orphy


  • 4.  Re: tar command

    Posted Thu October 11, 2007 04:23 PM

    Originally posted by: SystemAdmin


    Why this damn thing has to be so hard..

    Ok ..here is what I did

    /home/myID/temp:/> tar -cvf newtar.tar .

    so my newtar.tar gets generated under "/home/myID/temp"
    now I want to untar this under "/home/myID/logs", as you said I tried -C like this

    /home/myID/temp:/> tar -xvf newtar.tar -C /home/myID/logs but I am getting the following errors.

    File -C not present in the archive.
    File /home/myID/logs not present in the archive.


  • 5.  Re: tar command

    Posted Thu October 11, 2007 04:46 PM

    Originally posted by: SystemAdmin


    Unfortunately, it looks like the -C flag is not intended to be used when un-archiving files:
    [i]-C Directory Causes the tar command to perform a chdir subroutine to the
    directory specified by the Directory variable. Using the -C flag allows multiple
    directories not related by a close common parent to be [b][u]archived[/u][/b], using short
    relative path names. For example, to archive files from the /usr/include and
    /etc directories, you might use the following command:

    tar c -C /usr/include File1 File2 -C /etc File3 File4

    The -CDirectory flag must appear after all other flags and can appear in the
    list of file names given.[/i]

    I would suggest wrapping the command with other commands to change to the directory before executing tar and then to change back afterwards, e.g.
    code#x=$(pwd); cd /dest/dir; tar -xvf /path/tarfile; cd $x[/code]
    I cannot think of any other way to do this than to manually execute separate commands.


  • 6.  Re: tar command

    Posted Fri October 12, 2007 09:43 AM

    Originally posted by: orphy


    I said that you can use the GNU tar to do it but it appears that it's the AIX tar that you are using.

    Since you created the tarball with relative path, you can simply do

    cd /home/myID/logs && tar xvpf /home/myID/temp/newtar.tar

    I'm not aware of a way to do this with one single command unless you use the GNU tar which you can get from the URL below if you are interested.

    http://www-03.ibm.com/systems/p/os/aix/linux/index.html
    http://www.bullfreeware.com/listaix51.html

    An alternative way to do it would be

    cp -Rph /home/myID/temp/. /home/myID/logs

    but then I don't know the whole story what you are trying to do. This might not work well if you are doing scripting or trying to do some type of massive deployments to a bunch of boxes, etc so hope this helps!
    Orphy


  • 7.  Re: tar command

    Posted Fri October 12, 2007 11:38 AM

    Originally posted by: hwyguy


    Ok, there's 2 ways I can think of resolving this.

    1.) Change how you create the tar file.

    From the /home/myID directory, run (without quotes):

    "tar -cvf newtar.tar -C ./temp ."

    That will tar the contents of /home/myID/temp but will not have the temp directory in the pathname.

    From there, you would move the newtar.tar file into /home/myID/logs and run a straight "tar -xvf newtar.tar" and you're golden.

    2.) If you can't remake the tar but you need to change the destination

    [

    Use the pax command to do a search and replace on the directory. So if you created a tar with absolute paths to /home/myID/temp you'd run this to change the temp to /home/myID/logs

    "pax -rf newtar.tar -s/temp/logs/p"

    The -s flag will do a searh and replace just like vi.

    Any of these solutions should help you with your issue.


  • 8.  Re: tar command

    Posted Thu October 11, 2007 03:53 PM

    Originally posted by: SystemAdmin


    Could it be that you are missing a "-" before the options to tar?
    For example:
    codetar -xvf /tmp/lll.tar /var/tmp
    ^ notice the - in the above command[/code]