Hello,
I need a shell script to remove those files created 7 days ago.
Your response is appreciated.
Shang
I need a shell script to remove those files created 7 days ago.
Your response is appreciated.
Shang
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...
Sent via Deja.com http://www.deja.com/Quote:> Hello,
> I need a shell script to remove those files created 7 days ago.
> Your response is appreciated.
> Shang
>> 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
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
> >> 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
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.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
1. Delete files created 3 days ago
Does anyone give me some advice ?
I want to write a shell script as cronjob to
delete the files created 3 days before in a certain directory.
But I donot know how to select the files created 3 days ago .
Thanks !
2. HELP getting TERM + name services to work
3. deleting files created n days ago
4. ne2000 cards work on one network but not another
5. list all files modified at most n days ago
6. PMAG-F
7. List files modified 3 days ago
8. How to get rid of these entries on disk? (proper!!!)
9. Find Files that were created two hours ago
10. Q: Finding file created an hour ago.
11. caculate a date (how to find the date 7 days ago?)
12. How can I calculate how many days ago?
13. How Do I Get Date 7 Days Ago ?