moving files which have a datetime >= currentdate-N


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting moving files which have a datetime >= currentdate-N
# 1  
Old 10-22-2011
moving files which have a datetime >= currentdate-N

Hi ,

I want to move the files from a particular folder which have a datetime >= currentdate-N from a source to destination folder.

for ex today date is 22/10/2011 and the value of 'N' is 2 days then it should do the logic datetime >= currentdate-N that is 22/10/2011 - 2days so it will transfer all the files from 20/10/2011 to 22/10/2011(current date) to the output folder
# 2  
Old 10-22-2011
The "-mtime" option in "find" command is what you need.
# 3  
Old 10-22-2011
Quote:
Originally Posted by MacMonster
The "-mtime" option in "find" command is what you need.

Hi,

so if i have a properties file...shown below..
Code:
#############################################  #
Properties file for moving files 
 ############################################# 

 #This is the source directoy from where the files will be picked up
 SrcDirectory=/home/Administrator/files  

 #This directory path should end with a slash(/) 
DestDirectory=/home/Administrator/output/  

 #Configurable N days value is assumed here of 2 days
 Days=2

and there is my another main script file which is reading the parameters
from this properties file

Code:
awk -F = '/Days=/{days=$2}/SrcDirectory=/{src=$2}/DestDirectory=/{dest=$2}END{print days, src, dest}' archive.config  |while read DAYS INDIR OUTDIR do      find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \; done

Now when i run this main script file it transfers all the files from files
folder to output folder for example todays date is 22/10/2011 and I
want the files from 22/10/2011(current date) to 20/10/2011
(that is current date - 2 days) should be get moved to the output
folder,but this not happening,please guide me what should I do to make this
logic to be there..!! thanks in advance
# 4  
Old 10-22-2011
Your find command should rewrite to:

Code:
find $INDIR -type f -mtime -$DAYS -exec mv {} $OUTDIR \;

This User Gave Thanks to MacMonster For This Post:
# 5  
Old 10-22-2011
Quote:
Originally Posted by MacMonster
Your find command should rewrite to:

Code:
find $INDIR -type f -mtime -$DAYS -exec mv {} $OUTDIR \;


Hi MacMonster ,

Thanks a lot , for guiding the earlier as shown also I was using the find command ..

Code:
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;

so it was the
Code:
 "!"

before
Code:
 -mtime

option that was creating thre error, please expain..thanks in advance..!!Smilie
# 6  
Old 10-22-2011
Quote:
Originally Posted by rahul125
Hi MacMonster ,

Thanks a lot , for guiding the earlier as shown also I was using the find command ..

Code:
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;

so it was the
Code:
 "!"

before
Code:
 -mtime

option that was creating thre error, please expain..thanks in advance..!!Smilie
Without "-" or "+" in the "-mtime" option, it means EXTACT value. The "!" means NOT. Thus, the meaning of your original statement is to find any files which the last modified time are NOT EXACTLY two days ago.
This User Gave Thanks to MacMonster For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find files between two datetime..

Hi All, How do i find all the files between two times. Eg: 26 may 2014 06:00 to 26 may 2014 14:00 mmin and mtime gives for a specific period. we receive hundreds of files input directories and i need to find how many files are received between given specific datetime. Thanks. (2 Replies)
Discussion started by: abhi_123
2 Replies

2. AIX

Moving Hidden files to normal files

I have a bunch of hidden files in a directory in AIX. I would like to move these hidden files as regular files to another directory. Say i have the following files in directory /x .test~1234~567 .report~5678~123 .find~9876~576 i would like to move them to directory /y as test~1234~567... (10 Replies)
Discussion started by: umesh.narain
10 Replies

3. UNIX for Dummies Questions & Answers

Moving Files to VM

Hi guys, i need to test a script on my RedHat which it's mounted on a VirtualBox (oracle VM). So i need to copy a directory with subdirectories, from a remote host to my VM. I'd like to do that within cmd not with program like Filezilla or something like that. Any idea please? (4 Replies)
Discussion started by: Newer
4 Replies

4. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

5. UNIX for Dummies Questions & Answers

Moving Multiple files to destination files

I am running a code like this foreach list ($tmp) mv *_${list}.txt ${chart}_${list}.txt #mv: when moving multiple files, last argument must be a directory mv *_${list}.doc ${chart}_${list}.doc #mv: when moving multiple files, last argument must be a... (3 Replies)
Discussion started by: animesharma
3 Replies

6. Shell Programming and Scripting

moving the files in a.txt files to a different directory

HI All, I am coding a shell script which will pick all the .csv files in a particular directoryand write it in to a .txt file, this .txt file i will use as a source in datastage for processing. now after the processing is done I have to move and archive all the files in the .txt file to a... (5 Replies)
Discussion started by: subhasri_2020
5 Replies

7. UNIX for Dummies Questions & Answers

Moving files

Hi I need to be able to move files from one central locations to different servers on our network. So i want all of our operators to place files to one area on the main storage area. From there i need a script that first checks the file is stable (finished copying) then copy to another server,... (5 Replies)
Discussion started by: treds
5 Replies

8. Shell Programming and Scripting

Delete Files Based on Datetime Stamp

I have a Unix directory, let's call it /home/id for example purposes. It contains the following files: oldfile.txt.20091101, oldfile.txt.20091102, oldfile.txt.20091103, etc. I am trying to create a Korn Shell script that will go to /home/id and delete any oldfile.txt that has a datetime stamp... (1 Reply)
Discussion started by: ijmoore
1 Replies

9. Shell Programming and Scripting

Moving Files

Hi There, I am trying to move files, the file is present in this location: /iAm4Free/test/generate/txt/information.txt I need to move it to: /iAm4Free/test1/generate/txt/information.txt The only difference is the "test" is replaced with "test1". But the constraint is. The parent... (5 Replies)
Discussion started by: iAm4Free
5 Replies

10. UNIX for Dummies Questions & Answers

moving files ??

I am using AIX Version 5.1 If I moved a file say using this command but the directory rpt did not exist would this dump the file? I went back to the directory I was moving it from and the file was gone and when I looked in the directory I moved it to of course that directory was not found.... (9 Replies)
Discussion started by: rocker40
9 Replies
Login or Register to Ask a Question