Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete old files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm new to Unix so apologies for this simple question.

How can I delete files that are older than three days and end in .SPL


I'd like this as part of a series of commands. I've been through the manuals and can't find a simple answer.

 
This is the script (purgetmp.sh) that we use on all of our SCO systems.

You will need to modify the path of PURGELIST.


====================== START OF SCRIPT =====================

#!/bin/ksh
#
# purge - removes temporary files from the system
#
# this script looks at the file $PURGELIST, format is:
#
# directory_name pattern time [ #comment ]
#
# The value of 'pattern' determines which files are to be examined. If set to
# '*' all files in the specified directory will be examined.
#
# The value of time is used as an argument to the find command to indicate
# the age ( modify time ) of files to be removed.
#

SCCS="@(#) purgetmp Release No. : 1.1 : Date : 99/02/11 :''''";

trap '' 1 2 3 15

# Determine if SCO system

if [ -x /etc/sconf ] || [ -x /etc/scologin ]
then
SCOFLAG="Y"
PURGELIST=/star/conf/purgelist
else
SCOFLAG="N"
PURGELIST=/opt/bin/conf/purgelist
fi

TEMPFILE=/usr/tmp/`basename $0$$`

echo "`date` File Purge Started"

if [ ! -f $PURGELIST ]
then
echo "`basename $0`: WARNING: Configuration file $PURGELIST not set up"
exit 1
fi

sed 's/#.*$//g' $PURGELIST | while read DIR PATTERN MTIME # strip comment
do
if [ -d $DIR ]
then
FOUND=`find $DIR -name "$PATTERN" -type f -mtime +$MTIME -print | wc -l`

echo "Removing $FOUND files in $DIR\tmatching $PATTERN"
find $DIR -name "$PATTERN" -type f -mtime +$MTIME -print -exec rm -f {} \;
else
echo "Directory $DIR does not exist"
fi
done

rm -f $TEMPFILE
echo "`date` File Purge Completed"

=================== END OF SCRIPT ==========================


Hope you find this a help.


Regards


John


 
You can use the find command. There a a number of options you can put with find. You can find files based on the date last accessed, last modified, created. Look as the man pages for find for all the different options.


 
find /adirectory/*.SPL -mtime +3 -exec rm {} \;

You can also use -atime if you prefer to go by last accessed time than last modified time.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top