11
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.

25

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 for also mentioning the possibility of appending to the output file. – Dubu Nov 17 '15 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
    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 '15 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

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.