I’m learning about wildcards and I’m trying to figure out how to find filenames that contain a specific character, two or more times.
For example, finding filenames that have two or more x
‘s in them, such as Xerox.
I know how to find files that have an *x, or that have an *ox*, but I can’t figure out how I’d find a file named Xerox.
Any help is much appreciated.
Advertisement
Answer
For finding files that contain two or more x
‘s, you want to use a regular expression.
ls | egrep x.*x
is an example.
Take a look at this Regular Expression cheatsheet. This will work because you match a single x
, followed by 0 or more of any character (represented by .*
), followed by another x
.