LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-10-2008, 02:32 AM   #1
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Rep: Reputation: 15
Question copy folder/files according to modification date


Hi,
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?
 
Old 10-10-2008, 03:04 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
GNU find can do that.
Type this on the command line to read information about finding files according to modification time:
Code:
info find "finding files" time
 
Old 10-10-2008, 04:09 AM   #3
cyprinidae
Member
 
Registered: Oct 2008
Distribution: Fedora, CentOS, Crunchbang
Posts: 46

Rep: Reputation: 16
Code:
find /"yourdir" -mtime "number of days since your date"
will return all of the files created "number of days" ago in "yourdir"
 
Old 10-10-2008, 04:33 AM   #4
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
Code:
$ find /path/to/some/folder/ -ctime -3 -exec scp  {} jane@192.168.2.22:/home/jane/test/ \;
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.
Code:
$ find /path/to/some/folder/ -type d -ctime -3 -exec scp  {} jane@192.168.2.22:/home/jane/test/ \;

Last edited by bkcreddy17; 10-10-2008 at 04:37 AM.
 
Old 10-10-2008, 08:19 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Use scp -r option to copy directories + contents
 
Old 10-10-2008, 07:50 PM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

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

Quote:
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
 
Old 10-10-2008, 11:18 PM   #7
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
Ok even with "mtime" it is not working out. I did like this, i know this is not working out.
Code:
$ find /path/to/some/folder/* -type d -mtime -3 -exec scp  {} jane@192.168.2.22:/home/jane/test/ \;
What is the solution?
 
Old 10-11-2008, 10:17 PM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

Rep: Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022
'not working' ??

you have to show us what you tried and what msg you got or what happened if no msgs.
 
Old 10-13-2008, 11:39 PM   #9
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
Code:
$ find /path/to/some/folder/* -type d -mtime -3 -exec scp  {} jane@192.168.2.22:/home/jane/test/ \;
/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?
 
Old 10-14-2008, 01:44 AM   #10
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

Rep: Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022
did you see Hko's post #5 ?
 
Old 10-14-2008, 04:39 AM   #11
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
Thank you. This is it....
Code:
$ find /path/to/some/folder/* -type d -mtime -3 -exec scp -r {} jane@192.168.2.22:/home/jane/test/ \;
 
Old 10-14-2008, 05:11 AM   #12
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
If i want to do in between two machines by sitting on my machine, how is it possible?
 
Old 10-14-2008, 07:09 PM   #13
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

Rep: Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022
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
 
Old 10-14-2008, 11:28 PM   #14
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
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.
 
Old 10-15-2008, 07:24 PM   #15
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

Rep: Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete/move/copy files of specific date imsajjadali Red Hat 26 11-07-2013 11:34 PM
Copy Date/Time without actual files? - a real head scratcher tbeehler Linux - Software 17 07-25-2007 04:20 AM
CLI copy files by date linuxhippy Slackware 2 06-23-2006 09:01 PM
Auto Change Date on copy to user folder mariusak Linux - General 4 05-28-2005 06:42 PM
Copy files after a certain date davholla Linux - General 2 03-17-2005 09:29 AM


All times are GMT -5. The time now is 12:35 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration