zipping in a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting zipping in a loop
# 1  
Old 01-10-2007
Error zipping in a loop

Hello All,
I have a requirement that i need to gzip each file that is more than 5 days old inside a directory. Could some one help me with the script ?
do i need to write a for loop or can be done through single command?

Thanks,
Sateesh
# 2  
Old 01-10-2007
Code:
find . -mtime +5 | xargs gzip

# 3  
Old 01-10-2007
gzip only compresses a single file, so you need an intermediate program to generate an archive file which can then be compressed using gzip, so we try something like:
Code:
tar cvf - `find . -type f -mtime +5` | gzip -c 1>outputfile.tgz

To uncompress, you can try something like:
Code:
gunzip -c outputfile.tgz | tar xvf -

Regards,
Tayyab
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Zipping

Good Morning, I'd like to archive an old user's files in the home directory on Solaris 9 Will this work? cd home tar -zcvf jsmitharchive.tar.gz jsmith/ ---------- Post updated at 09:37 AM ---------- Previous update was at 09:33 AM ---------- Also- is the last /necessary (after... (4 Replies)
Discussion started by: Stellaman1977
4 Replies

2. Shell Programming and Scripting

Zipping files

Hi Guys, The script below works but it creates a zip folder under 123_arch.zip -- test1 -- orig1.txt -- orig2.txt -- orig3.txt -- orig4.txt I don't want the sub directory test1 but everything under the base *arch name I can not create a long name with... (4 Replies)
Discussion started by: GaryP1973
4 Replies

3. UNIX for Dummies Questions & Answers

Zipping files

Hi All, I have a scenario where in am using uuencode to send a txt file as an excel to end users( email attachment).I have 7 different files and these files are sent as emails 7 times... So my question is, can i not zip all the 7 files at once and attach those files in a single... (9 Replies)
Discussion started by: saggiboy10
9 Replies

4. Shell Programming and Scripting

Zipping and moving

Hi, I have got the script which find out the file that was modified 3 days ago now i want that all the files which fall into this category to be get zipped and then send to another directory...plz can u suggest me for that or any commands (18 Replies)
Discussion started by: SARAL SAXENA
18 Replies

5. Shell Programming and Scripting

zipping files

Hi, Is there any difference if files are individually zipped and archived in a directory or if files are moved into archiving directory and zipping that directory. (3 Replies)
Discussion started by: swathich
3 Replies

6. Shell Programming and Scripting

copying and zipping

Hi I have managed to copy a few files into a directory but since there are too many files it looks a bit untidy . Is there a way i can directly copy all of them into a compresses file(.gz). This would make it easier to ftp the file as well...Many Thanks... (2 Replies)
Discussion started by: jamshedj
2 Replies

7. UNIX for Dummies Questions & Answers

Zipping files?

how would i zip a file? what does zip mean? (4 Replies)
Discussion started by: trob
4 Replies

8. Shell Programming and Scripting

zipping files

Dear Experts, I need a script which will zipped the files older than 2 days. but i dont want to use find . * -mtime 2. Is there is any other method to achive this task. i will ececute the script daily. Regards, (3 Replies)
Discussion started by: shary
3 Replies

9. UNIX for Dummies Questions & Answers

Zipping

Hi In unix i want to zip the files in a directory excluding *.dmp, *.log, *.lst, *.out files in that directory. pls let me know what command to use. $zip ........ ? Thanks (1 Reply)
Discussion started by: dreams5617
1 Replies

10. Shell Programming and Scripting

Zipping the dir

Hi, Ex: Directory /u01/par If a directory contains all the below files: a.lst b.lst c.lst d.lst ......etc i have 50 files in this directory. How to(command to) zip all the files in this directory into a single zip file. Thanks (1 Reply)
Discussion started by: dreams5617
1 Replies
Login or Register to Ask a Question