Find files that end with number

filenamesfindpatternswildcards

Im trying to make some backup script as the log files get bigger and bigger. What i have is coping the current file, (for example secure file in /var/log/) and remove the content from that file. But there are some files with the name like: secure.1, secure.2 and all this i like to count them, and if the number is bigger then 2 to archive them all. I can't find the method to find this files or count them. The first think that come up to me was:

find /var/log/ -name *.1 | wc -l

and this will always print 1 as there is one file secure.1. How can i count like in for loop where i can specified a range of numbers like {1..5} or similar. Is there a way to separate this files and make them as one and them backup or delete or what ever … or first of all how can i find all this numbers that ends up with number.

Best Answer

With simple -name:

find /var/log -name '*.[2-9]'

or for any digit:

find /var/log -name '*.[[:digit:]]'

or if other chars are possible after digit:

find /var/log -name '*.[2-9]*'
Related Question