Tuesday, 20 August 2013

Find and move directories based on file type and date

Find and move directories based on file type and date

I have a directory "New Movies" containing 200+ subdirectories "Movie Name
(year)". The subdirectories "Movie Name (year)" contains a single video
file (avi/mkv) and several related jpg/xml files.
I need to move all directories containing a video file that is at least
180 days old to another directory.
For example:
New Movies/Movie A (year) would contain movie.mkv, folder.jpg & movie.xml
and I want to move them to a subdirectory of the same name elsewhere with
all files present and intact.
After looking elsewhere on this site I have tried:
cd "/mnt/user/New Movies/"
find -type f \( -name "*.avi" -or -name ".*mkv" \) -mtime +180 -exec sh -c
'mv "${0%/*}" /mnt/user/Movies' {} \;
The command successfully moves the first subdirectory and all files to
their new home, however every single operation after this one returns the
error
find: './Movie B (year)': No such file or directory
find: './Movie C (year)': No such file or directory
and so on through all directories contained under "New Movies" whether
they were due to be moved or not.

No comments:

Post a Comment