Review & Changing Directories
Review: Where am I?
To get your bearings and view your current working directory you can use the familiar
pwd command simply prints out the contents of the
$PWD shell variable. Don’t forget you can see the contents of any shell variables with the
Review: What are the contents of this location?
To view the contents of the current working directory you can use the familiar
ls command without any arguments.
Change Current Working Directory
To change the current working directory you can use the
cd builtin command.
cd allows for one optional argument. If no argument is provided it will set the current working directory to the
$HOME shell variable.
cd works with both absolute and relative paths.
cd relative path
Starting from the home directory we could move into the
Documents/ directory with the following command:
Take note from the image that our terminal emulator always tells us the current working directory. You should see
~/Documents$ directly before the character where you can enter text commands. You can also see on the previous line before the
cd command had been executed the text directly before our input area is only
cd absolute path
Our current working directory is
/home/student/Documents. We can return to the home directory by using an absolute path:
And we’re back to
The main benefit in using an absolute path as the argument for the
cd command is it will work from any location. The absolute path is an unique identifier for a directory.
Another useful tool for changing directories is to learn some of the Bash shell shortcuts.
~: a shortcut for the
.: a shortcut for the current working directory (
..: a shortcut for the parent of the current working directory
From a terminal change into the root directory:
From the root directory change into the home directory by using the home shortcut:
The default argument for the
cd command is the home directory. An even more efficient shortcut for changing into the home directory would be simply
cd with no arguments. Try it out on your own, by changing into the root directory, and then entering
cd without any arguments.
Shortcut to Parent
From your home directory let’s change into the parent directory using the
Using the parent directory shortcut we were able to move up one directory.
You can extend the parent and current directory shortcuts. Assuming you are in
/home/student/Documents you can change into
/home/student/Desktop with the command:
Additionally, the parent and current directory shortcuts can be used with most bash commands.