Skip to content
Advertisement

How to zip multiple folders separately in linux

Below mentioned folders contain some data. I need to zip all the folders separately.

ItembankUpdate-20210602-NGSS-1       
ItembankUpdate-20210602-NGSS-4  
ItembankUpdate-20210602-NGSS-7
ItembankUpdate-20210602-NGSS-3      
ItembankUpdate-20210602-NGSS-5  
ItembankUpdate-20210602-NGSS-8
ItembankUpdate-20210602-NGSS-2      
ItembankUpdate-20210602-NGSS-6

With this Command, I can zip only one folder

zip -r ItembankUpdate-20210602-NGSS-3.zip ItembankUpdate-20210602-NGSS-3

How can I zip all the folders separately at once?

Advertisement

Answer

First, make sure that you are in the directory where the above mentioned folders are. Then run:

find . -type d -maxdepth 1 -execdir zip '{}.zip' '{}' ;

This will find all the directories and zip them with the names:

ItembankUpdate-20210602-NGSS-1.zip
ItembankUpdate-20210602-NGSS-4.zip
ItembankUpdate-20210602-NGSS-7.zip
ItembankUpdate-20210602-NGSS-3.zip
ItembankUpdate-20210602-NGSS-5.zip
ItembankUpdate-20210602-NGSS-8.zip
ItembankUpdate-20210602-NGSS-2.zip
ItembankUpdate-20210602-NGSS-6.zip
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement