I tried the answers here, but without luck.

find . -name "*.epub" -exec zipgrep pattern {} \;

showed me "matched", but didn't give me the matching epub file back. Also, it returned huge blobs of data, which were hard to grep through.

grep -a didn't work at all.

I want something like grep -R but for epub files.

  • I think zipgrep should pass other command line options to egrep, so did you try adding -H (or -l if you want only the matching filename)? – steeldriver Jun 28 '18 at 15:57

This will give you the full path to all the *.epub files.

find / -name *.epub -exec ls {} \; 2>/dev/null

If you want to store that ouput in a list:

find / -name *.epub -exec ls {} \; 2>/dev/null >> /tmp/list

If you want to search that list for a string I would use a for loop. If you are getting huge blobs of data it may see them as one long line. this will print the patter and the 5 char before and after.

for i in `cat /tmp/list` ; do echo $i ; grep -a -o -p '.{0,5}pattern.{0,5}' ; done
  • Thanks a lot! Thats a super useful combination of commands. However, the first one just doesn't give me anything back? (I have a lot of epub files in that folder/subfolder). – JJ Abrams Jun 28 '18 at 16:45
  • Which distro are you using? This works with RHEL6. $ find /tmp -name *.epub -exec ls {} \; 2>/dev/null /tmp/test/subdir/sub.epub /tmp/test/subdir/subdir2/sub2.epub /tmp/test/test2.epub /tmp/test.epub – SpruceTips Jun 28 '18 at 17:09
  • 1
    You do not need -exec ls, this is the default behaviour of find. – Patrick Mevzek Jun 28 '18 at 17:09
  • @SpruceTips: I am using Ubuntu 16.04 and I ran the same command (just replaced the / with a . ) – JJ Abrams Jun 28 '18 at 17:30

I would use:

find . -name '*.epub'  -exec zipgrep -q {pattern} {} \; -print
  • -q suppresses the display of hits
  • since zipgrep returns 0 only if it finds a match, the -exec zipgrep ... acts as a filter, so the -print is only executed if there was a match (in case you need it, it can be another -exec that will only be executed on the matching files).
  • I get quite some errors when running the command: caution: filename not matched: OEBPS/images/[Originaldateien]/ caution: filename not matched: OEBPS/images/[Originaldateien]/929-4-8300-2179-8_img_cover.jpg caution: filename not matched: OEBPS/images/[Originaldateien]/logo.bmp zipinfo: cannot find or open ./new_ebooks/Harry, Fontaine - Final Chapter Three.epub, ./new_ebooks/Harry, Fontaine - Final Chapter Three.epub.zip or ./new_ebooks/Harry, Fontaine - Final Chapter Three.epub.ZIP. /usr/bin/zipgrep: 97: test: -eq: unexpected operator /usr/bin/zipgrep: 100: test: Illegal number: – JJ Abrams Jun 28 '18 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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