Regex for find command to match files with a non-empty file extension -


i have series of files want clean .log files have been rotated. examples:

error.log access.log error.log-2016-02-05 access.log.1 debug.log debug.log--2 

regex matching of log files with:

find . -regextype posix-extended -regex '^.*.log.*' 

how can match files have characters after *.log?

replace last occurrence of .* .+.

  • * matches 0 or more instances of previous character.
  • + matches 1 or more instances.

you need escape . before log \, otherwise match character rather literal period.

in summary, use this:

find . -regextype posix-extended -regex '^.*\.log.+' 

a few other adjustments might useful:

  • you don't want match files empty filenames, should switch first .* .+ (thanks, jan!).

  • you don't want allow files file extension .log. (a single . character after .*log), should switch final .+ \..+.

this give final command:

find . -regextype posix-extended -regex '^.+\.log\..+' 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -