Saturday, 24 August 2019

Linux wildcards and patterns

Wildcards and patterns are used in any of the file manipulation commands (cp, mv and so on)

Windcards

* - matches zero or more characters an file names
? - matches exactly one character in file names

Patterns

[pattern] - Matches exactly one character in the pattern.

Examples

ca[ls]
Any of those file names will match:
cal
cas

ca[ls]*
Any of those file names will match:
cal
cas
calls.txt
casts

Ranges

[g-f] - matches any files that starts with g,e,f
[2-5] - matches any files that starts with 2,3,4,5

Named classes

[[:alpha:]] - matches alphabetic letters in any case
[[:alphanum:]] - matches alphanumeric characters
[[:digit:]] - matches any digits from 0 to 9
[[:lower::]] - lowercase
[:upper:]] - uppercase
[[:space:]] - spaces, tabs and new line characters


No comments: