Visit Our UNIX and Linux User Community


Copy files for particular dates


 
Thread Tools Search this Thread
Operating Systems AIX Copy files for particular dates
# 1  
Old 03-01-2012
Question Copy files for particular dates

Hi,

I need to copy particular date files from one directory to another.

For example,
I have thousands of files in
/home/usr
From this I need to copy only particular date files (each date contains thousand number of files) to some directory of another server.

Could anyone please help me on to just copying this particular date files from one directory to another directory?

Please help me on this guys.

Thanks in advance .
# 2  
Old 03-01-2012
Do your file names contain the date that you'll use to select them, or are you needing to use the last modification time of the file as your selection criteria? The answer to this question will determine the method needed to find and copy the files. If the filenames contain the date you wish to use, please post a sample of the names.
# 3  
Old 03-02-2012
yeah I need particular date like Feb 15 and Feb 16 files.

Thank you
# 4  
Old 03-03-2012
Assuming by your response that the file names do NOT contain the date, and thus you need to base your selection on the last modification time, this would be one way. Create a start/end marker with timestamps that bound your desired selection criteria, and then run a find that lists all files that fall within that range.

Code:
#!/usr/bin/env ksh

touch -t 201202150000.00 marker.start    # bounds Feb 15 2012 midnight - Feb 16 23:59:59
touch -t 201202162359.59 marker.end

# cd to desired directory if needed, or enter full path instead of '.' in the find command 
find . -type f -newer marker.start  ! -newer marker.end   |while read file
do
    if [[ ${file%%.*} != "marker" ]]    # skip markers (assumes no files you want to copy start with marker.
    then
        ls -al "$file"            # demonstration/verification 
        # remove the ls command and replace with your copy command 
    fi
done
rm marker.start marker.end


Last edited by agama; 03-03-2012 at 12:41 PM.. Reason: clarification

Previous Thread | Next Thread
Test Your Knowledge in Computers #124
Difficulty: Easy
Generally speaking, Linux is only a Kernel, while Linux distributions are treated as an OS.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare file dates before copy

Sometimes when I boot, my system goes into emergency mode. I then use Clonezilla to restore an image. Usually the image is older than the current date. This is part of a backup script that runs as a startup program. cd /home/andy/bin/ zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py... (22 Replies)
Discussion started by: drew77
22 Replies

2. UNIX for Dummies Questions & Answers

Need to Move files of different dates

Hi, Currently I'm moving the files based on date like below. "mv *20150901* backup_folder" - Limitation: can move only 1 day files to backup folder. I want to move the files of different dates like 20150901,02, 03, 04..... Is there any single command to do it. Thanks in advance!! (2 Replies)
Discussion started by: prakashs1218
2 Replies

3. Shell Programming and Scripting

Deleting the files between particular dates

Hi Please help me for the below task. In my home directory if I run ls -l command, it lists all the files, here I want to delete files created from January 2014 to Aug 2014...but I need to keep the files which are created after September 01 2014. Thanks Siva (3 Replies)
Discussion started by: kumar85shiv
3 Replies

4. Shell Programming and Scripting

Files between two dates in UNIX

Hi Team, I need to connect to a prod server and need to get the files which falls between two dates. I should not create ant files on that machine. I am using korn shell. Your help is very much appreciated. Vinay (13 Replies)
Discussion started by: gvkumar25
13 Replies

5. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

6. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

7. UNIX for Dummies Questions & Answers

files between any two given dates

Can any one help me in getting all the files between any two given dates.. (8 Replies)
Discussion started by: thanuman
8 Replies

8. UNIX for Dummies Questions & Answers

Files and dates

Hello all. I am trying to do a file listing on a particular directory by date. I need to list the files and their directories that have a timestamp between Dec-1-2006 and Jan-1-2007. Any help would be greatly appreciated. (1 Reply)
Discussion started by: mastachef
1 Replies

9. UNIX for Dummies Questions & Answers

Copy only files created between two dates

Hi all, I like to get two date values from command line, and I have to copy all the files created in between that dates in a particular folder to destination folder. The date comparison is little bit consusing me. Please help. Regards Sethu. (2 Replies)
Discussion started by: r_sethu
2 Replies

10. UNIX for Dummies Questions & Answers

Remove files by dates

I've tried every way possible to remove files by date and nothing seems to work. Does anyone have an idea how to remove files by dates? Thanks in advance.... (1 Reply)
Discussion started by: dman110168
1 Replies

Featured Tech Videos