Finding a file contained within a bunch of tar files without opening any

So I was debugging some code the other day and I quickly found myself in a situation where I had to look for a class file that was located in one of the many millions of jar files that are there in my maven cache. My immediate reaction was

“Ugh, this is going to be loads of effort and is going to take ages!”.

Luckily, quick one minute google found the following command:

find /home/manthan/.m2 -name '*.jar' -type f|while read f; do p="$(tar tf $f|egrep awesome)"; [ -n "$p" ] && echo -e "$f\n$p" ; p=""; done

Where awesome.class is the file I’m looking for in all files (indicated with -type f option) with extension jar found in /home/manthan/.m2 directory.

Source: Superuser – Search through tar files for a pattern and print the full path of what’s found

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.