Solved

use find to search through compressed files?

Posted on 2004-09-07
12
325 Views
Last Modified: 2012-05-05
Hi all,

Is it possible? I don't see any option in the man page for this.

I'm looking for an old file on a windows machine with cygwin installed. I tend to compress (and not consistently either, sometimes zip, bzip2, or gzip) old file/directories and lump them all together. I'm sure I have the file somewhere but it is likely compressed in my mess of archives somewhere and I don't want to manually have to search through them all.

Any suggestions?

Thanks,

-Pat
0
Comment
Question by:pat5star
  • 3
  • 3
  • 3
  • +2
12 Comments
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 125 total points
ID: 12003620
Hi pat5star,

find / -name "*.gz" | while read name
do
     temp=`gzip -l $name | awk ' { print $4 } ' | grep <filename>`
     if [ -n $temp ]
            echo $name has <filename>
     fi
done

Sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12003628
pat5star,

A similar script can be written for bzip2 or any other archiving program that will let you list the files in the archive

Sunnycoder
0
 
LVL 23

Assisted Solution

by:Mysidia
Mysidia earned 125 total points
ID: 12003679
Yes, it's possible it may just take a long time.
for example...

mkdir /tmp/lists
cd /tmp/lists

basepath=/path/to/start/from
gpcmd='grep -i filename_you_are_looking_for'
find $basepath -name \*.zip -print0 > zips
find $basepath -name \*.tar -print0 > tarballs
find $basepath -name \*.tar.bz2 -print0 > bzip_tarballs
find $basepath -name \*.tar.gz -print0 > gzip_tarballs

cat zips |xargs -0 -n 1 unzip -v |$gpcmd
cat tarballs |xargs -0 -n 1 tar tvf |$gpcmd
cat bzip_tarballs |xargs -0 -n 1 tar jtvf |$gpcmd
cat gzip |xargs -0 -n 1 tar jtvf |$gpcmd
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 23

Expert Comment

by:Mysidia
ID: 12003792
Err, actually, my above commands would find if it's around but not tell you exactly which archive
the file was found in (fairly useless)

Instead, an approach more like this:

cat zips |xargs --verbose --replace -0 sh -c 'echo "Archive: {}" ; unzip -v "{}" |grep name_search_text'
cat tarballs |xargs --verbose --replace -0 sh -c 'echo "Archive: {}" ; tar tvf "{}" |grep name_search_text'
cat bzip_tarballs |xargs --verbose --replace -0 sh -c 'echo "Archive: {}" ; tar jtvf "{}" |grep name_search_text'
cat gzip |xargs --verbose --replace -0 sh -c 'echo "Archive: {}" ; tar ztvf "{}" |grep name_search_text'
0
 
LVL 17

Accepted Solution

by:
owensleftfoot earned 250 total points
ID: 12004826
For a change maybe windows has an easier solution :) Have a look at http://www.worldssp.net/software/Zipsearch.htm
0
 
LVL 20

Expert Comment

by:Gns
ID: 12005949
Um what's easier with a shareware install Foot? Extending Sunnys script (sorry Mysidia, I've not looked over your scriptlets for sanity... yet:-) to "work" with any number of tools/archivers for finding the archive containing a specific file is trivial.

-- Glenn
0
 
LVL 17

Expert Comment

by:owensleftfoot
ID: 12011255
" Um what's easier with a shareware install Foot?"

Hi Glen. he's looking for "an old file". With the emphasis on "an". As in singular. Why bother typing in some of the above code (which may well not work or may be buggy) when  he can download a shareware windows program which will  do what he wants "out of the box"? A lazy programmer is a good programmer.. You cant get any lazier than not having to program at all. I prefer linux but Im not political about it - if there is an easier windows solution I will use it.
0
 
LVL 3

Author Comment

by:pat5star
ID: 12012975
I awarded a grade of 'A' to this answer as all solutions were very helpful. I awarded 250 points to owensleftfoot because in this particular case I needed to find the file on a windows machine and his suggestion is really the easiest to use and enabled me to find what I needed. I awarded 125 points both to sunnycoder and Mysidia as those scripts should work well for me on my linux machines or even the windows machines that I have cygwin installed on.

Normally I like writing or tweaking scripts to do what I want but this case is different. I needed that file ASAP and really didn't want to spend the time tweaking and testing a script to make sure it's checking all directories, files, and compressed files properly. Later when I have time to spare I will as these are handy scripts that I know I'll need again in the future...at least until I learn how to archive things in a more orderly fashion :P

I hope everyone is happy with the way I split the points and I appreciate the advice. Thanks again,

-Pat
0
 
LVL 20

Expert Comment

by:Gns
ID: 12013880
Thank you Pat for the nice feedback. (And now Foot can say the mandatory "nananananana, I wa-as ri-ight":-):-)

-- Glenn
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12013936
lol ... I cant wait to hear that :o)
0
 
LVL 17

Expert Comment

by:owensleftfoot
ID: 12014393
" Thank you Pat for the nice feedback. (And now Foot can say the mandatory "nananananana, I wa-as ri-ight":-):-)"

Im too much of a gentleman Glen :)
0
 
LVL 20

Expert Comment

by:Gns
ID: 12014401
:-)

-- Glenn
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question