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
Solved

use find to search through compressed files?

Posted on 2004-09-07
12
323 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coding C# in Linux 8 125
Need help in coverting and customizing my exisiting RHEL/SUSE image to qcow/cloud image 33 88
ignore other .htaccess 2 58
Linux FTP Error 5 33
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

839 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