Quantcast
Channel: CodeProject Latest postings for Regular Expressions
Viewing all articles
Browse latest Browse all 224

RegEx- Find files in Linux which match the expression

$
0
0
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
|

Viewing all articles
Browse latest Browse all 224

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>