how to remove all files from a directory which are 24 hr old
hi
I was preparing a script which will remove all my files from directory which are 24 hour old. I tried some thing like this find . \( -name 'log.*' -mtime +1 \) -exec rm {}; but it is throughing error like : missing argument to exec. please help me in this regard. |
You're trying to delete files OVER 24 hours old?
find /path -name "log.*" -mtime -1 -type f -exec ls -lh {} \; Run that first to see the files incase the command is not what you're looking for. then run: find /path -name "log.*" -mtime -1 -type f -exec rm -f {} \; Change the / to your path. |
Thanks,
but the command find /path -name "log.*" -mtime -1 -type f -exec ls -lh {} \; is throwing some error saing that: missing arguments to -exec. I tried one more thing like find /sisback -name "log.1*" -type f -mtime -1 |xargs rm but it is showing that-- /sisback no such file or directory. though I have a directory in the same name in my present working directory. Need your help please... |
Quote:
Code:
find /path -name "log.*" -mtime -1 -type f -exec ls -lh '{}' \; |
Usually the error you gave means you didn't end the -exec command with `\;'.
You can also use the -delete command. find /dir -mtime +1 -delete The command with -exec ls could have been: find /dir -mtime +1 -ls |
It might also be worth looking at tmpwatch.
DESCRIPTION tmpwatch recursively removes files which haven't been accessed for a given number of hours. Normally, it's used to clean up directories which are used for temporary hold- ing space such as /tmp. |
Quote:
Code:
find /path -name "log.*" -mtime -1 -type f -exec ls -lh {} \; Code:
find /path -name "log.*" -mtime -1 -type f -exec ls -lh '{}' ';' |
What OS and what shell are you using? The examples I posted work for me on a CentOS OS using bash shell.
|
Thanks to all...
I am using Fedora-9 and bash shell... |
All times are GMT -5. The time now is 06:14 PM. |