Do not -exec mv the directory which is currently being examined by find. It seems that find gets confused when you do that.
Workaround: first find the directories, then move them.
cd "/mnt/user/New Movies/"
find -type f \( -name "*.avi" -or -name ".*mkv" \) -mtime +180 \
-printf "%h\0" | xargs -0 mv -t /mnt/user/Movies
Explanation:
-printfprints the match according to the format string.%hprints the path part of the match. This corresponds to the"${0%/*}"in your command.\0separates the items using the null character. This is just precaution in case the filenames contain newlines.xargscollects the input from the pipe and then executes its arguments with the input appended.-0tells xargs to expect the input to be null separated instead of newline separated.mv -t <target>allowsmvto be called with all the source arguments appended at the end.
Note that this is still not absolutely safe. Some freak scheduler timing in combination with pipe buffers might still cause the mv to be executed before find moved out of the directory. To prevent even that you can do it like this:
cd "/mnt/user/New Movies/"
find -type f \( -name "*.avi" -or -name ".*mkv" \) -mtime +180 \
-printf "%h\0" > dirstomove
xargs -0 mv -t /mnt/user/Movies < dirstomove
Background explanation:
I asume what happens with your find is following:
findtraverses the directory/mnt/user/New Movies/. While there it takes note of the available directories in its cache.findtraverses into one of the subdirectories using the system callchdir(subdirname).- Inside
findfinds a movie file which passes the filters. findexecutesmvwith the given parameters.mvmoves the directory to/mnt/user/Movies.findgoes back to parent directory using the system callchdir(..), which now points to/mnt/user/Moviesinstead of/mnt/user/New Movies/findis confused because it does not find the directories it noted earlier and throws up a lot of errors.
This assumption is based on the answer to this question: find -exec mv stops after first execfind -exec mv stops after first exec. I do not know why find just stops working in that case and throws up errors in your case. Different versions of find might be the explanation.