Hi Frineds,
I want to delete a set of files which are older than 7 days from teh current date.I am totally enw to shell scripting, can anyone help me with a sample code to list out the files which are older and then remove them from the directory.
Please help
THanks
Viswa
find /path/to/files -type f -mtime +7 -exec rm -f {} \;
To be sure you are getting what you think, run this first to check:
find /path/to/files -type f -mtime +7 -exec ls -l {} \;
and read through the output carefully .
See if this works for you:
find . -type f -mtime +7 -exec rm -f {} \;
Thank You very much i never thought i would get such a quick response. It worked Thanks a Ton!!!
What to do if i have to restrict the search to the current directory alone ??
You can do :
find . \( ! -name . -prune \) -type f -mtime +7 -exec rm {} \;
or with GNU version of find :
find . -maxdepth 1 -type f -mtime +7 -exec rm {} \;
Jean-Pierre.