Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to use the find command so that it searches the files within a tar.gz archive also using wildcards?

like

find archive.tar.gz --name *foo*
share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

How about just:

$ tar tf archive.tar.gz | grep foo
share|improve this answer
    
doesnt that just list all the files? –  clamp Mar 12 '12 at 13:06
    
@clamp Yes, if you want to do something to each file, simply pipe that output to another command. –  Herman Torjussen Mar 12 '12 at 13:07
    
thanks! sorry but im a newbie in unix. i tried: tar tf graphics.tar.gz | find . --name *space* but it says unkown predicate --name –  clamp Mar 12 '12 at 13:17
    
@clamp find arguments only take one dash, but because it's a list of files on stdin, you want to use grep instead, like hesse's example code. Try tar tf graphics.tar.gz | grep 'space' –  Kevin Mar 12 '12 at 13:24
1  
grep *foo* isn't a valid regular expression. greg doesn't understand globs, it understands regular expressions. Try grep foo instead. –  Alexios Mar 12 '12 at 14:19
show 2 more comments

Mount the archive as a directory. You can do it with the AVFS filesystem, which allows you to access any archive as a directory whose name has a trailing #.

mountavfs
cd ~/.avfs$PWD
find archive.tar.gz\# -name '*foo*'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.