user5639117
user5639117

Reputation: 91

How do I compress a directory into an archive file on AIX where tar z isn't available?

I have a directory on a Unix server that I need to compress (recursively, including all files and directories) into one archive file, that I can FTP to my Windows box. I need to keep the directory/file structure.

All the help I can find says to use something like

tar -cvfz myarchive.tar.gz /path/dirtocompress

but I have no "z" option available - if I just type tar at the console, it gives me the usage details but there's no "z" option. If I try the above command without the "z", it works without compression - but the file gets truncated because I don't have enough space in my home directory to store the file uncompressed (the space available is set by a restriction that I have no control over, not by not having enough available disk space). If I run it with the "z", I just get the "tar usage" output to the console, indicating it doesn't understand it.

I've also tried redirecting the output to gzip:

tar cvf - /path/dirtocompress | gzip > myarchive.tar.gz

This compresses the directory into one archive file that fits inside my home folder, but doesn't preserve the path structure, so I end up with all the files and directories in the root of the archive.

I don't have the option to install anything on this Unix server, such as a different version of tar.

If this was Windows I could just zip up the directory and it would create one archive, containing all files and folders recursively and preserving the path structure. How do I achieve this on Unix using the above constraints?

Upvotes: 3

Views: 31784

Answers (1)

user5639117
user5639117

Reputation: 91

The correct command is

tar cvf - /path/dirtocompress | gzip > myarchive.tar.gz

This will compress the directory into one gzip file. As suggested by patrix, you can verify the paths are being stored correctly in this file using the following command which lists the contents of the file to stdout:

gunzip -c myarchive.tar.gz | tar -tvf -

The issue is that the Windows decompression software isn't interpreting/decompressing the archive correctly; WinZip 11.2 is ignoring the paths.

Using 7-zip for Windows, I was able to decompress the file and preserve the paths.

Upvotes: 6

Related Questions