Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to zip files without the top level folder but keep the sub folders

Tags:

Suppose I have a folder named abc, it has several sub folders recursively, I want to zip everything under abc, when I use the following command

zip -r abc.zip abc/*

I get abc.zip, but it contains the top level folder abc, and everything is under abc, like abc/xxx, abc/yyy etc, How can I remove the top level folder abc? I want to put everything directly in abc.zip.

Note:

  1. I can only zip from outside of the folder, so navigate to folder abc, and zip * is not work for me
  2. I need to run this command in a single line, I can separated multiple commands by ;
  3. option -j also does not work, since it remove the sub folders, I want to keep them there.
like image 250
zdd Avatar asked Dec 05 '12 08:12

zdd


People also ask

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".

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.


2 Answers

cd abc
zip -r ../abc.zip *

Though I will say in most cases keeping it abc makes for easier management.

like image 177
Gilbert Avatar answered Sep 18 '22 18:09

Gilbert


7z a -tzip abc.zip -w abc/.

321

like image 43
reisio Avatar answered Sep 17 '22 18:09

reisio