Quote:
Originally Posted by xavix
Hello,
How can I move files based on age in the following scenario:
$SOURCE contains some subfolders with some files inside them.
Each subfolder contain files of the same date, but the last modofication date of the subfolder can be more recent than the date of the files inside it, e.g.:
$tree . -D
.
|-- [Feb 18 16:44] Folder1
| |-- [Feb 3 3:58] 1.jpg
| |-- [Feb 3 3:58] 2.avi
| `-- [Feb 3 3:58] 3.jpg
`-- [Feb 18 16:44] Folder2
|-- [Jan 29 3:33] a.jpg
|-- [Jan 29 3:33] b.jpg
|-- [Jan 29 3:33] c.avi
`-- [Jan 29 3:34] d.avi
If I try to move only the files newer than 15 days (today is Feb 18) with the following command, I get all the entire tree because it seems is just reading the date on the folders not on the files.
find $SOURCE -mtime -15 -exec mv {} $DEST \;
So, I want to move the files and the folders that contains the files to $DEST.
You might have to write a bit more code to be a bit more specific with what you want. Since $SOURCE contains the list of directories, it is using the dates on those as the comparison to mtime. What you are not telling it to do is go into the directories by using the --depth option to find. Also, I would have to check and see if find has an option to not act on directories themselves.
Regards,
Jeff