iterate over apache 2 log file names and compare numbers using linux bash

Viewed 99

Here is an example of logs in my /var/www/apache2/log folder-

./no_domain_access.log.7.gz
./no_domain_access.log.8.gz
./no_domain_access.log.9.gz
./no_domain_error.log.10.gz
./no_domain_error.log.11.gz
./no_domain_error.log.12.gz
./no_domain_error.log.13.gz
./no_domain_error.log.14.gz
./no_domain_error.log.15.gz
./no_domain_error.log.16.gz
./no_domain_error.log.17.gz
./no_domain_error.log.18.gz
./no_domain_error.log.19.gz
./no_domain_error.log.20.gz

and goes until 50...

I would like to iterate over those files and remove all log files that are greater then 5.

using regex syntax will give me the option to match numbers in the pattern of [1-9] or {1,2} but this will also match that log files that i dont want to delete ( single numbers 1-5 log files that i wish to keep)

How can i match only file names with numbers higher than 5 ?

Thanks!

4 Answers
Related