11

I am logged into Sun Solaris OS. I want to create and extract a compressed tar file. I tried this normal UNIX command:

tar -cvzf file.tar.gz directory1

It is failing to execute in Sun OS with following error

bash-3.2$ tar -cvzf file.tar.tz directory1
tar: z: unknown function modifier
Usage: tar {c|r|t|u|x}[BDeEFhilmnopPqTvw@[0-7]][bfk][X...] [blocksize] [tarfile] [size] [exclude-file...] {file | -I include-file | -C directory file}...
  • 2
    Why do you think it's a normal UNIX command? – schaiba Apr 28 '17 at 12:30
  • I think you need to spend some time reading on the differences between Unixes Linux and GNU tools. – coteyr Apr 28 '17 at 18:16
  • 4
    When they added that z flag to GNU tar, we lost our greatest example for teaching people how to think logically and construct a pipeline... – user41515 Apr 28 '17 at 19:48
26

To avoid creation of temporary intermediate file you can use this command

tar cvf - directory1|gzip -c >file.tar.gz
  • 2
    This has the potential advantage that some of the processing can happen in parallel. – psmears Apr 28 '17 at 15:47
  • Is the f - needed, or does Solaris tar output to stdout by default? – Mark Apr 28 '17 at 21:29
  • 2
    @Mark: According to the man page, "If f is omitted, tar will use the device indicated by the TAPE environment variable, if set; otherwise, it will use the default values defined in /etc/default/tar." So, no, it doesn't look like you can safely assume that f - isn't needed. – Ilmari Karonen Apr 29 '17 at 12:29
10

Looks like Solaris's tar doesn't know how to compress. So just do it manually:

tar -cvf file.tar directory1 && gzip file.tar

That's all the -z switch of GNU tar does, anyway. The command above will produce file.tar.gz.

  • This will work (as long as you have enough spare disk space to store the intermediate uncompressed file.tar archive), but it's needlessly slow and wasteful of disk space. I can't think of any situation where this would be preferable to Romeo Ninov's answer. – Ilmari Karonen Apr 29 '17 at 12:25
  • 1
    @IlmariKaronen neither can I. I just thought of this first. – terdon Apr 29 '17 at 12:37
2

Check if you haveSUNWgtar installed. This the the GNU version of tar and provides /usr/sfw/bin/gtar which will allow the use of the GNU options to tar.

-1

Please try below command

tar -cvf file.tar directory1 && gzip file.tar

(to zip the file on solaris)

gunzip file.tar.gz

(to unzip)

  • 1
    This doesn’t add a whole bunch beyond a previous answer – Jeff Schaller Feb 12 '18 at 20:50
  • It also just dumps the whole tar file (including all the binary in the headers) onto the terminal, instead of unarchiving the files. You would probably need to reset the terminal afterwards. – Paul_Pedant Nov 26 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.