LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2011, 09:16 AM   #1
moviecarpet
LQ Newbie
 
Registered: May 2011
Posts: 7

Rep: Reputation: Disabled
How To Copy all Files and Folders from specific date?


Hi
I wanna copy all folders and files created from 01.01.2011 until today to new place

ie:

cp -r /home/moviecar/public_html/wp-content/uploads/ /home/teaser/public_html/wp-content/uploads
 
Old 05-26-2011, 09:52 AM   #2
Adol
Member
 
Registered: Feb 2011
Location: Osaka, Japan
Distribution: Gentoo, Opensuse
Posts: 262

Rep: Reputation: 5
I found a method that should work using xarg and find commands(but I cant get it working. You may have better luck).

Here is the url:
http://www.cyberciti.biz/faq/linux-u...lists-utility/

Here is the command I'm tying:
Code:
find /home/petreuss/examp1/ -mtime -30 | xargs -0 -r -I * cp -v -p * --target-directory=/home/petreuss/examp2
Code:
-mtime -30
looks for files made 30 days ago.

If anyone sees the mistake in my code please let me know. Its really starting to irritate me.

Good luck

Last edited by Adol; 05-26-2011 at 10:51 AM.
 
Old 05-26-2011, 06:32 PM   #3
Adol
Member
 
Registered: Feb 2011
Location: Osaka, Japan
Distribution: Gentoo, Opensuse
Posts: 262

Rep: Reputation: 5
Ok.

I got the command working.

I hope this helps your situation.

I'm using this command the find to move/copy files:
Code:
find /home/petreuss/test/ -iname "*" -mtime -30 -print0 | xargs -0 -I {} cp -v {} /home/petreuss/test2/
find command includes directory you are searching.

iname can filter files for example
Code:
-iname ".txt"
only finds .txt files.

Code:
-mtime
this is the time varriable. You can use this chart to set it:

Quote:
find . -mtime 0 # find files modified between now and 1 day ago
# (i.e., within the past 24 hours)
find . -mtime -1 # find files modified less than 1 day ago
# (i.e., within the past 24 hours, as before)
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago

find . -mmin +5 -mmin -10 # find files modified between
# 6 and 9 minutes ago
Code:
-print0
this is important because it prints the files and gets them ready for xarg to work.

Good luck
 
Old 05-26-2011, 07:17 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by Adol View Post
Code:
-print0
this is important because it prints the files and gets them ready for xarg to work.
Better explanation: it separates the filenames with NULL characters instead of newlines. This is good becasue filenames can actually contain newlines (even though the chance of this is almost zero and you should never name a file like that), but not NULLs.

The "-0" option to xargs tells it to use NULLs as separators.
 
1 members found this post helpful.
Old 05-26-2011, 08:01 PM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by moviecarpet View Post
Hi
I wanna copy all folders and files created from 01.01.2011 until today to new place

ie:

cp -r /home/moviecar/public_html/wp-content/uploads/ /home/teaser/public_html/wp-content/uploads
The Linux ext filesystem does not store creation time. You probably want modification time. Using -mtime is not the only option. You can use find's -newer and/or -newerXY option to achieve what you are trying. But you will first have to generate a reference file with the same timestamp that you want to use as reference; in your case that would be 01.01.2011. The 'touch' command can do this:
Code:
touch -t 201101010000 reference.file
Confirm that the modification time is correct
Code:
$ stat -c "%y %n" reference.file
2011-01-01 00:00:00.000000000 +0000 reference.file
Now you can use this file as reference file for the -newer option:
Code:
find /path/to/folder -type f -newer reference.file -exec cp '{}' /path/to/target/folder \;
I see a windows logo in your profile. If you want to search a windows partition then you could try to use the -newerXY option (man find for more info on that).
Code:
find /path/to/folder -type f -newerBB reference.file -exec cp '{}' /path/to/target/folder \;
'-newerBB' means that it will compare the birth-time of the file which should be the creation time in windows. Note, that you will also have to create the reference file on a windows partition, so that it will have the creation time attribute.
[IMPORTANT]
I have used this technique on Linux filesystems but I have never tried using 'find' this way on a windows partition. I am simply deducing the procedure.

Hope this helps.

Last edited by crts; 05-26-2011 at 08:05 PM.
 
  


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-08-2013 12:34 AM
deleting by date a specific range of files nooks12 Linux - Newbie 2 01-08-2008 03:45 PM
Command to copy files/folders but skip bad/corrupt files?? leemoreau Linux - Newbie 2 04-02-2007 03:27 PM
Finding out the creation date for files/folders... darkarcon2015 Linux - Software 1 03-24-2005 06:59 PM
Copying files from a specific date dman65 Linux - Software 3 09-22-2003 11:16 AM


All times are GMT -5. The time now is 10:44 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration