First of all, A wildcard is a generic term referring to something that
can be substituted for all possibilities. For a GNU/Linux system there
are two different major ways that wildcards are used,
- Globbing patterns/Standard wildcards (Commonly Used)
- Regular Expressions (More Powerful)
Shell file name Globbing(Standard Wildcard) and regular expressions use some of the same characters, and they have similar purposes, but they aren't compatible.
Let's get deeper,
Let's get deeper,
- File name expansion predates regular expressions
- Regexes are slower than standard wildcards
- While *.txt is easily understandable by casual users, the equivalent .*\.txt$ is something more targeted to experienced users. Here .txt is used in globbing while .*\.txt is used in regex.
- In Perl regular expressions, the period (‘.’)character refers to any single character. It is similar to the question mark(‘?’)character in wildcard pattern matching.As a result: example.com not only matches example.com but also matches exampleacom, examplebcom, exampleccom and so on.
There is a rough similarity between file globbing syntax and regexes, but if you need regex matching of file names, you need to do it another way. Take the find command for example.
find -regex is one option. (Notice that there is also find -name, by the way, which uses glob syntax.)
0 comments:
Post a Comment