Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Linux compatible zip archive of a directory on a Mac

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!

like image 659
dbonneville Avatar asked Dec 15 '14 19:12

dbonneville


People also ask

How do you create an archive file on a Mac?

Compress a file or folder: Control-click it or tap it using two fingers, then choose Compress from the shortcut menu. If you compress a single item, the compressed file has the name of the original item with the . zip extension. If you compress multiple items at once, the compressed file is called Archive.

How do I convert a directory to a zip file in Linux?

The easiest way to zip a folder on Linux is to use the “zip” command with the “-r” option and specify the file of your archive as well as the folders to be added to your zip file. You can also specify multiple folders if you want to have multiple directories compressed in your zip file.

Is Mac compatible with zip files?

Both Mac and Windows come with an inbuilt compression feature that enables you to zip files. The zip files put all your files in one place. The file archive will put all the compressed files in one place.


2 Answers

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

like image 103
dbonneville Avatar answered Sep 20 '22 17:09

dbonneville


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

like image 34
Michael G Avatar answered Sep 19 '22 17:09

Michael G