LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2011, 12:34 PM   #1
dougp23
Member
 
Registered: Oct 2006
Posts: 43

Rep: Reputation: 15
BASH Unzip (and Search) Many Files in Directories


Our email system does a backup each day of all email sent and received, and stores it in a directory with the date stamp, so:

mail/2010-10-10/2010-10-10.zip
mail/2010-10-11/2010-10-11.zip
mail/2010-10-12/2010-10-12.zip

etc

I now have to provide all emails from jsmith@whatver.com from 2010-10-01 to 2010-12-31. Of course, this is impossible to do until I unzip everything!

There has got to be a way to automate this! I am thinking some sort of bash script would walk through all the directories unzipping as it went, then I could use egrep or something for what i am looking for.

Appreciate any help!
 
Old 03-09-2011, 12:36 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Do you have to keep the unzipped files in the dated directories? Or can the unzipped files be lumped into one directory together?
 
Old 03-09-2011, 12:41 PM   #3
dougp23
Member
 
Registered: Oct 2006
Posts: 43

Original Poster
Rep: Reputation: 15
Nope, it could all be unzipped into one big directory! I'm not fussy, lol!
 
Old 03-09-2011, 01:20 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Code:
cd /mail/directory/; find . -name \*.zip -exec unzip {} -d /some/directory/to/unzip/to/ \;
 
1 members found this post helpful.
Old 03-09-2011, 01:45 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
What about zipgrep? It is a shell script usually provided by the unzip package that does exactly what you're looking for, using unzip and egrep.
 
1 members found this post helpful.
  


Reply



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
BASH: Unzip files/folders from archive one at a time using a loop cade Programming 3 05-16-2010 10:48 PM
Search repo for files/directories by name with wget gnashley Programming 1 12-30-2007 05:13 AM
Bash script to search through directories. mcdrr Programming 5 05-11-2007 05:41 PM
How to search all directories for a file in bash overlook1977 Linux - Newbie 7 04-10-2007 07:00 AM
Search for files only in directories you have sufficient permissions tepez Linux - Software 1 04-08-2007 10:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:48 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