-   Programming (
-   -   copy folder/files according to modification date (

bkcreddy17 10-10-2008 02:32 AM

copy folder/files according to modification date
Is there any command combination or a bash shell script to copy directory/file according to date of modification or creation.
Suppose i want to copy files/dir creater on 2007-Feb-11 in to some directory. How to do this?

Hko 10-10-2008 03:04 AM

GNU find can do that.
Type this on the command line to read information about finding files according to modification time:

info find "finding files" time

cyprinidae 10-10-2008 04:09 AM


find /"yourdir" -mtime "number of days since your date"
will return all of the files created "number of days" ago in "yourdir"

bkcreddy17 10-10-2008 04:33 AM


$ find /path/to/some/folder/ -ctime -3 -exec scp  {} jane@ \;
Yeh i am able to copy file but nut folder. How do i copy a folder and its content?
It is not happening even like this.

$ find /path/to/some/folder/ -type d -ctime -3 -exec scp  {} jane@ \;

Hko 10-10-2008 08:19 AM

Use scp -r option to copy directories + contents

chrism01 10-10-2008 07:50 PM

FYI, I'd use mtime .. there's no such thing as 'creation' time in Unix.


Three fields in the inode structure contain the last access, change, and modification times: atime, ctime, and mtime. The atime field is updated each time the pointer to the file's data blocks is followed and the file's data is read. The mtime field is updated each time the file's data changes. The ctime field is updated each time the file's inode changes. The ctime is not creation time; there is no way under standard Unix to find a file's creation time.
Perl Cookbook

bkcreddy17 10-10-2008 11:18 PM

Ok even with "mtime" it is not working out. I did like this, i know this is not working out.

$ find /path/to/some/folder/* -type d -mtime -3 -exec scp  {} jane@ \;
What is the solution?

chrism01 10-11-2008 10:17 PM

'not working' ??

you have to show us what you tried and what msg you got or what happened if no msgs.

bkcreddy17 10-13-2008 11:39 PM


$ find /path/to/some/folder/* -type d -mtime -3 -exec scp  {} jane@ \;
/path/to/some/folder/dir1: not a regular file
/path/to/some/folder/dir2: not a regular file
/path/to/some/folder/dir3: not a regular file

This was the out put i got.It is considering as a file but not directories. Files are getting copied but not directories. How to copy directories?

chrism01 10-14-2008 01:44 AM

did you see Hko's post #5 ?

bkcreddy17 10-14-2008 04:39 AM

Thank you. This is it....

$ find /path/to/some/folder/* -type d -mtime -3 -exec scp -r {} jane@ \;

bkcreddy17 10-14-2008 05:11 AM

If i want to do in between two machines by sitting on my machine, how is it possible?

chrism01 10-14-2008 07:09 PM

Both scp args (src and dest) can be user@machine so

current> scp user1@box1:/home/user1/file user1@box2:/home/user1/file

if you have access to all 3 systems; src, dest, current

bkcreddy17 10-14-2008 11:28 PM

No, not just copying with scp. It should find the latest files/dir modified in src remote machine and then copy them into dest local machine. This action must be performed from the local machine.

chrism01 10-15-2008 07:24 PM

Look into rsync. Not sure if you can do it in one line like that; ie its normally just 2 machines involved, src, dest.

If not, you'll either have to setup rsync on the 2 machines you want to update between, or find a way of generating the expected filenames and use scp as described.

All times are GMT -5. The time now is 02:29 PM.