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?
tar cvf
should create a tar file with directories. If you runzcat archive.tar.gz | tar tvf -
, does the output contain the paths? – nohillsidetar: Unexpected end-of-file
if I run your command, because it's truncated when creating without compression (because of the home folder space restriction). – user5639117ls -l
). If you get this error, the tar file itself may be corrupt. – nohillsidegunzip -c myarchive.tar.gz | tar -tvf -
to get the list to work, but yes, here it displays the paths. So, I guess the process is correct, but WinZip is not doing the decompression properly. Thanks for the help diagnosing this. – user5639117