Wildcards Flashcards
What is a wildcard?
a character or string used for pattern matching
What is globbing?
The expansion of wildcards patterns into a list of files or directories
*-
A wildcard for trying to match one or more characters
?
a wildcard for matching exactly one charater
[]
Matches exactly one character in the brackets []
eg:
ca[nt]
-cat (yes)
-can (yes)
-candy (yes)
-catch (yes)
-cap (no)
[!]
Match any one thing in the bracket that is NOT in a file
[a-g]*
Match all the characters that are in the range
[[:alpha:]]
Matches alphabetical characters (lower and upper)
[[:alnum:]]
letters and decimal digits
[[:digit:]]
0-9
[[:lower:]]
lowercase letters
[[:space:]]
Whitespace (tabs, newline, space)
[[:upper:]]
uppercase letters
How do you match wildcard characters?
Use an \
ls *.txt
Lists everything with .txt
ls ??
lists all files that are 2 characters long
ls a?.txt vs ls a*.txt
One will just ab.txt, the other will list a.txt and ab.txt
ls c[aeiou]t
cat and cot
ls [a-d]*
lists anything that has at least 1 or more instances of that pattern a-d
stdout
Standard output or 1
stderr
Standard error or 2
stdin
Standard input or 0
>
redirects output to a file and overwrites w/e was there
> >
redirects output to a file and appends to what was there
<
redirects input to a command
&
redirects to a file descriptor instead of name
2>&1
combines stderr and stdout
2>file
redirect a standard error to a file
ls -l»_space; files.txt
appends the listed output to files.txt