DeadnightWarrior
New Member
Hi all,
First of all I'm not a Linux expert so I apologize for not being too accurate or informed about CLI and such.
My company sells services that are commonly managed by physical or virtual machines running a customized CentOS 6 distro.
All of our software is Java based and installed under the /opt directory.
The sudo command is usually not active, so we tipically use "su" if we need root privileges, making sure we "exit" when the task is done.
Here's my issue:
Sometimes our programs tend to write a ton of logs in a specific directory, ending up in full disk spaces after some months.
We can't just wipe the entire directory clean, as we need to have at least the latest log for each type (you can have something like db_log, system_log, user_log, etc, all with their timestamp).
How could I write a script that deletes everything BUT the latest logs (or even everything except all files from less than 7 days ago, for example)?
It would be easy to write something like "rm -rf *" and schedule it to run once a day but it's not what I'm looking for.
Any help would be greatly appreciated.
Thank you!
First of all I'm not a Linux expert so I apologize for not being too accurate or informed about CLI and such.
My company sells services that are commonly managed by physical or virtual machines running a customized CentOS 6 distro.
All of our software is Java based and installed under the /opt directory.
The sudo command is usually not active, so we tipically use "su" if we need root privileges, making sure we "exit" when the task is done.
Here's my issue:
Sometimes our programs tend to write a ton of logs in a specific directory, ending up in full disk spaces after some months.
We can't just wipe the entire directory clean, as we need to have at least the latest log for each type (you can have something like db_log, system_log, user_log, etc, all with their timestamp).
How could I write a script that deletes everything BUT the latest logs (or even everything except all files from less than 7 days ago, for example)?
It would be easy to write something like "rm -rf *" and schedule it to run once a day but it's not what I'm looking for.
Any help would be greatly appreciated.
Thank you!