Menu

untar to specified folder

Help
2009-05-29
2012-07-26
  • Nikolay Vertyanov

    windows. im try to use tar to untar files to specified folder:

    • tar.exe in dir_1
    • archive.tar in dir_2
    • need to extract file to dir_3

    the line i use:
    cd dir_2
    tar -xvf archive.tar -C dir_3
    error occur: error ... dir_2\dir_3: invalid argument

     
    • Nikolay Vertyanov

      I try but in --help no key or switch for definite destination folder to untar

       
      • Keith Marshall

        Keith Marshall - 2009-06-05

        If I understand you correctly, you have an archive file in some directory, (you called it "dir_2"), and you want to extract it into another directory, (which you called "dir_3")?

        Right. tar will, by default, extract into your current working directory, reinstating the hierarchy specified within the archive itself, relative to current directory as prefix. Thus, provided you didn't make the grave error of creating the archive with absolute path names:

        $ cd d:\path\to\dir_3
        $ tar xvf d:\path\to\dir_2\archive.tar

        should achieve what you want. (If you did create the archive, specifying absolute path names for the archived files, then I fear tar will always extract back to the same absolute paths; the moral is: never specify absolute path names for the files you add to a tar archive, always use a relative path).

        In an earlier post, you said you did:

        $ cd dir_2
        $ tar xvf archive.tar -C dir_3

        (exploiting the GNU tar -C extension feature), and it didn't work. I've never seen that fail, (but then, I use the MSYS implementation of GNU tar, rather than GnuWin32's). When you invoked that command, did your "dir_3" already exist as a subdirectory of "dir_2"? (Hint: tar will try to cd to the directory specified with -C; if it doesn't exist, that must fail; tar will not call mkdir for you).

         
    • GnuWin

      GnuWin - 2009-05-31

      Try to use bsdtar from the libarchive package.

       
MongoDB Logo MongoDB