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?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Ashar
  • 491
  • Linking in https://unix.stackexchange.com/questions/23744/how-do-i-extract-with-tar-to-a-different-directory?rq=1 and https://unix.stackexchange.com/questions/187692/unable-to-extract-to-specific-directory?rq=1 – Jeff Schaller Jan 05 '21 at 14:00
  • @JeffSchaller tar xC /tmp/moht -f /tmp/moht/104.tar tar: C: unknown function modifier – Ashar Jan 05 '21 at 14:04
  • @JeffSchaller the links you shared seem to indicate cd is the only option … Do you agree ? – Ashar Jan 05 '21 at 14:06

1 Answers1

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • 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... – Andrew Henle Jan 06 '21 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 06 '21 at 17:58
  • Solaris tar supports -C for creation only. The version from SchilliX added support for extraction as well. See: https://sourceforge.net/p/schillix-on/schillix-on/ci/default/tree/usr/src/cmd/tar/ 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 '21 at 15:05