Phase 1Discover the terminal

#2 Navigating folders

ls, cd, mkdir

The file system

Your computer organizes everything into folders (or directories) nested inside one another, like drawers in a cabinet. The terminal lets you navigate through this tree structure.

Here is an example of a typical structure:

Tree structure
/home/user/
  Documents/
    notes.txt
  projects/
    website/

pwd — Where am I?

You already know pwd from the previous lesson. It displays the full path of the current directory. It's your compass in the terminal.

Example
$ pwd
/home/user

ls — View contents

ls (short for list) displays the files and folders in the current directory.

Example
$ ls
Documents  projects

You can also view the contents of another folder by passing its name as an argument:

List a specific folder
$ ls Documents
notes.txt

The -la option shows a detailed view with permissions, owner, and modification date:

Detailed list
$ ls -la
total 16
drwxr-xr-x  4 user user 4096 mar  3 10:00 .
drwxr-xr-x  3 root root 4096 mar  1 08:00 ..
drwxr-xr-x  2 user user 4096 mar  2 14:30 Documents
drwxr-xr-x  3 user user 4096 mar  3 09:15 projects

cd — Move around

cd (short for change directory) lets you change folders. It's like opening a drawer.

Enter a folder
$ cd Documents
$ pwd
/home/user/Documents

To go up one level (return to the parent folder), use cd ..:

Go up
$ cd ..
$ pwd
/home/user

The shortcut ~ always represents your home directory (/home/user). You can return to it from anywhere with cd ~ or simply cd.

mkdir — Create a folder

mkdir (short for make directory) creates a new folder. If the command succeeds, it produces no output — silence means success.

Create a folder
$ mkdir my-folder
$ ls
Documents  my-folder  projects

Your turn

Try the commands ls, cd, mkdir and pwd in the terminal below. Note that the terminal is simulated: the displayed current directory won't actually change, but the outputs are realistic.

terminal — bash
user@stemlegacy:~$