![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Remove logs by date | cvdev | SUN Solaris | 3 | 05-31-2008 03:09 AM |
| Sorting Files by date and moving files in date order | rebel64 | Shell Programming and Scripting | 2 | 03-11-2008 12:45 PM |
| Remove the date from the file | pradkumar | UNIX for Dummies Questions & Answers | 5 | 01-10-2008 01:36 AM |
| Remove out date logs | eric_wong_ch | Shell Programming and Scripting | 2 | 10-09-2007 11:52 AM |
| Remove files based on date | hshapiro | UNIX for Dummies Questions & Answers | 4 | 12-09-2005 12:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to remove files with a date
I have files with a date name ( 20060506 20060507 etc..) that i want to remove
because it keeps filling up the directory. Can someone please help me with a script to remove those date files. i would like to keep atleast 14 days worth from the current date. I hope i have explained it clearly and thanks ![]() |
|
||||
|
Quote:
Can you do it based upon modification time instead of filename? The below will remove all files in <dir> that have not been modified in the past 14 days. Code:
find <dir> -mtime +14 -exec rm -f {} \;
|
|
||||
|
Quote:
#! /bin/sh Today_Date=`date +%Y%m%d` log=`/usr/TRS/HULFT/movedata.log` mkdir /usr/TRS/backup/${Today_Date} mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} > ${log} find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -fr {} \; > ${log} |
|
||||
|
Quote:
The rest looks ok. I would change would be the redirects on your log files. If you want a new log file everyday, then you can rm the logfile at the beginning of your script. The find command will work. I changed the search path a little, but your version should work as well. Your script will probably leave a bunch of directories, /usr/TRS/backup/<date>, out there. I would include something to clean that up. See below for the changes. I hope this helps. Mike Code:
#! /bin/sh
Today_Date=`date +%Y%m%d`
log="/usr/TRS/HULFT/movedata.log"
#If you want a new log file on each run
rm -f ${log}
mkdir /usr/TRS/backup/${Today_Date}
mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} >> ${log} 2>> ${log}
find /usr/TRS/backup -name 'T*' -mtime +1 -exec rm -fr {} \; >> ${log} 2>> ${log}
|
|
||||
|
Quote:
Thanks for the help. I think this shld work well. Many Thanks again =) regards wee |
![]() |
| Bookmarks |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|