Linux Command Line Interface: The Basics — Part 4

Austin Songer
Code The World
Published in
2 min readJan 16, 2017

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:

  1. Click on the terminal window
  2. Type ls to list the current directory contents, return key
  3. Type cd dir1 to enter the dir1 directory, return key
  4. 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:

  1. Execute the pwd command to confirm we are on the dir1 directory
  2. Execute the ls -a command to confirm that we indeed have single and double dots available
  3. Execute cd .. to exit the current directory and go back 1 directory (to the parent directory)
  4. Execute pwd to confirm that we are back on the /home/root/workspace/ directory

--

--

Austin Songer
Code The World

Trusted Veteran | Compassionate. Aspiring. Resourceful.