Delete Files Based on Datetime Stamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete Files Based on Datetime Stamp
# 1  
Old 12-01-2009
Question Delete Files Based on Datetime Stamp

I have a Unix directory, let's call it /home/id for example purposes. It contains the following files: oldfile.txt.20091101, oldfile.txt.20091102, oldfile.txt.20091103, etc.

I am trying to create a Korn Shell script that will go to /home/id and delete any oldfile.txt that has a datetime stamp that is older than 14 days from the current date.

I am not sure of the best way to accomplish this. Any suggestions?
# 2  
Old 12-01-2009
Code:
find /home/id -name "oldfile.txt.*" -mtime +14 -exec rm {} \;

find only works on multiples of x*24 hours (where x = days) so a file less than 14 days old, say 13 days 23 hours 59 minutes and 59 seconds at the time of your find command will not be deleted.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search Files on a given path based on latest time stamp

find /app/data -name "Availability" - Below is the output now i need to filter based on latest modified timestamp. I know 3 is the latest modified time stamp but i tried different options but only filtering docs and not on headnote..Can any one tell me how to do that.. ... (2 Replies)
Discussion started by: vkiyv05
2 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. Shell Programming and Scripting

Delete specific lines from files based on another file

I have some text files in a folder named ff as follows. I need to delete the lines (in-place editing)in these files based on another file aa.txt. 32bm.txt: 249 253 A P - 0 0 8 0, 0.0 6,-1.4 0, 0.0 2,-0.4 -0.287 25.6-102.0 -74.4 161.1 37.1 13.3 10.9 250... (2 Replies)
Discussion started by: aden
2 Replies

4. Shell Programming and Scripting

How to add a datetime stamp at a particular position in a filename?

hi, i have some files in a directory say abc.txt def.txt ghi.txt i am storing these file names in a temp file. ls -l | grep "^-" | awk '{print $NF}' > temp_file$$ i want to add a date time stamp at a particular place in the file names. it can be 1) before the extension... (2 Replies)
Discussion started by: Little
2 Replies

5. Shell Programming and Scripting

Delete all except latest datetime entery folder

Hello Expert, I have a strange requirement, I have folder where weekly backup are taken... week1_bkup_02102011 week2_bkup_09102011 week3_bkup_16102011 . . everyweek a backup is created I want to delete all folder except latest one for example in above a week4_bkup_23102011 is added... (3 Replies)
Discussion started by: aks_1902
3 Replies

6. Shell Programming and Scripting

Delete Files based on size

Hello Community! Im newbie on shell programming and its my first post. Im trying to make a bash shell script that it removes files of subdirectory. it is called : rms -{g|l|b} size1 dir -g means : remove file or files in dir that is above size1 -l means: remove file or files in dir that... (1 Reply)
Discussion started by: BTKBaaMMM
1 Replies

7. Shell Programming and Scripting

Identify log files based on time stamp,zip and then copy..HELP

Hi All, PFB is a requirement. I am new to shell scripting. So plz help. It would be highly appreciated. 1. choose all the log files based on a particular date (files location is '/test/domain')--i.e,we should choose all the files that are modified on 29th November, neither 28th nor 30th 2.... (3 Replies)
Discussion started by: skdas_niladri
3 Replies

8. Shell Programming and Scripting

PERL - Selecting specific files based on 'date stamp' values

Hi, I've list of files in a directory, which have date stamp value in their names. ex: abc_data_20071102.csv, abc_data_20091221.csv, abc_data_20100110.csv, abc_data_20100222.csv, abc_data_20080620.csv,... etc., I need to select and process only files, within the given date... (4 Replies)
Discussion started by: ganapati
4 Replies

9. UNIX for Dummies Questions & Answers

How to search for files based on the time stamp

Hi All, I know the timestamp of a file. Now i would like to list all the files in the with the same time stamp in the same file. Any help would be appreciated. Thanks. sunny (1 Reply)
Discussion started by: sunny_03
1 Replies

10. UNIX for Dummies Questions & Answers

Need to delete the files based on the time stamp of the file

Hi Everyone, I want to delete some files in a path based on the time stamp of the file that is i want to delete the file once in a month. Can any one help me on this? Thanks in advance (2 Replies)
Discussion started by: samudha
2 Replies
Login or Register to Ask a Question