Hi,

I am new to shell scripting.So someone please do help me out.I have stored two dates in the given format below.

cur_time=`date '+ %b%e%T'`

time=`ls -lu f1 | cut -d "" -f6`

I hope both these will show the dates in this format.
for eg. Dec 23 10:10

Now I want to compare the contents of variable time with that of cur_time and delete the file if time is 48 hours before cur_time.Please help me with the necessary shell script or if there is a better option please let me know.I want to write a function for this.This is how I started.

delete()
{
cd /home/julie/trash
cur_time=`date '+ %b%e%T'`
for i in `ls-lu`
do
time=`ls -lu $i| cut -d "" -f6`

Help me finish this function.

Regards,
Toms

find does date comparisons for you.
Example - this code deletes files older than 48 hours (2 days):

find /home/julie/trash -type f  -mtime +2 -exec rm -f {} \;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.