Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Delete Files Older Than 2 Weeks
Name: JessicaJ Date: February 3, 2003 at 16:29:09 Pacific OS: HPUX CPU/Ram: unsure
Comment:
Hi,
I am trying to delete log files older than a certain date using a Korn shell script.
The best suggestion I've found (on this board) is to calculate the date of two weeks ago (very difficult) and then touch a file with that date specified as the -t option. Then I can use if [ file1 -ot file2 ].
I'm looking for any other sugggestions and/or ways to calculate the day two weeks ago (doesn't have to be exactly two weeks).
Name: JessicaJ Date: February 3, 2003 at 17:52:23 Pacific
Reply:
I found another option:
find -mtime
Could that be used?
0
Response Number 2
Name: Frank Date: February 4, 2003 at 01:59:05 Pacific
Reply:
Hi Jessica,
depends on what you mean by two weeks ago. If you mena two weeks ago from the current date than you can use find /Directory -mtime +14 -exec rm -f {} \;
to check if the files are the files you would like to delete use: find /Directory -mtime +14 -exec ls -l {} \;
If you would like to delete files 14 day older than a reference file you should use the touch and find . -newer solution.
Summary: Hi, I want to delete files which had been created 2 days ago having names like: er_n5412_output_yyyymmdd.csv.processd from the directory /opt/apps/ccba/dev/callftp/cps_adhoc. There will be several ot...
Summary: I am new to shell scripting. The requirement is as follows: At the beginning of the script, check file creation date. If it's more than 2 days old, rename the file with prefix "backlog". I would reall...
Summary: Hi, I have to move files older than 4 hours from a directory to another. How to find these file ? The find command with -mtime can't be applied because time is up than 24 hours. Thanks ...