Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create zip file and ignore directory structure

Tags:

linux

zip

People also ask

How do I exclude a folder from a ZIP file?

Exclude Multiple Files/Directories from Zip Archive You can define -x multiple times in a single zip command to exclude multiple files and directories from zip archive.

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.

Can you zip folders with subfolders?

On the General tab in Properties, click the button Advanced. In the next window, tick the check box Compress contents to save disk space under the Compress or Encrypt attributes section. There, you need to choose "Apply changes to this folder only" or "Apply changes to this folder, subfolders and files".


You can use -j.

-j
--junk-paths
          Store just the name of a saved file (junk the path), and do  not
          store  directory names. By default, zip will store the full path
          (relative to the current directory).

Using -j won't work along with the -r option.
So the work-around for it can be this:

cd path/to/parent/dir/;
zip -r complete/path/to/name.zip ./* ;
cd -;

Or in-line version

cd path/to/parent/dir/ && zip -r complete/path/to/name.zip ./* && cd -

you can direct the output to /dev/null if you don't want the cd - output to appear on screen


Use the -j option:

   -j     Store  just the name of a saved file (junk the path), and do not
          store directory names. By default, zip will store the full  path
          (relative to the current path).

Somewhat related - I was looking for a solution to do the same for directories. Unfortunately the -j option does not work for this :(

Here is a good solution on how to get it done: https://superuser.com/questions/119649/avoid-unwanted-path-in-zip-file