linuxbashfindmove

Find different types of files and move to a specific directory


Finding *.mkv and *.mp4 works

find /home6/movies/ -name '*.mp4' -o -name '*.mkv'

but moving them for some reason partially fails and moves only mkv files

find /home6/movies/ -name '*.mp4' -o -name '*.mkv' -exec mv {} /home6/archive/ \;

Am I using an incorrect find switch "-o" for this task?


Solution

  • Looks like you need to surround the or expression in parentheses so the exec applies to both matches.

    This is a similar question: `find -name` pattern that matches multiple patterns

    find /home6/movies/ \( -name '*.mp4' -o -name '*.mkv' \) -exec mv {} /home6/archive/ \;