Zip multiple files recursively via UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Zip multiple files recursively via UNIX
# 1  
Old 02-05-2012
Zip multiple files recursively via UNIX

Hello,
After searching, I didn't find any answer to execute my task. Her what I want to achieve on my MAC :
  1. Create a ZIP file (not tar.gz or other) from a file
  2. I want the ZIP created to have the name of the original file
  3. I want to do this on multiple files (314 exactly)
So at the end the result should be :
filename-1.jpg => filename-1.zip
filename-2.jpg => filename-2.zip
... => ...
filename-n.jpg => filename-n.zip


All my originals files are in the same folder, so the idea is to parse this folder and zip all the files one by one.


Thanks for your help.
David
# 2  
Old 02-05-2012
Code:
ksh
for i in *.jpg
do
gzip -c $i >${i%.*}.zip
done

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 02-06-2012
Thanks !!!

Just a big thank you for this quick and perfect answer !
Worked like a charm. FYI, I was calculating, that if I had to do it by "hand" (right click -> compress file), if you calculate 4-5 sec by file, it would have taken me 4 hours to do it...

So I owe you 4 hours ;-)

Have a nice life.

---------- Post updated 06-02-12 at 03:28 PM ---------- Previous update was 05-02-12 at 07:02 PM ----------

Work like a charm but I just realize that when you unzip one of the files zipped with this script, you get a file without extension...

You must replace ${i%.*} by ${i}

thanks again

David

Last edited by anou; 02-06-2012 at 10:30 AM.. Reason: Found the solution
# 4  
Old 02-06-2012
It was your requirement to name your file

filename-1.zip

instead of the default

filename-1.txt.gz

so you can now :

Code:
ksh
for i in *.zip
do
gunzip -c $i >${i%.*}.jpg
done

If you don't want have to worry about all that, just don't pay attention to the extension and stay with the default one.

So the most simple solution for zip/unzip will be something like :

Code:
for i in *.jpg
do
gzip $i
done

Code:
for i in *.gz
do
gunzip $i
done

or even:
Code:
gzip *.jgp
gunzip *.gz


Last edited by ctsgnb; 02-06-2012 at 10:55 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

Search/Replace in multiple files recursively

Hi there, I am using AIX and trying to search and replace a string with another string in multiple files in different directories. I wanted to search replace in steps so I don't change all of the instance anywhere in the server at once, minimizing impact. STEP 1: -------- I first searched... (5 Replies)
Discussion started by: zaino22
5 Replies

4. Shell Programming and Scripting

Create multiple zip files each containing 50 xml files.

Hi, Is there a direct command or need to write a shell script for following requirement? Everyday a folder is populated with approx 25k to 30k xml files. I need to create multiple zip files in the same folder each containing 50 xml files. The last zip file may or may not contain 50 xml files.... (6 Replies)
Discussion started by: Rakesh Thobula
6 Replies

5. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

6. UNIX for Dummies Questions & Answers

Zip multiple files and copy to help

Hi All, I have a set of large files ~ 500_900Mb I have generated and I'd like to quickly zip and copy them to a new folder elsewhere ... Can anyone suggest a quicky ?? Cheers :) (3 Replies)
Discussion started by: pawannoel
3 Replies

7. Shell Programming and Scripting

creating a multiple zip files

Hi, Please help me, i need a single line command for te below steps 1: listing a directory 2: searching a particular pattern in the names and creating the zip files of each eg : ls -lrt | grep jil | awk '{print $9}' output is kap.jil pranabjil pranabjil1 pranabjil2... (1 Reply)
Discussion started by: pranabrana
1 Replies

8. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

9. UNIX for Advanced & Expert Users

moving multiple files --recursively using BSD

i am using a FreeBSD remote account and I have directory that holds a number of other directories most of which posses *.tgz *.tar.bz2 *.gz files... on a linux system i would use a find format such as this to locate and mv *.tgz and *.tar.bz2 files find ./dir -type f -iname "*.t*" -print |... (3 Replies)
Discussion started by: moxxx68
3 Replies
Login or Register to Ask a Question