- [Instructor] In Chapter One of this course
we talked about using dot and dot dot
as short cuts to the current directory
and the parent directory.
These short cuts are provided by the file system.
We can see these by showing hidden files with LS.
Type in LS space dash L A and hit enter.
The top two items are the dot and dot dot directories.
There is another way of expanding the path
to include these directories and more
using bash path substitution.
The tilde is a meta character with special meaning.
It allows us to expand the path
to include directories like the users home,
the current directory, parent directory,
or even the previous directory.
If we type in echo space tilde
and hit enter, it shows our home directory.
We can also get it to expand out
to other users home directories as well
by specifying the user.
Type in echo space tilde
root and hit enter.
If we follow the tilde with a plus symbol
it will expand to our current directory.
Let's see into another directory first.
Type in CD space slash var and hit enter.
Now, type in echo tilde plus and hit enter.
This is similar to the dot character
but provided by the bash tilde substitution.
If we append a hyphen to the tilde
it will expand to our previous directory.
Type in echo space
tilde hyphen and hit enter.
The tilde hyphen allows us to bounce
between two directories very easily.
We can also expand to any directory in the list,
we have to use the push D command to put
directories in the list first.
Type in push D
space slash E T C slash
yum dot repos dot d
and hit enter.
Now, let's type in push D space slash var slash log
and hit enter again.
Use the dir commands to verify.
Type in D I R S and hit enter.
We see that we have a couple of directories in the stack.
Now, use tilde substitution to access them.
We have to supply a directory number starting from zero
so type in echo space tilde zero and hit enter.
The tilde hyphen expansion allows us
to bounce between two directories.
This allows us to bounce between any number of directories.
Type in echo space
tilde one and hit enter.
We can use these with any command.
For instance if we wanted a CD to a directory
we type in C D space tilde zero and hit enter.
C D space tilde one and hit enter.
To remove items from the list use pop D.
Let's view our list again using dirs.
Type in pop D space plus one and hit enter.
This removes the second item from the list,
remember that we're counting from zero
so the left most item is item zero.
Another great tool is brace expansion.
By using braces we can provide whole word patterns.
For instance, if we type echo space
S left curly bracket
P E comma P I
right curly bracket L L and hit enter,
it echos both spell and spill.
This works by expanding the characters in the braces.
For each character in the brace,
it expands the word inserting that character
or characters into the word,
so we end up with spell and spill.
Note: this does not work inside of quotes.
Bring your line back and insert quotes before the S
and after the last L and hit enter.