Only Copying Files That Were Recently Modified
Recently I had to assist someone whose OneDrive had stopped working for a few days. Their OneDrive folder had to be reset entirely. However, doing so would mean that all files that had not yet been uploaded over the past few days, would be lost.
As a workaround, I looked for a solution that copied all files that were modified during the last 10 days. The following commands did the trick:
find /path/to/source -mtime -10 -type f -print > recent.txt
This first command builds a list of all files that were changed in the last 10 days (as specified by the -mtime
parameter). Good to know: if you every want to find all files not changed in the last 10 days, use +10
as the value.
Now we need to actually copy out the listed files. We can do so with rsync:
rsync -r --progress --files-from=recent.txt / /target/folder
The --files-from
parameter is where the magic happens. It instructs rsync to only copy files from the source if they are listed in the recent.txt
file we generated earlier.
To keep things simple, I recommend using only absolute paths in both commands.