LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How To Copy all Files and Folders from specific date? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-copy-all-files-and-folders-from-specific-date-882819/)

moviecarpet 05-26-2011 08:16 AM

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

Adol 05-26-2011 08:52 AM

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

Adol 05-26-2011 05:32 PM

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

MTK358 05-26-2011 06:17 PM

Quote:

Originally Posted by Adol (Post 4368065)
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.

crts 05-26-2011 07:01 PM

Quote:

Originally Posted by moviecarpet (Post 4367615)
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.


All times are GMT -5. The time now is 11:31 PM.