Reputation: 1871
We want to capture all logs that ended with ".log.[any number]
So I create this syntax
find . -type f -regex '\.log\.*[0-9]$' -print
command does not give any output
But this doesn't capture the files as the following ( expected results )
controller.log.2018-01-03-01
server.log.2017-10-31-03
server.log.2018-01-23-11
server.log.2018-04-06-17
server.log.2018-07-07-05
controller.log.2018-01-03-02
log-cleaner.log.10
server.log.2017-10-31-04
server.log.2018-01-23-12
server.log.2018-04-06-18
server.log.2018-07-07-06
controller.log.2018-01-03-03
log-cleaner.log.2
server.log.232.434
what is wrong with my syntax ?
Upvotes: 0
Views: 184
Reputation: 2091
From find
manpage:
-regex pattern
File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named
./fubar3
, you can use the regular expression.*bar.
or.*b.*3
, but notf.*r3
. The regular expressions understood by find are by default Emacs Regular Expressions, but this can be changed with the -regextype option.
So, you must match the whole path, in this case you could try with:
find . -type f -regex '.*\.log.*[0-9]$' -print
Upvotes: 1
Reputation: 133458
Could you please try following.(considering that your files are same format as shown samples)
find . -regextype posix-extended -regex ".*\.log.[0-9]{4}(-[0-9]{2}){3}"
Upvotes: 0