How to move files older than X to another folder?
87,450
Solution 1
The command seems ok and in my 11.10 it works. Haven't you missed the trailing slash in the destination folder?
find /storage/current/dbdumps/ -type f -mtime +30 -exec mv '{}' /storage/archive/dbdumps/ \;
Other thing you may try is using /bin/mv
insted of just mv
.
Solution 2
You can try this version (works in 11.10, i guess it will work in other versions too :) ):
find /storage/current/dbdumps/ -type f -mtime +30 -print | xargs -I {} mv "{}" /storage/archive/dbdumps
Related videos on Youtube
Author by
traveh
My name is Amir Ashkenazi and I am an accomplished web-site developer and webmaster. i own a blog about web developing web developers, computer geeks and site owners
Updated on September 18, 2022Comments
-
traveh over 1 year
How do I move files older than 30 days from folder
/storage/current/dbdumps/
to/storage/archive/dbdumps
?I tried:
find /storage/current/dbdumps/ -type f -mtime +30 -exec mv '{}' /storage/archive/dbdumps \;
but seems invalid in Ubuntu 11.04.
-
Admin over 12 yearswhat is the error message?
-
-
Iesus Sonesson over 7 yearsYou should use quotation around {} after mv, as files may or may not contain spaces etc. I would have piped the findings to
xargs -I{} mv "{}" /storage/archive/dbdumps/