6

I've tried multiple ways of creating a zip or a tar.gz on the mac using GUI or command lines, and I have tried decompressing on the Linux side and gotten various errors, from things like "File.XML" and "File.xml" both appearing in a directory, to all sorts of others about something being truncated, etc.

Without listing all my experiments on the command line on the Mac and Linux (using tcsh), what should 2 bullet proof commands be to:

1) make a zip file of a directory (with no __MACOSX folders)

2) unzip / untar (whatever) the Mac zip on Linux with no errors (and no __MACOSX folders)

IT staff on the Linux side said they "usually use .gz and use gzip and gunzip commands".

Thanks!

3 Answers 3

6

After much research and experimentation, I found this works every time:

1) Create a zipped tar file with this command on the Mac in Terminal:

tar -cvzf your_archive_name.tar.gz your_folder_name/

2) When you FTP the file from one server to another, make sure you do so with binary mode turned on

3) Unzip and untar in two steps in your shell on the Linux box (in this case, tcsh):

gunzip your_archive_name.tar.gz

tar -xvf your_archive_name.tar

3
  • Just do tar xvfz ... to extract. The z has tar call gzip for you, and you avoid creating a large, intermediate .tar file.
    – Mark Adler
    Dec 17, 2014 at 4:14
  • That will not prevent resource fork/extended attribute information from being put in the tar file, which shows up as ._* files. Nor will it prevent .DS_Store files from being archived. See my answer for how to avoid those.
    – Mark Adler
    Dec 17, 2014 at 4:19
  • It's also not a "zipped" file, at least by the traditional definition of "zipped." A .zip file is compressed with PKZIP or any of the utilities based on the Info-Zip package, including zip/unzip and WinZIP. gzip uses the same compression scheme, but it does not archive. Its use case is to serve as a filter for tar. The more recent additional "zips," including bzip2 (another compressor-only) and 7Zip (archive+compress), only serve to confuse things.
    – Joe Sewell
    Mar 10, 2015 at 11:58
2

On my Mac and in ssh bash I use the following simple commands:

Create Zip File (-czf)
tar -czf NAME.tgz FOLDER
Extract Zip File (-xzf)
tar -xzf NAME.tgz

Best, Mike

1

First off, the File.XML and File.xml cannot both appear in an HFS+ file system. It is possible, but very unusual, for someone to format a case-sensitive HFSX file system that would permit that. Can you really create two such files and see them listed separately?

You can use the -X option with zip to prevent resource forks and extended attributes from being saved. You can also throw in a -x .DS_Store to get rid of those files as well.

For tar, precede it with COPYFILE_DISABLE=true or setenv COPYFILE_DISABLE true, depending on your shell. You can also throw in an --exclude=.DS_Store.

Your "IT Staff" gave you a pretty useless answer, since gzip can only compress one file. gzip has to be used in combination with tar to archive a directory.

5
  • On my mac, I had gotten mixed case XML and xml files. For the script, I normalized them by simply renaming them all to lower case. In one of the zip attempts, I forget which one, the archive unzipped on the Linux box with both in there! I do have a working solution after much trial and error. I'll post it below. Dec 17, 2014 at 4:03
  • Linux does allow file names that differ only in case. To get that you would have archive two files in different directories on the Mac whose names differ only in case (since they can't coexist in the same directory), and the unarchive them into the same directory on Linux.
    – Mark Adler
    Dec 17, 2014 at 4:21
  • Mark, my current statement is "tar -cvzf archive.tar.gz my_folder/". How do I integrate the -x option? I tried and it said I can't have both c and x. Dec 24, 2014 at 17:07
  • You need to read the answer more carefully. -x is for zip. For tar you use --exclude.
    – Mark Adler
    Dec 24, 2014 at 17:11
  • Thanks, I missed that! Dec 27, 2014 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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