Deleting Files Older than 24 hours

Hi,

I am using Solaris Box, I need to delete file(cookies.html) from the path(/usr/temp) which are older than 24 hours(I want in hours, not in days)

Can u provide the command for the above query

work with "find" have a look at the manpage and make the options fit your needs... what means "older than 24 hours"? created, modified or last accesed... you can check all of this with the "find" command!

hth,
DN2

Use zsh:

rm -- /usr/temp/**/cookies.html(mh+24)

--------------------------------------------------------------------
So my Final shell script should be this as below..Right??

find /usr/temp/**/cookies.html -type f -mtime (mh+24) -exec rm -f {} \;

can you confirm whether this script is correct, to delete the file older than 24 hours(not 1 day)

  1. With zsh you don't need to call find
    (note that "**" globs multiple "/", it's a recursive globbing)
    all that you need is:
rm -- /usr/temp/**/cookies.html(mh+24)

or, in this case, even just:

rm /usr/temp/**/cookies.html(mh+24)
  1. You can execute it first with ls -l,
    just to be sure that it generates the files you need to remove:
ls -l /usr/temp/**/cookies.html(mh+24)

If there are many files and you get the "argument list too long" error,
use this:

 autoload zargs ; zargs /usr/temp/**/cookies.html(mh+24) -- rm

----------------------------------------------------------------------
Since in future, we will be migrating to Unix Box, so then in that case, this command will work perfectly fine...right?

find /usr/temp/cookies.html -type f -cmin +1440 -exec rm -f {} \;

The above command will delete all the files (cookies.html) which are older than 24 hours (24*60mins = 1440) ...right ??

------------------------------------------------------------------------I am able to delete the files from the given path, where files are older than 24 hours.
But it is also going inside the directories of the path and deleting the files older than 24 hours.I want just the files to be deleted from that path, without going inside any directory of that path and deleting files from that directory too

find /tmp/test -type f -mtime +0 -exec rm {} \;

For example: if the test directory has one more directory "/test/test2" and files are there in the test2 directory, but if i issue the above command, it will go inside the test2 and delete files...

I dont want this command to go inside the directory and deleting files
Can you troubleshoot and pass the solution.

Hi mazhar803, I suggest reading the FAQs for the 'find' command.