Move files from one date to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move files from one date to another
# 1  
Old 01-16-2015
Move files from one date to another

Hi

I have hundreds of files with the following format

Quote:
a_01152015.csv
b_01152015,csv
c_01152015,csv....
;;
;
;
I need to move this 1000 files from above to a different date
Quote:
a_01212015.csv
b_01212015.csv
c_01212015.csv

Is there a way to do that with a script or command
# 2  
Old 01-16-2015
Code:
for FILE in *.01152015.csv
do
        FILE2="${FILE/01152015/01212015}"
        echo mv "$FILE" "$FILE2"
done

Remove the 'echo' once you've tested that it does what you want.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-16-2015
Thank you corona688 for nice approach, one more approach with find command.
Code:
find -type f -name "*_01152015.csv" -exec bash -c 'echo mv $0 ${0/01152015/01212015}' {} \; 2>/dev/null

NOTE: We can remove echo if happy with results, also if needed remove 2>/dev/null which has been added to remove errors.

Thanks,
R. Singh
# 4  
Old 01-16-2015
Quote:
Originally Posted by RavinderSingh13
Thank you corona688 for nice approach, one more approach with find command.
You should warn the OP that find is recursive, it will search inside subfolders.

Also, running an entire shell for each individual file you want to move is not an efficient solution. You only need one shell:

Code:
find -type f -name '*_01152015.csv' | while read FILE
do
        FILE2="${FILE/01152015/01212015}"
        echo mv "$FILE" "$FILE2"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. UNIX for Dummies Questions & Answers

Move Multiple Files adding date timestamp before file type

There are files in a directory and I have to move multiple files adding datetimestamp before the file type. /Data/ abc.csv def.csv ghi.csv I have to move this files to archive directory adding datatimestamp before .csv /archive/ abc_YYYYMMDDHHMMSS.csv def_YYYYMMDDHHMMSS.csv... (7 Replies)
Discussion started by: eskay
7 Replies

4. Shell Programming and Scripting

Move log files with date and delete older than 3 weeks

I have written a script which generate one logfile on every sunday and thursday I want to move the older log files into /tmp directory befor generating new one so i used mv command like mv usr/sbin/appl/logfile.txt usr/sbin/appl/tmp 2) But when i move this file to /tmp it will... (1 Reply)
Discussion started by: Nakul_sh
1 Replies

5. Shell Programming and Scripting

Move all files except sys date (today) files in Solaris 10

I want to move all files from one directory to another directory excluding today (sysdate files) on daily basis. file name is in pattern file_2013031801, file_2013031802 etc (2 Replies)
Discussion started by: khattak
2 Replies

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

7. Emergency UNIX and Linux Support

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... (11 Replies)
Discussion started by: dsfreddie
11 Replies

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

9. Shell Programming and Scripting

Move files based on date in filename

I know this gets covered quite a bit in the forum and I think there is enough there for me to figure out how to do what I am trying to do, I just don't think I would do it very efficiently so I am going to ask the question... I have database log files with date and time stamps in the file like ... (7 Replies)
Discussion started by: slatoms
7 Replies

10. UNIX for Dummies Questions & Answers

Move A File With Same Date,don't Change The Desitination Dir Date

Assume, I created one file three years back and I like to move the file to some other directory with the old date (Creation date)? Is it possible? Explain? (1 Reply)
Discussion started by: jee.ku2
1 Replies
Login or Register to Ask a Question