13
find -type f -name "*.avi" -exec md5sum {} + > checklist.chk
find -type f -name "*.mp4" -exec md5sum {} + > checklist.chk

How to combine these two commands?

  1. Either by combining both search terms in one command or

  2. So that each command adds its output to the same file.

Hope it's clear what I am trying to do.

0

3 Answers 3

26

Combining:

find -type f \( -name "*.avi" -or -name '*.mp4' \) -exec md5sum {} + > checklist.chk 

Adding output to one file:

find -type f -name "*.avi" -exec md5sum {} + > checklist.chk
find -type f -name "*.mp4" -exec md5sum {} + >> checklist.chk
1
  • 1
    +1 for also mentioning the possibility of appending to the output file.
    – Dubu
    Nov 17, 2015 at 8:24
8

There are many ways to do this:

Using Or -o:

find . -type f \( -name '*.avi' -o -name '*.mp4' \) -exec md5sum {} + > checklist.chk

Using Regex:

find . -type f  -regextype posix-extended -regex '.*\.(avi|mp4)$' -exec md5sum {} + > checklist.chk

Both will write the output to the file checklist.chk.

1
  • 1
    Thanks.. I knew about the -o operator but didn't know the syntax. Also didn't know about regex can be used like this. Thanks :)
    – akya
    Nov 17, 2015 at 7:40
4

With the -o flag ( which is under OPERATORS in find's man page )

find . -type f \( -name "*.avi" -o -name "*.mp4" \) -exec md5sum {} + > checklist.chk

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .