- [Narrator] In addition to standard globs,
bash allows us to use extended globs.
This is an option that may be turned off
in your version of Linux .
Check to see if it's turned on,
type in a terminal, shopt and hit enter.
Look through the list and find extglob
and ensure that's turned on.
If it is not turned on you'll need to type in
shopt -s extglob and hit enter.
To make this persistent, you'll need to
put it in your bash or C startup file.
Extended globs give us more pattern matching power.
They grant us the power to specify
the number of occurrences to match,
which is difficult to do with standard globs.
They also allow grouping matches.
Patterns can be more than one character.
If we want to match three occurrences of ABC, we could.
They also allow us to match one pattern or another.
With extending globbing we can specify
zero or one occurrences of a match.
For instance, if we want to match zero or one occurrence
of the letters ABC, we'd use file?(abc).txt for our pattern.
To match one or more occurrence
use + before the parentheses.
This would be similar to a set or a ? in a standard glob,
but we have more power here as we can match whole words.
For instance, the pattern file+(abc).txt
would match fileabc.txt, which would be one occurrence
of the match, as well as fileabcabc.txt,
which would be multiple occurrences.
We can also match one thing or another using a |.
For instance, to match files that end in .jpg or .gif,
we could use +(*.jpg|*.gif).
You can do the same thing with standard globbing,
but it gets a bit long winded.
To match zero or more occurrences
we'll want to use an *.
This is a commination of ?, which is zero or one
occurrences and the +, which is one or more occurrences.
If we used a pattern of photo*(abc).jpg
it would match photo.jpg, which is zero occurrences
of the match, photoabc.jpg, which would be one occurrence,
photoabcabc.jpg, which would be
multiple occurrences of the pattern.
We can also invert our match
by using the ! before the parentheses.
!(*.jpg|*.gif) would match file.txt, fileabc.txt
and any other file that did not end with .jpg or .gif.
One more thing we can do
with extended globbing is group patterns.
This is a long pattern, so stay with me.
!(+(photo|file)*+(.jpg|.gif))
What we've done here is we've grouped
two different patterns in one match.
This will match all files that do not start with photo
or file and don't end with .jpg or gif.
We'll be using standard and extended globbing
throughout this course.
Keep in mind that we can use both types of globbing
with all commands including ls and cp.