0

I wish to extract /tmp/moht/104.tar to /tmp/moht/ directory

ls -ltr /tmp/moht/104.tar
-rwxrwxr-x   1 meadmin  meadmin  933498880 Jan  5 07:03 /tmp/moht/104.tar

I tried the below commands, but it does not extract to /tmp/moht/ directory.

It does not even print any output for extraction despite me using the -v option with tar command.

Below is everything I tried.

tar -xvf 104.tar --directory /tmp/moht/
tar -zvxf 104.tar --directory /tmp/moht/
tar -zvxf 104.tar -C /tmp/moht/
tar -jvxf 104.tar -C /tmp/moht/

If I cd /tmp/moht and fire this command tar -xf 104.tar then the files get extracted alright.

I'm using Sun Solaris Sparc. I do not wish to cd but give absolute path for both the tar file as well as the destination. I am not using GNU tar, but the tar that comes with Solaris.

This will be a part of a script so all the filenames and paths will be changed to variables; hence my requirement is very specific. Can you please suggest?

3

1 Answer 1

3

Solaris tar does not support the (presumably GNU tar) -C option during extraction to change directory before extraction. The Solaris tar -C option specifies which files or directories are to be archived or extracted. As a result, you need to cd to the directory where you want the extracted files to be put.

cd /tmp/moht && tar xf 104.tar

Note that Solaris tar does not use hyphenated functions like -xf ..., but rather bare letter options: xf .... Also note that 104.tar indicates an uncompressed tar file, so you do not need the j or z options; Solaris tar will automatically recognize compressed tar files for you.

3
  • Solaris tar has supported the - on the options since Solaris 8 or so at the latest, it's just documented in the Sun manner - a footnote buried somewhere that I can't find. And my experience with (older?) Solaris tar in automatically recognizing compressed archives has been poor... Jan 6, 2021 at 17:51
  • Thanks, Andrew! I didn't have an active Solaris system at-hand to prove or disprove the - support, so I based my claim on the documentation. At least they didn't say "SunOS"?!?
    – Jeff Schaller
    Jan 6, 2021 at 17:58
  • Solaris tar supports -C for creation only. The version from SchilliX added support for extraction as well. See: sourceforge.net/p/schillix-on/schillix-on/ci/default/tree/usr/… and BTW: Hyphens are tolerated for the first argument since the early 1980s and the -C option is from BSD-4.2 (1982).
    – schily
    Jan 12, 2021 at 15:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .