Delete all .log files and .bat files except the most recent?
I have a directory with multiple .log files and multiple .bat files.
1. I want to delete all .log files. 2 I want to delete all .bat files except the most recently created one. Any ideas on how i could do this? |
You haven't mentioned whether you need to do this on a repeated basis (script), so this assumes you don't. Also assumes you are in the directory containing the files.
1. rm *.log 2a. Code:
ls -latr *.bat 2c. Code:
for i in `find ./*.bat | grep -v "whatever bat file you want to keep"`; do rm $i; done |
Is this a homework question?
EDIT: Never mind, an answer has already been given. An alternative for the .bat files: Code:
echo rm "$( /bin/ls -1t *.bat | head -n-1 )"
|
Or there is always logrotate to manage log files
Code:
man logrotate |
All times are GMT -5. The time now is 05:39 AM. |