36
You're almost right.
-mtime 365 will be all files that are exactly 365 days old. You want the ones that are 365 days old or more, which means adding a + before the number like this -mtime +365.
You may also be interested in the
-maxdepth 1 flag, which prevents you from moving items in sub directories.
If you want to be sure that you are only moving files, not directories, add
-type f to the line.
At the end of the line we add
\; so that find knows that's the end of the command we are executing.
So the line should be:
find /sourcedirectory -maxdepth 1 -mtime +365 -type f -exec mv "{}" /destination/directory/ \;
To be on the safe side, start by just doing a ls -l instead of mv - that way you can check in advance that you're getting exactly the files you want, before re-running it with mv, like this:
find /sourcedirectory -maxdepth 1 -mtime +365 -type f -exec ls -l {} \;
No hay comentarios:
Publicar un comentario