Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line zip everything within a directory, but do not include any directory as the root

I can't find the answer to this for the life of me. Because I am packaging a zip in a specific way for a build process, I don't want to include a folder at all in the resulting zip at the root. For example, if I have this file path:

MyFolder/     A.png     B.txt     C.mp3 

And I use either the command:

zip -r -X "MyFolder.zip" MyFolder/* 

or

cd MyFolder; zip -r -X "../MyFolder.zip" * 

I end up with a zip file that has the root element of MyFolder. What I want is for when I unzip it is to dump all of it right into the directory, like this:

A.png B.txt C.mp3 

In other words, I don't want MyFolder or any other folder as the root. I read through the whole manual and have tried numerous options and a lot of Google searching, and zip seems to just really want to have a folder at the root.

Thanks!

like image 244
Eli Avatar asked Jul 03 '14 00:07

Eli


People also ask

How do I zip the contents of a directory?

Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location.

How do I create a zip folder without a new folder?

To select non-consecutive files or folders, hold down the Ctrl key as you select the individual files and/or folders. 2. Right-click on the file or folder (or group of files or folders), then point to Send to and select Compressed (zipped) folder. 3.

How do I zip all files and subdirectories 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.

Can zip files contain directories?

A Zip file is a data container containing one or more compressed files or directories. Compressed (zipped) files take up less disk space and can be transferred from one to another machine more quickly than uncompressed files.


1 Answers

It was Archive Utility's fault (a Mac OS X unzipper app). When I used the unzip command from the command line, it works great.

(cd MyFolder && zip -r -X "../MyFolder.zip" .) 
like image 52
Eli Avatar answered Sep 29 '22 09:09

Eli