Linux Command Line Interface: The Basics — Part 4
4.0 Changing directories
Navigating directories using the CLI?
Bash provides a widely used command called cd
or change directories command that allows the user to navigate through directories.
In order to see how it works perform the following:
- Click on the terminal window
- Type
ls
to list the current directory contents, return key - Type
cd dir1
to enter the dir1 directory, return key - Type
ls
to list the dir1 directory contents, return key
Take a look inside the dir1
directory in the file tree. It should match the contents you got from the ls
command.
That’s it, you’ve learned how to enter a directory in bash scripting.
Command: cd
Definition:
The cd
command or change directories command allows you to go inside a directory by adding its name as an argument:
cd name_of_directory
4. 1. Navigating backwards
Remember the double dots?
When we executed the ls -a
command, we noticed a set of single and double dots: . ..
As we previously mentioned these dots are utilities that bash uses to help navigate the file system.
Going back one directory level
Having entered the dir1 directory in the previous section, we may then want to get back out of it:
- Execute the
pwd
command to confirm we are on the dir1 directory - Execute the
ls -a
command to confirm that we indeed have single and double dots available - Execute
cd ..
to exit the current directory and go back 1 directory (to the parent directory) - Execute
pwd
to confirm that we are back on the/home/root/workspace/
directory