Need help with a shell script

i want to make a script that enter certain give directory each day , then remove all files to got max files of the last five day only

if today is 11 jan 2013 and i wanna check my directory ( /logs/Data/users ) for example when ls -lrt i find the oldest file by date 7 jan 2013 and all older dates is removed :confused:

thanks alot for yr help

What have you tried?

i cant adjust any one by date mine was to delete last 5 but iwanna make one by date

for sourcefile in `ls -lrt | awk 'NR>1 { print $NF } ' | head -5`
do
echo "Removing file: $sourcefile"; rm $sourcefile
done7

Have a read of the manual page for find and the section on -mtime

That might have what you need.

Robin

1 Like

Please look at this thread, posted some hours ago:
http://www.unix.com/shell-programming-scripting/215693-help-needed-delete-script.html\#post302768281

1 Like