Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to zip particular folders in linux using shell

Tags:

linux

shell

sh

zip

Let say we have a directory structure like:

A
|---B
|   |---C
|   |   |--f1.txt
|   |
|   |---D
|   |   |--f2.txt
|
|---E
|   |---f3.txt
|   |
|
|---F
|   |---f4.txt

Now how to zip a file BE.zip excluding F directory, i.e when I unzip BE.zip the result should be:

|---B
|   |---C
|   |   |--f1.txt
|   |
|   |---D
|   |   |--f2.txt
|   
|---E
|   |---f3.txt
like image 522
Bhuvan Avatar asked Nov 27 '13 06:11

Bhuvan


People also ask

How do I zip a folder in shell script?

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.

How do I zip a specific folder?

Locate the file or folder that you want to zip. 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 zip a specific file in Linux?

Syntax : $zip –m filename.zip file.txt 4. -r Option: To zip a directory recursively, use the -r option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory.

How do I zip an entire directory in Linux?

You can compress directories and the corresponding sub-directories by using the -r flag. The -r flag will tell zip to traverse the entire directory recursively. To suppress the output from the compression process, use the -q for quiet mode. The command creates a zip archive of the specified files with no output.


1 Answers

ok got it..

zip -r BE.zip B/ E/
like image 150
Bhuvan Avatar answered Nov 08 '22 18:11

Bhuvan