Hi. I want to remove all log files from the last 7 days from a folder, but leave all the other files. Can I use the below command? How do you specify that it just delete the files with .log extension?
find /path/to/file -mtime +7 -exec rm -f {} \;
Do I need to write this command into some file, or can I just write it in command prompt and have it run automatically every day?
I have no idea how to run a cron job in linux.
del *.log /a /s /q /f Step 1: Also run Command Prompt as administrator. Step 2: Type wevtutil el and press Enter to list all the logs. Step 3: TYpe wevtutil cl + the name of the log you want to delete and press Enter to remove the log file.
The safest method to empty a log file in Linux is by using the truncate command. Truncate command is used to shrink or extend the size of each FILE to the specified size. Where -s is used to set or adjust the file size by SIZE bytes.
Most versions of cron will log when jobs run and whether there are any errors with your crontab. They do not log cron job output or exit statuses.
Use wildcard. And just put it in your crontab
use the crontab -e
option to edit your crontab jobs.
See example:
* * * * * find /path/to/*.log -mtime +7 -exec rm -f {} \;
Just to increment the answer check this nice article on how to work with your crontab
! in Linux .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With