Copying specific files from one dir to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying specific files from one dir to another
# 1  
Old 03-17-2010
MySQL Copying specific files from one dir to another

Hi Folks,

I have one curious case. There are list of following files placed in one directory such as... And updated each month.

files.JAN09.csv files.FEB09.csv files.MAR09.csv .....

Now, I need to move a specific files; i.e,

For this month, I need to move only OCT09, NOV09, DEC09, JAN10;
For next month, I need to move only NOV09, DEC09, JAN10, FEB10;
And for next, DEC09, JAN10, MAR10, APR10;

Could any experts help me to code on Shell Script?

Thanks in advance.
# 2  
Old 03-17-2010
try (with GNU date)

Code:
dest_path=/some/path/to/archive
for month in 5 4 3 2
do
	file_date=$(date -d "$month month ago" +"%b%y" | tr '[a-z]' '[A-Z]')
	mv files.${file_date}.csv ${dest_path} 2>/dev/null && echo "files.${file_date}.csv has been moved"  || echo "file files.${file_date}.csv not found"
done


Last edited by clx; 03-18-2010 at 05:04 AM.. Reason: handled failed condn
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Copying files with a specific pattern

Hi All I am trying to copy files from one location to another and given below are some sample ones: aaa_bbb_ccc_ddd_cost_code_20140330.gz aaa_bbb_ccc_ddd_revenue_zone_20140329.gz aaa_bbb_ccc_ddd_benefit_extract_20140330.csv.gz aaa_bbb_ccc_ddd_profit_zone_20150509.csv.gz... (17 Replies)
Discussion started by: swasid
17 Replies

3. Shell Programming and Scripting

PERL - Copying ONLY files from one dir to another

I'm writing a Perl script which has its 1st step as to copy files from one directory to another directory. The Source directory has got files with extension, without extension, directories etc. But I want to copy ONLY files with no extension. The files with extensions and directories should not get... (2 Replies)
Discussion started by: jhamaks
2 Replies

4. Shell Programming and Scripting

Issue with copying files into dir inside for loop

Hi , I'm trying to move/copy the files inside the loop into a directory . I tried the below code and the issue is the data is not copying into the created directory but the files are copying into another file file_path="/home/etc" Last_Day=20130930 mkdir $file_path/ARC_${Last_Day} ... (3 Replies)
Discussion started by: smile689
3 Replies

5. Shell Programming and Scripting

Copying files to new dir structure.

I am trying to figure out a way to script copying specific files from one dir structure to another. I have a dir structure like this: dira/author 1/book 1/file a.epub /book 2/file b.epub /author 2/book 1/file c.epub /author 3/book 1/file d.epub /book 2/file... (2 Replies)
Discussion started by: arcanas
2 Replies

6. Shell Programming and Scripting

How to delete files in specific dir

I've got a problem how to delete files from specific directory. I don't want do it recursively but only in specific directory. So, command like find /home/dirname/ -mtime +8 -type f -exec rm {} \; is not for me because this command will remove ifs files in /home/dirname and all... (2 Replies)
Discussion started by: zukes
2 Replies

7. UNIX for Advanced & Expert Users

copying of files by userB, dir & files owned by userA

I am userB and have a dir /temp1 This dir is owned by me. How do I recursively copy files from another users's dir userA? I need to preserve the original user who created files, original group information, original create date, mod date etc. I tried cp -pr /home/userA/* . ... (2 Replies)
Discussion started by: Hangman2
2 Replies

8. Shell Programming and Scripting

copying files to new dir

Hello, I'm new to shell scripting so I don't really understand what I'm doing wrong. The script I'm trying to do saves all the files (*.c) on the current dir to a list and, one by one, copies them to a new one called Backup. The thing is, if there are already other versions of the files I'm... (6 Replies)
Discussion started by: G3nn
6 Replies

9. Shell Programming and Scripting

Copying specific files from remote m/c to specific folders

Hi All, I am trying to rsync some of the latest files from remote m/c to my local linux box. Folder structure in my remote m/c looks like this /pub/Nightly/Package/ROLL/WIN /pub/Nightly/Package/SOLL/sol /pub/Nightly/Package/SOLL/linux Each of the folder contains gzip files which on daily... (0 Replies)
Discussion started by: jhoomsharabi
0 Replies

10. UNIX for Dummies Questions & Answers

Copying specific files

I wanted to see if some one could confirm the proper command and format for copying specific files i.e., ones that contain certain character string in the file name. I would like to copy all files that contain a numeric sequence in the file name i.e., "922371". Files are compressed - *.gz. Would... (3 Replies)
Discussion started by: faaron3
3 Replies
Login or Register to Ask a Question