Making a copy of all files (including subdirectories)...
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Making a copy of all files (including subdirectories)...
I would like to write a command to copy all of files in a directory and its subdirectories that have been modified in the last month. How do I do this?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Making a copy of all files (including subdirectories)...
Not sure of a way to only copy files modified in the past month, but using cp with the -rfu flag should copy all files in all subfolders that are newer than the ones in the target directory.
I'm sure there is a way to only copy files modified in the past month, but it will most likely require a few lines of code instead of a single command.
Here's one of the top results of a google search using the query "how to copy files modified recently linux"
[url]http://www.unix.com/shell-programming-scripting/34582-trying-copy-files-changed-recently.html[/url]
When scripting, google is your friend.
I'm sure there is a way to only copy files modified in the past month, but it will most likely require a few lines of code instead of a single command.
Here's one of the top results of a google search using the query "how to copy files modified recently linux"
[url]http://www.unix.com/shell-programming-scripting/34582-trying-copy-files-changed-recently.html[/url]
When scripting, google is your friend.
Re: Making a copy of all files (including subdirectories)...
Thanks, big. What is this Google you speak of? Cuz, ya know, if you don't know the answer, then it's never the case that the OP has already tried Google (and/or other search engines) before posting.
If anyone else has helpful info, please let me know.
If anyone else has helpful info, please let me know.
Re: Making a copy of all files (including subdirectories)...
Code: Select all
man find
...
-mtime n
File's data was last modified n*24 hours ago. See the comments for -atime to understand how
rounding affects the interpretation of file modification times.
Re: Making a copy of all files (including subdirectories)...
The Ubuntu forum was actually helpful.
[url]http://ubuntuforums.org/showthread.php?t=2174664[/url]
Code: Select all
cd /src
rsync -aR0vn --files-from=<( find . -mtime -30 -type f -print0 ) . /dest
n = dry run
Re: Making a copy of all files (including subdirectories)...
Yeah, Vaphell is a code-ninja.