Wildcards
Wildcards
a character or string used for pattern matching
paths
* matches zero or more characters
ie:
*.txt =
ger.text apple.txt
telop.txt a.txt
yellw.txt atech.txt
testtxt all.txt
a*
la
lata
pla
placa
• Find all files that begin with foo:
find / -type f -name foo*
• Find all files that end with s:
find / -type f -name s
• Find all files that end with .bk:
find / -type f -name .bk
• Find all directories that end with .txt:
find / -type d -name .txt
• Find the files in /etc that end with deny:
find /etc -type f -name deny
? - matches exactly one character slot
. (. is a placement)
?.* (
???
*.??
Character Classes
Character class- matches any of the characters included between the brackets
[ ] - square brackets
matches any one of a list of comma-separated characters. A dash between two characters indicates a range to be matched.
For example:
m [a,o,u]m
results............mam, mum, mom
m[-d]m
results.............can be anything that stats and ends with 'm' and has any character 'a' to 'd' in between: mam, mbm, mcm, mdm
Examples:
• [root@yellowtail wildcards] # ls
a ab.txt b blues.mp3 c cot e g jazz.mp3
aa a.txt bb b.txt cat d f h songs.txt
• [root@yellowtail wildcards] # ls c[eioau] t
results... cat cot
• [root@yellowtail wildcards] # ls c[ueoai] t
results... cat cot
• [root@yellowtail wildcard] # ls [a-d]*
[a-d] is considered a range
results.... a aa ab.txt a.txt b bb blues.mp3 b.txt c cat cot d
• [root@yellowtail wildcard] # ls ??
results..... aa bb
• [root@yellowtail wildcard] # rm ??
results....... rm: remove regular empty file 'aa'? y
results....... rm: remove regular empty file 'bb'?y
a b c cat cot d e f g h
{ } brace expansion / making files
\ to recognize a character
ie: new\york = 'new york'
files: can candy cat catch cot cin cit
ls c[jghhakdh]t
ls c [aoi]n
ls c [ai]*
must start with c
must have a or i
cat catch cin cit
ls c[!a.i]t
look for anything with c
exclusion
not1!hing with a or i
includes t
What will this do?
*??.t*
What will this do?
ls f*[!111] 1?
-name (string of characters)
find /etc -f -name deny ( looking for files within the root that have any amount of characters with deny
find / -type f -name foo ( looking for files within the root of the system
-user )
Wildcards
a character or string used for pattern matching
paths
* matches zero or more characters
ie:
*.txt =
ger.text apple.txt
telop.txt a.txt
yellw.txt atech.txt
testtxt all.txt
a*
la
lata
pla
placa
• Find all files that begin with foo:
find / -type f -name foo*
• Find all files that end with s:
find / -type f -name s
• Find all files that end with .bk:
find / -type f -name .bk
• Find all directories that end with .txt:
find / -type d -name .txt
• Find the files in /etc that end with deny:
find /etc -type f -name deny
? - matches exactly one character slot
. (. is a placement)
?.* (
???
*.??
Character Classes
Character class- matches any of the characters included between the brackets
[ ] - square brackets
matches any one of a list of comma-separated characters. A dash between two characters indicates a range to be matched.
For example:
m [a,o,u]m
results............mam, mum, mom
m[-d]m
results.............can be anything that stats and ends with 'm' and has any character 'a' to 'd' in between: mam, mbm, mcm, mdm
Examples:
• [root@yellowtail wildcards] # ls
a ab.txt b blues.mp3 c cot e g jazz.mp3
aa a.txt bb b.txt cat d f h songs.txt
• [root@yellowtail wildcards] # ls c[eioau] t
results... cat cot
• [root@yellowtail wildcards] # ls c[ueoai] t
results... cat cot
• [root@yellowtail wildcard] # ls [a-d]*
[a-d] is considered a range
results.... a aa ab.txt a.txt b bb blues.mp3 b.txt c cat cot d
• [root@yellowtail wildcard] # ls ??
results..... aa bb
• [root@yellowtail wildcard] # rm ??
results....... rm: remove regular empty file 'aa'? y
results....... rm: remove regular empty file 'bb'?y
a b c cat cot d e f g h
{ } brace expansion / making files
\ to recognize a character
ie: new\york = 'new york'
files: can candy cat catch cot cin cit
ls c[jghhakdh]t
ls c [aoi]n
ls c [ai]*
must start with c
must have a or i
cat catch cin cit
ls c[!a.i]t
look for anything with c
exclusion
not1!hing with a or i
includes t
What will this do?
*??.t*
What will this do?
ls f*[!111] 1?
-name (string of characters)
find /etc -f -name deny ( looking for files within the root that have any amount of characters with deny
find / -type f -name foo ( looking for files within the root of the system
-user )