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?
# 8  
Old 05-24-2012
Code:
#!/bin/bash

DAYSBACK=7
WORKINGDIR="/tmp"
TARGETDIR="/tmp/mvd"
ACTION="cp"     # change this to mv 

for day in `seq 1 ${DAYSBACK}`
do
        ${ACTION} ${WORKINGDIR}/`date -d "${day} days ago" +%Y%m%d`.zip ${TARGETDIR}
done

# 9  
Old 05-26-2012
Code:
dir=/aas/home/testdir1/final
for fname in `find . -name "*.zip" -mtime -7`
do
mv $fname $dir
done

# 10  
Old 05-26-2012
The only problem i see with using find is that it relies on the fact that the files have correct modification time.

@dsfreddie - will the files always have correct metadata? Modified time etc?
# 11  
Old 06-06-2012
Hi Shailesh,

Thanks for your inputs.

Pls find below what I have tried so far,

Quote:
export BUS_DATE=`cat path/parameterfilename.txt | grep 'P_BUS_DATE' | cut -d"=" -f2`
CURR_DY=`date "+%Y%m%d"`
CURR_DY_SECS=`date --date=$CURR_DY +"%s"`
BUS_DATE_SECS=`date --date=$BUS_DATE +"%s"`
#DAYS = $((($CURR_DY_SECS - $BUS_DATE_SECS) / 86400 ))
DAYS=$((($CURR_DY_SECS - $BUS_DATE_SECS) / 86400 ))
i=$DAYS
while [[ $i -ge 0 ]]
do
# mv /path/filename.$(expr $CURR_DY - $i).dat /iis_dev_data/wcc/cpmg/ctl/
# mv /path/filename.$(expr $CURR_DY -d "$i day" "+%Y%m%d").dat /destination/
# mv /path/filename.$($CURR_DY -d "-$i day" "+%Y%m%d").dat /destination/
# mv /path/filename.$[$CURR_DY -d "-$i day" "+%Y%m%d"].dat /destination/
mv /path/filename.$(expr $CURR_DY -d "-$i day" "+%Y%m%d").dat /destination/
#i=$ [ expr $i - 1 ]
i=$(($i - 1))
done
However, it is giving errors like below,

Quote:
++ expr 20120606 -d '-9 day' +%Y%m%d
expr: syntax error
+ mv /iis_dev_data3/wcc/cpmg/tmp/filename..dat /iis_dev_data/wcc/cpmg/ctl/
mv: cannot stat `/iis_dev_data3/wcc/cpmg/tmp/filename..dat': No such file or directory
+ i=8
+ [[ 8 -ge 0 ]]
++ expr 20120606 -d '-8 day' +%Y%m%d
expr: syntax error
+ mv /iis_dev_data3/wcc/cpmg/tmp/filename..dat /iis_dev_data/wcc/cpmg/ctl/
mv: cannot stat `/iis_dev_data3/wcc/cpmg/tmp/filename..dat': No such file or directory
Can you pls help
Thanks,

Freddie
# 12  
Old 06-08-2012
Thanks All for the inputs.

The code below worked for me Smilie

Quote:
#!/bin/bash

DAYSBACK=7
WORKINGDIR="/tmp"
TARGETDIR="/tmp/mvd"
ACTION="cp" # change this to mv

for day in `seq 1 ${DAYSBACK}`
do
${ACTION} ${WORKINGDIR}/`date -d "${day} days ago" +%Y%m%d`.zip ${TARGETDIR}
done
Thanks
Freddie
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