How to remove those files created 7 days ago?

How to remove those files created 7 days ago?

Post by Shangwu Q » Thu, 09 Sep 1999 04:00:00



Hello,

I need a shell script to remove those files created 7 days ago.
Your response is appreciated.

Shang

 
 
 

How to remove those files created 7 days ago?

Post by hacke.. » Thu, 09 Sep 1999 04:00:00


cd into whatever dir you want to do this in and run something like...

find . -mtime 7 -exec rm -f {} \;

...be wary and test your script first. Make sure that it finds the files
you actually want to remove.  A safer way to do this for purposes of
testing is...

find . -mtime 7 -ok rm {} \;

which will interactively prompt you for actual removal of the file.  You
can substitute the "." for wahtever dir you wish to use the find command
in...example...

find /home/shang -mtime 7 -exec rm -f {} \;

Cheers...



Quote:> Hello,

> I need a shell script to remove those files created 7 days ago.
> Your response is appreciated.

> Shang

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

How to remove those files created 7 days ago?

Post by Christopher J. Matter » Fri, 10 Sep 1999 04:00:00




>> Hello,

>> I need a shell script to remove those files created 7 days ago.
>> Your response is appreciated.

>> Shang
> #/bin/ksh
> for i in `find . -mtime 7 -print`;do
>     if [[ -w "${i}" ]];then
>         print -u1 "Deleting ${i}
>         rm -f ${i} 2>/dev/null;
>     fi
> done
> exit 0;
> If what you really meant is that you want to delete file that are
> greater than six days old then change the 7 to +6

Nope.  That will delete files that were *last changed* seven days
ago (or last changed more than six days ago).

There is no way to do what he asked.  You cannot manipulate
files in Unix based on their creation date because "creation
date" (however you want to define that) is not recorded anywhere.

                            Chris Mattern

 
 
 

How to remove those files created 7 days ago?

Post by Kenneth C Stah » Fri, 10 Sep 1999 04:00:00





> >> Hello,

> >> I need a shell script to remove those files created 7 days ago.
> >> Your response is appreciated.

> >> Shang

> > #/bin/ksh
> > for i in `find . -mtime 7 -print`;do
> >     if [[ -w "${i}" ]];then
> >         print -u1 "Deleting ${i}
> >         rm -f ${i} 2>/dev/null;
> >     fi
> > done
> > exit 0;

> > If what you really meant is that you want to delete file that are
> > greater than six days old then change the 7 to +6

> Nope.  That will delete files that were *last changed* seven days
> ago (or last changed more than six days ago).

> There is no way to do what he asked.  You cannot manipulate
> files in Unix based on their creation date because "creation
> date" (however you want to define that) is not recorded anywhere.

>                             Chris Mattern

In common parlance there are a great many unix users who interchangeably
swap the terms "modification" and "creation" dates. Yes, there really
truely is a distinction, but the distinction is irrelevant in many case.
If you think about it, files that are generated as the result of some
process running are generally static and even though they have the write
permission set, they are never modified subsequent to creation. As a
result, at least on a logical level, the creation date is synonymous
with the modification date that recorded. Therefore, for most general
purposes my suggestion will work even though it lacks precision and
isn't an exact match for the problem as defined - however, I'm going to
bet that the original person who posted the question will find that my
solution is "good enough" and will accomplish the task.

And to the original poster - if you really truely need something that is
more precise then your application would have to write a seperate file
that contains information which you can then read in, parse, and make a
programmatic choice regarding which files to delete. The overhead is
enormous, but if you really need exacting precision then it is probably
the only way you can accomplish what you want.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-