0

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

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by jim mcnamara
0

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 {} \;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.