Solved

use find to search through compressed files?

Posted on 2004-09-07
12
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

738 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