LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-15-2007, 12:44 PM   #1
PlymWS
Member
 
Registered: Aug 2006
Posts: 51

Rep: Reputation: 16
Zip multiple directories to seperate archives


I have about 200 directories that I need to zip up into seperate archives, with the zip file being named the same as the directory it contains. I will be doing this through an SSH client, not a GUI.

For example directory 1 to 1.zip, dir. 2 to 2.zip etc. etc.

I don't want to have to type in manually all the directory names. Can I get zip to do this from the command line ?
 
Old 06-15-2007, 02:13 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
For a directory (and contents), don't you have to use tar first?---i.e. I am not sure you can zip a directory.

Tar will combine things into an archive AND do the compression--all in one commands. It will accept multiple source names.

Depending on where all the directories are, it could be quite simple--eg if all in one place:

(Pseudo-Code)
for i in `ls -l|grep '^d'` do
awk something to get the filename
tar czvf $filename $filename_xxx (where xxx is some tag to add to each filename)
done
 
Old 06-15-2007, 08:51 PM   #3
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
Make a directory (say /zipdir) to hold the zip files. Assuming you are in a directory that contains the directories you want to zip, and nothing else, then

for i in * ; do zip -r /zipdir/$i.zip $i ; done

should do it.
 
Old 06-16-2007, 04:40 AM   #4
PlymWS
Member
 
Registered: Aug 2006
Posts: 51

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by maroonbaboon
Make a directory (say /zipdir) to hold the zip files. Assuming you are in a directory that contains the directories you want to zip, and nothing else, then

for i in * ; do zip -r /zipdir/$i.zip $i ; done

should do it.
That worked perfectly. Thanks very much !
 
  


Reply

Tags
zip



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Handling RAR and 7-Zip archives in Linux LXer Syndicated Linux News 0 02-02-2007 07:21 AM
untarring archives that span multiple tapes? BrianK Linux - General 2 11-29-2005 09:41 PM
Directories on seperate partitions. ToothlessRebel Linux - Newbie 5 11-27-2004 09:34 AM
Seperate program directories in Linux NGraphiX Linux - General 7 09-17-2002 07:08 PM
FYI: Antivirus scanner DoS with zip archives unSpawn Linux - Security 0 08-14-2001 07:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration