Making a copy of all files (including subdirectories)...

Forum rules
Before you post please read this

Making a copy of all files (including subdirectories)...

Postby tharpa on Tue Sep 10, 2013 8:42 pm

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?
tharpa
Level 1
Level 1
 
Posts: 35
Joined: Sat Mar 24, 2012 3:18 pm
Location: North America

Linux Mint is funded by ads and donations.
 

Re: Making a copy of all files (including subdirectories)...

Postby bigj231 on Tue Sep 10, 2013 9:52 pm

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"
http://www.unix.com/shell-programming-scripting/34582-trying-copy-files-changed-recently.html
When scripting, google is your friend.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: Making a copy of all files (including subdirectories)...

Postby tharpa on Tue Sep 10, 2013 10:45 pm

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.
tharpa
Level 1
Level 1
 
Posts: 35
Joined: Sat Mar 24, 2012 3:18 pm
Location: North America

Re: Making a copy of all files (including subdirectories)...

Postby Habitual on Sun Sep 15, 2013 8:20 pm

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.
What's a landing but a take off in reverse?
My DorkBlog
User avatar
Habitual
Level 8
Level 8
 
Posts: 2001
Joined: Sun Nov 21, 2010 8:31 pm
Location: Slackware

Re: Making a copy of all files (including subdirectories)...

Postby tharpa on Thu Sep 19, 2013 8:56 pm

The Ubuntu forum was actually helpful.

Code: Select all
cd /src
rsync -aR0vn --files-from=<( find . -mtime -30 -type f -print0 ) . /dest

n = dry run


http://ubuntuforums.org/showthread.php?t=2174664
tharpa
Level 1
Level 1
 
Posts: 35
Joined: Sat Mar 24, 2012 3:18 pm
Location: North America

Re: Making a copy of all files (including subdirectories)...

Postby Habitual on Thu Sep 19, 2013 10:37 pm

Yeah, Vaphell is a code-ninja. ;)
What's a landing but a take off in reverse?
My DorkBlog
User avatar
Habitual
Level 8
Level 8
 
Posts: 2001
Joined: Sun Nov 21, 2010 8:31 pm
Location: Slackware


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest