How to move files from a directory which falls between Date Range?

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support How to move files from a directory which falls between Date Range?
# 1  
Old 05-23-2012
How to move files from a directory which falls between Date Range?

Hi All,

I am trying to to move files from a directory to another which falls from Current day - 7 days. The files are in zipped format with dates appended on it.

Can you pls help me as this came as a immediate change before the production Release planned next week.

Pls let me know if you have any questions.

Thanks,
Freddie
# 2  
Old 05-23-2012
in what format the files have date. Also which OS and shell your are using
# 3  
Old 05-23-2012
do the dates reflect the file mtime? If so
Code:
touch -t 201205160000 /tmp/dummy
cd /old_directory
find . -type f -name '*zip*'  -newer  /tmp/dummy |
while read fname 
do
#test
  echo " $fname will become /new_directory/$fname
#real
#  mv $fname  /new_directory/$fname
done

See the #real part? run the code as is to verify if this is what you want. It is harmless. Do this FIRST.

If OK: Then edit the script and remove the # in front of the word mv
# 4  
Old 05-23-2012
Code:
find -type f '!' -mtime +7 /path/to/folder | while read FILE
do
        echo mv "$FILE" /path/to/dest/
done

Remove the 'echo' once you've tested to make sure it does what you want.
# 5  
Old 05-23-2012
Hi Shailesh,

The date is in 20120131 format. It is LINUX & ksh.

Thanks,
Freddie
# 6  
Old 05-23-2012
Could you show an entire filename for reference?
# 7  
Old 05-23-2012
you can use this:
Code:
d=$(date '+%Y%m%d')
i=6
while [ $i -ge 0 ]
 do 
 printf "mv filename_$(expr $d - $i) /move/path/\n"
 i=$(expr $i - 1)
done

replace printf with mv command if this code does get what you want.

Last edited by 47shailesh; 05-23-2012 at 05:17 PM.. Reason: added mv to printf
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

4. UNIX for Dummies Questions & Answers

Extracting rows from a text file if the value of a column falls between a certain range

Hi, I have a file that looks like the following: 10 100080417 rs7915867 ILMN_1343295 12 6243093 7747537 10 100190264 rs2296431 ILMN_1343295 12 6643093 6647537 10 100719451 SNP94374 ILMN_1343295 12 6688093 7599537 ... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Move files from one directory to another based on creation/modification date

Hi All, Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates. While visiting couple of posts, i could see we can... (3 Replies)
Discussion started by: dsfreddie
3 Replies

6. Shell Programming and Scripting

Script to move files to a directory according to date

hi all, here is the description to my problem. input parameter: $date1 based on the date i need to select three files starting with audit.log* based on its modified date, a date before, a date after(if its exists). We need to compare the input date to modified date of the file. And then... (3 Replies)
Discussion started by: ashrocks
3 Replies

7. Shell Programming and Scripting

Grep by range of date from file creation in directory

Hi Expert, Need your scripting and finding data so that it help me to find the culprit of this memory usage error. Data provided here is a sample. Process Snapshot directory: /var/spool/processes-snapshot webdev9o9% pwd /var/spool/processes-snapshot webdev9o9% ls -lrct -rw-r--r-- ... (3 Replies)
Discussion started by: regmaster
3 Replies

8. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

9. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies
Login or Register to Ask a Question