Trying to delete files
Hi All,
Im not the most experienced scripter but I need to look for certain file types that are over a certain age and remove them. I found the following on a site but I keep getting errors. Any help would be great. Thanks and kind regards Danny The command in my script Code:
/usr/bin/rm `/usr/bin/find dbbackup -name '*.dmp' -mtime +10` Code:
usage: rm [-fiRr] file ... |
You can try the following syntax, using xargs
Code:
find dbbackup -name "*.dmp" -mtime +10 -print0 | xargs -0 echo rm |
RE: Trying to delete files
Hi Smurff,
I think that may be you can try rm to force delete (with '-f'). /bin/rm -f `/usr/bin/find dbbackup -name '*.dmp' -mtime +10` I think you get that message when find doesn't find any archive that meets the condition. By adding -f you may get rid of that message. Regards, Matías I just changed the paths to fit my system and try your command, but Quote:
|
I'm really new to this stuff, but are you sure you need the path in front of the 'rm?' Maybe there's just no rm within /usr/bin/?
And can you use quotes like that to pass the argument of the operation in all distros? |
Quote:
Quote:
To smurff: The trick is to first run the find command and be sure it does what you expect. Then you can incorporate it in a more complex structure. The error message implies that "rm" was given no arguements. |
Guys,
Thank you all so much for taking the time to answer. Colucix, thank you. Its good to know but that command did not seem to be on my solaris box. But thank you anyway. Matiasar, Thank you, the -f was the issue. Thank you very much. Techwatcher, I too am quite new, well I have been doing this for quite some time but I dont go out of my confort zone to often :) Pixellany, Thanks. I did take the line apart. Thats good advice. Code:
[smurff@nemo ~]$ ls dbbackup/ |
Why don't you use the built-in functionality of find? Something like
find dbbackup -name '*.dmp' -mtime +10 -exec rm {} \; (notice the blank between the closing bracket and the slash). |
Note that when you ran
find dbbackup/ -name '*.dmp' -mtime +10 you got no output; no files are old enough to match from the man page: TESTS Numeric arguments can be specified as +n for greater than n, -n for less than n, n for exactly n. Try ls -l on your files to check the last modified times. |
Quote:
If your question is Solaris specific, report it for it to be moved on the Solaris forum. If you are looking for a solution working on both Linux, Solaris and other systems, then ask for a move to the programming forum. |
All times are GMT -5. The time now is 02:54 PM. |