#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:
/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.
$ pwd
/home/userls — View contents
ls (short for list) displays the files and folders in the current directory.
$ ls
Documents projectsYou can also view the contents of another folder by passing its name as an argument:
$ ls Documents
notes.txtThe -la option shows a detailed view with permissions, owner, and modification date:
$ 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 projectscd — Move around
cd (short for change directory) lets you change folders. It's like opening a drawer.
$ cd Documents
$ pwd
/home/user/DocumentsTo go up one level (return to the parent folder), use cd ..:
$ cd ..
$ pwd
/home/userThe 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.
$ mkdir my-folder
$ ls
Documents my-folder projectsYour 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.