Lots of searching with this current project… this time looking for files inside an archive, without having to extract them first. Using Apple’s Terminal, or any Unix / Linux bash shell: [script lang="bash"]find /dir/ -iname archive.tar -print0 | xargs -0 tar t -f | grep “filename you are searching for”
find /dir/ -iname archive.zip -print0 | xargs -0 unzip -l | grep “filename you are searching for”
find /dir/ -iname archive.rar -print0 | xargs -0 unrar l | grep “filename you are searching for”
[/script]
Command breakdown
(:TODO: code formatter)
- find /dir/
- use the powerful find command inside the folder where the archive is
- -iname archive.
- look for the archive (case insensitive search)
- -print0
- when files are found, spit them out in a list with a NULL at the end instead of a new line – this helps with the next step
- |
- pass the list generated by find to the next command…
- xargs -0
- …which is xargs, used to take a list of results and pass them on. The -0 is telling xargs to use NULL as the separator
- tar t -f
- use tar to list (t) the content of the archive, files only (-f)
- unzip -l
- use unzip to list the content of the archive
- unrar l
- use unrar to list the content of the archive
- |
- pass the list generated by find to the next command…
- grep “filename you are searching for”
- only show the items in the list that match the fillename, using grep

Updates
subscribe to this blog's rss feed'
follow me on twitter
subscribe friendfeed
my delicious bookmarks
my youtube channel