2

How do I compress a directory and its contents in ksh on AIX

for a file I do compress filename

Aravind
  • 1,599

3 Answers3

5

tar cjf <your-name-in-specific-path> <your-directory-path>

c: Create              
j: Use bzip2 for compression            
f: Save it to given file name

NOTE: If your tar version doesn't have these options you can follow the below instruction:

  1. tar cf <your-name-in-specific-path> <your-directory-path>
  2. gzip <your-name-in-specific-path>

NOTE: You can compress your file with other tools like bzip2, xz and so on.

3

A directory cannot be compressed, because a directory is not a plain file. It is a pointer to a container of a set of files.

You can tar a directory and its contents into a single file and compress that file. Or you can cd into the directory and compress each individual file.

hymie
  • 1,710
3

Tar in AIX by default does not support compression. You will need to incorporate with gzip command to have it tar and compress at the same time.

$ tar cvf test.tar test                      # pure tar only
$ tar cvf - test | gzip > test.tar.gz        # tar and compress together

To uncompress and untar as well :

$ gunzip -c test.tar.gz | tar tvf -           # list compress files
$ gunzip -c test.tar.gz | tar xvf -           # decompress files
Pacifist
  • 5,787