Copy files based on modification date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy files based on modification date
# 8  
Old 06-03-2009
Thanks for all the reply.Smilie Not sure why my message was not publish yesterday.Smilie

Anyway, how to check if YYMM directory is exist and if not, to create before copy files according to the directory?

Once again, appreciate all your help.
# 9  
Old 06-04-2009
Quote:
Originally Posted by KhawHL
... how to check if YYMM directory is exist and if not, to create before copy files ...
Code:
[ ! -d <directory> ] && mkdir <directory>

tyler_durden
# 10  
Old 06-15-2009
Tried on following command:
cp -p `ls -l|awk '$6 ~ /Jun/{print $9}'` path/0906 --> OK.

# cp -p `ls -l *.* | awk '$6 ~ /$mon/{print $9}'` 0906
awk: syntax error near line 1
awk: bailing out near line 1
cp: Insufficient arguments (1)
Usage: cp [-f] [-i] [-p] f1 f2
cp [-f] [-i] [-p] f1 ... fn d1
cp -r|R [-f] [-i] [-p] d1 ... dn-1 dn

How can I use variable in this command?

Please advise.
Thank you.
# 11  
Old 06-15-2009
check this option

Code:
awk -v

# 12  
Old 06-15-2009
cp -p `ls -l *.* | awk '$6 ~ /$mon/{print $9}'` 0906

cp -p `ls -l *.* | awk -v '$6 ~ /$mon/{print $9}'` 0906 -- same error, where should I use the -v?
# 13  
Old 06-15-2009
I hope that you will read about the option first and then try, but you did not. Something like this ?..

Code:
cp -p `ls -l *.* | awk -v mon="Jun"  '$6 ~ /mon/ {print $9}'`

# 14  
Old 06-15-2009
Hi,

Thanks for the response. Tried as below.

# cp -p `ls -l *.* | awk -v mon="Jun" '$6 ~ /mon/ {print $9}'` 0906
awk: syntax error near line 1
awk: bailing out near line 1
cp: Insufficient arguments (1)
Usage: cp [-f] [-i] [-p] f1 f2
cp [-f] [-i] [-p] f1 ... fn d1
cp -r|R [-f] [-i] [-p] d1 ... dn-1 dn

I need to use variable instead of hardcode the month, appreciate someone can guide me on this. Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort and move multiple files by modification date

Hi I have a problem, I have a large group of archive files in a folder some are later versions of the same archive, the only difference btween them is that the archiving program we use appends the name with a code for it to keep track of in its data base, and the modification date. I am starting... (6 Replies)
Discussion started by: Paul Walker
6 Replies

2. UNIX for Dummies Questions & Answers

Copy log based on from-date and to-date

Hi all, i go a customer support requirement where i need to scan several files based on from/to date like 1-oct to 2-oct please help... (3 Replies)
Discussion started by: AbhiJ
3 Replies

3. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

4. 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

5. Shell Programming and Scripting

Copy files based on last created date

Hi, I have a requirement to copy files from a windows network drive to a Linux server using shell script based on the last created date. Ex: FileName CreatedDate/Time F1 05-01-2012 3:00 PM F2 05-01-2012 3:15 PM F3 05-01-2012 2:00 PM When i run the shell script... (1 Reply)
Discussion started by: Lee_10
1 Replies

6. Shell Programming and Scripting

How to list the files based on the modification time using the find command?

Hi All, I need to list the files based modification time of the files from a directory, I cannot use "ls -t" as there are lot of files, which "ls" command cannot handle. New files will land there daily. So iam looking for an alternative through "find"command. All suggestions are welcomed. ... (6 Replies)
Discussion started by: Kesavan
6 Replies

7. Shell Programming and Scripting

Rename old files with last modification date

Hi everyone, I have files like file1_Mod.txt, file2_Mod.txt. I want to rename the old files with the last modification date. I write the below script to rename with current date, but I donīt know how to use "date -r" to get the last modification date with the same format I have below... (5 Replies)
Discussion started by: cgkmal
5 Replies

8. Shell Programming and Scripting

Copy files based on date

Hi all i am having so many files in my directory.Is there any option to copy files based on date. example i am having file this -rw-rw-r-- 1 ram user 1 Feb 2 17:12 abc -rw-rw-r-- 1 ram user 1 Feb 2 17:12 bnw -rwxrwxr-x 1 ram user 21122 Feb 4... (3 Replies)
Discussion started by: suryanarayana
3 Replies

9. UNIX for Advanced & Expert Users

Help with sorting files according to modification date

Hi, I was very surprised to not be able to find an answer to this question despite my best efforts in Google and elsewhere. Maybe it's a good thing as it forced me to finally become a member in this great forum that i use frequently. Ok my question: I want to be able to sort files inside a... (3 Replies)
Discussion started by: stavros
3 Replies

10. Shell Programming and Scripting

List the file or files with last modification date

hi. I need help my programing friends :p I need to list all the files with a certain name (for example FileName) by last modification date but only the one with the last date. If there are two files with the same name and same modification date it should print the both. For example in this set... (6 Replies)
Discussion started by: KitFisto
6 Replies
Login or Register to Ask a Question