RegEx- Find files in Linux which match the expression
-
This is for my VMware vCenter servers where I am trying to clean out extra log files which are no longer required. The type of files for this example are:
Quote:
/storage/log/vmware/eam/web/localhost_access_log..2020-12-06.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-13.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-31.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-13.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-03.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-08.txt /storage/log/vmware/eam/web/localhost_access_log..2020-07-21.txt /storage/log/vmware/eam/web/localhost_access_log..2020-08-03.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-30.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-08.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-27.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-14.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-28.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-01.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-29.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-19.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-05.txt
The expression which works for me in my Linux file system is this one:
find /storage/log/vmware/ -mtime +10 -type f -name "localhost_access_log..2020-[0-9][0-9]-[0-9][0-9].txt"
It uses the Linux "find" command to find the files, the files have to be "mtime=10" 10 days or older. I would like to shorten the regex to simplify it, and using RegExr: Learn, Build, & Test RegEx[^] as my tester, I found that the following regex works:
localhost_access_log\.\.2020-[0-9]{2}-[0-9]{2}\.txt
However when I try it on my Linux filesystem, it fails to produce results. I get nothing returned.
| +-- JDMils | +-- VB6 +-- VB Dot Net |
-
This is for my VMware vCenter servers where I am trying to clean out extra log files which are no longer required. The type of files for this example are:
Quote:
/storage/log/vmware/eam/web/localhost_access_log..2020-12-06.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-13.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-31.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-13.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-03.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-08.txt /storage/log/vmware/eam/web/localhost_access_log..2020-07-21.txt /storage/log/vmware/eam/web/localhost_access_log..2020-08-03.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-30.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-08.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-27.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-14.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-28.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-01.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-29.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-19.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-05.txt
The expression which works for me in my Linux file system is this one:
find /storage/log/vmware/ -mtime +10 -type f -name "localhost_access_log..2020-[0-9][0-9]-[0-9][0-9].txt"
It uses the Linux "find" command to find the files, the files have to be "mtime=10" 10 days or older. I would like to shorten the regex to simplify it, and using RegExr: Learn, Build, & Test RegEx[^] as my tester, I found that the following regex works:
localhost_access_log\.\.2020-[0-9]{2}-[0-9]{2}\.txt
However when I try it on my Linux filesystem, it fails to produce results. I get nothing returned.
| +-- JDMils | +-- VB6 +-- VB Dot Net |
-
This is for my VMware vCenter servers where I am trying to clean out extra log files which are no longer required. The type of files for this example are:
Quote:
/storage/log/vmware/eam/web/localhost_access_log..2020-12-06.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-13.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-31.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-13.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-03.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-08.txt /storage/log/vmware/eam/web/localhost_access_log..2020-07-21.txt /storage/log/vmware/eam/web/localhost_access_log..2020-08-03.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-30.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-08.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-27.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-14.txt /storage/log/vmware/eam/web/localhost_access_log..2020-09-28.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-01.txt /storage/log/vmware/eam/web/localhost_access_log..2020-11-29.txt /storage/log/vmware/eam/web/localhost_access_log..2020-10-19.txt /storage/log/vmware/eam/web/localhost_access_log..2020-12-05.txt
The expression which works for me in my Linux file system is this one:
find /storage/log/vmware/ -mtime +10 -type f -name "localhost_access_log..2020-[0-9][0-9]-[0-9][0-9].txt"
It uses the Linux "find" command to find the files, the files have to be "mtime=10" 10 days or older. I would like to shorten the regex to simplify it, and using RegExr: Learn, Build, & Test RegEx[^] as my tester, I found that the following regex works:
localhost_access_log\.\.2020-[0-9]{2}-[0-9]{2}\.txt
However when I try it on my Linux filesystem, it fails to produce results. I get nothing returned.
| +-- JDMils | +-- VB6 +-- VB Dot Net |
Unless told otherwise, find uses file globs, I think. But you can change the regex engine using -regextype. e.g. -regextype posix-extended. find will tell you what regex engines it knows about if you say -regex help. Possibly one of the engines knows how to parse your regex expression to your liking.
Keep Calm and Carry On
-
Unless told otherwise, find uses file globs, I think. But you can change the regex engine using -regextype. e.g. -regextype posix-extended. find will tell you what regex engines it knows about if you say -regex help. Possibly one of the engines knows how to parse your regex expression to your liking.
Keep Calm and Carry On
Thanks K5054, that was the clincher. To find the files I need, I had to perform the following: * State the Regex Engine as 'posix-extended' * Put the expression '.*' at the start of the filename as the files are treated as fully qualified filenames (file path & filename). Thus, I can now use the following:
find /storage/log/vmware/ -type f -regextype posix-extended -regex '.*vpxd-svcs-access-.2022-[0-9]{2}-[0-9]{2}.log.gz'
And....
find /storage/log/vmware/ -type f -regextype posix-extended -regex '.*sps.log.[0-9]{2}.gz'
| +-- JDMils | +-- VB6 +-- VB Dot Net |