Help with script to copy/rename files, then delete by date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script to copy/rename files, then delete by date
# 1  
Old 03-28-2012
Help with script to copy/rename files, then delete by date

Hi All,

I am new to scripting and am looking for some assistance setting up a script. Basically I need the script to scan a folder for the newest files and make a copy of those files, adding a month to the date stamp. I also need this script to delete the previously copied files to save space.

The files I need to scan and copy have the format
Code:
FileX_Sat_8hr00-08.file

The copied files (which also need to be deleted) have the format
Code:
FileX_03-MAR-2012_Sat_8hr00-08.file

I've seen examples of what I'm trying to do, such as deleting any files a day older for instance. These examples haven't done exactly what I'm looking for though.

Any assistance would be appreciated.

Last edited by Scrutinizer; 04-05-2012 at 04:26 PM.. Reason: code tags
# 2  
Old 03-28-2012
What is the criteria used for identifying files from a particular time range...
# 3  
Old 03-29-2012
They will all have the date time stamp and extension in common. ex. Sat_8hr00-08.file

---------- Post updated 03-29-12 at 09:59 AM ---------- Previous update was 03-28-12 at 11:05 PM ----------

Could I use:

Code:
find . -mtime 1 -exec ls -d {} \; ‘ xargs ls -ltr



To find the files created the day before?

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-05-2012 at 04:25 PM..
# 4  
Old 04-05-2012
Anyone have any ideas?
# 5  
Old 04-05-2012
Code:
ls -l | awk '{ print $6 }'

- this command separates the month column from the ls -l output.
- you could always read that output in to some sort of selection scenario of if statements. i guess that is crude, but i am relatively new to this too. if you could separate month output into numbers you could use a sort command and a command that picks the end or beginning values of the output. look for tail or head, i believe as the commands.

Moderator's Comments:
Mod Comment Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-05-2012 at 04:24 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oop to copy and rename files through SQL Statement in shell Script

#!/bin/sh sqlplus -s "/ as sysdba" << EOF SET HEADING OFF SET FEEDBACK OFF Select pt.user_concurrent_program_name , OUTFILE_NAME FROm apps.fnd_concurrent_programs_tl pt, apps.fnd_concurrent_requests f where pt.concurrent_program_id = f.concurrent_program_id and pt.application_id =... (1 Reply)
Discussion started by: usman_oracle
1 Replies

2. Shell Programming and Scripting

Linux Script to copy and rename files through SQL statement

Hi, I require help to complete below requirement through Linux Script. I have a SQL query which shows two columns as output. One is Report Name and other is report path. Query return multiple rows. below is the output. Report Name Cotton Stock Report (Net Weight)- Customized Output... (3 Replies)
Discussion started by: usman_oracle
3 Replies

3. UNIX for Dummies Questions & Answers

Script to copy files from a certain date

I need to copy files from a directory that has a lot of files in it. However I only want to copy them from a certain date. My thoughts so far are to use ls -l and to pipe this into awk and print out tokens 6 (month)and 7 (day). $ ls -l -rw-r--r-- 1 prodqual tst 681883 Jun 12... (2 Replies)
Discussion started by: millsy5
2 Replies

4. Shell Programming and Scripting

Files rename and copy

hello, I am write a Script and i would listing all Files from Path1 out with DSR*.txt and give a new name an copy to the Path2. I have problems with that to rename. Someone can help me? Sorry, for my english. My english is not gut. I hope you understand my. That is my Script. ... (2 Replies)
Discussion started by: efeijoo
2 Replies

5. Shell Programming and Scripting

Copy files from folder and rename them

hello, I need to build a shell script that receives the folder to copy by parameter and copy all files except thumb.db to another folder and rename them like, file.jpg renamed to file_bb1.jpg. can someone help me Thanks (4 Replies)
Discussion started by: zeker
4 Replies

6. Shell Programming and Scripting

Script to copy log files with today's date

I am a newbie to scripting. I need a korn shell script to copy log files of current day to archive folder and rename with current days date stamp. I would really appreciate your help. File structure is as follows. Everyday files get overwritten, so I need copy to a archive directory and... (3 Replies)
Discussion started by: mdncan
3 Replies

7. Shell Programming and Scripting

Script required to copy and delete files

Hi All, I have written a script to ensure all my ARCHIVE files are backed up retaining the directory structure. The Script is-- #!/bin/sh # Script to take backup of DCS Folders # The file locations are /ftp/edi_ftp/edi_p/dcsftp/DCS/*/ARCHIVE DCSITIME=$(perl -e '($ss, $mm, $hh, $DD, $MM,... (3 Replies)
Discussion started by: srnagu
3 Replies

8. Shell Programming and Scripting

copy/rename file as date() unix/shell

File.jpg I want to copy and rename this as 2008-12-02.jpg I tried this copy File.jpg date '%y-%m-%d-%H:%M:%S'.jpg This doesnt work.... what do i do? (1 Reply)
Discussion started by: hdogg
1 Replies

9. UNIX for Dummies Questions & Answers

script to rename files with current date and copy it.

I have few webservers logs like access.log. which would be growing everyday. what i do everyday is, take the backup of access.log as access.log_(currentdate) and nullify the access.log. So thought of writing a script... but stuck up in middle. My requirement: to take the backup and nullify... (6 Replies)
Discussion started by: logic0
6 Replies
Login or Register to Ask a Question