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}...
3
  • 2
    Why do you think it's a normal UNIX command?
    – schaiba
    Apr 28, 2017 at 12:30
  • I think you need to spend some time reading on the differences between Unixes Linux and GNU tools.
    – coteyr
    Apr 28, 2017 at 18:16
  • 5
    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, 2017 at 19:48

4 Answers 4

29

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

tar cvf - directory1|gzip -c >file.tar.gz
5
  • 2
    This has the potential advantage that some of the processing can happen in parallel.
    – psmears
    Apr 28, 2017 at 15:47
  • Is the f - needed, or does Solaris tar output to stdout by default?
    – Mark
    Apr 28, 2017 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. Apr 29, 2017 at 12:29
  • @Romeo: Thanks for the answer, I found it useful. Can you clarify why "-" is needed between cvf and directory name? Additionally, I tried your command on several OSs - Solaris 10, 11.4, Linux (RHEL, CentOS, Oracle, etc.) and works consistently. I also reviewed the respective tar man pages - why does the above work in Linux without "-" before the cvf ? I would expect Linux to require something like "tar -cvf ...." Thanks again for the answer.
    – rc1
    Feb 29, 2020 at 2:55
  • @rc1, the dash in tar mean you set the output file to be STDOUT. There are two styles of parameters, BSD and SYSV. And Linux tar work with both of them (with and w/o dash before cvf) Feb 29, 2020 at 7:19
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.

2
  • 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. Apr 29, 2017 at 12:25
  • 1
    @IlmariKaronen neither can I. I just thought of this first.
    – terdon
    Apr 29, 2017 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)

2
  • 1
    This doesn’t add a whole bunch beyond a previous answer
    – Jeff Schaller
    Feb 12, 2018 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. Nov 26, 2019 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.