← All lessons
Command line basics · Lesson 2 of 7

Finding your way

Files on Linux live in one big tree of folders (also called directories). The very top is /, called the root. Your home folder is usually /home/ plus your name.

The shell is always in one folder, the working directory. pwd (print working directory) says which. ls lists what's in it, and cd (change directory) moves you.

$ pwd
/home/sam
$ ls
Documents  Music  Pictures  notes.txt
$ cd Documents
$ pwd
/home/sam/Documents

A path is a file's address. An absolute path starts at the root with / and works from anywhere: /home/sam/Documents. A relative path starts from where you are: from /home/sam, Documents means the same folder.

Three short names help. . is the folder you're in, .. is the one above it, and ~ is your home. So cd .. goes up one level, cd ../Music goes up and then into Music, and cd on its own (or cd ~) always takes you home. cd - jumps back to wherever you were before.

Names starting with a dot, like .bashrc, are hidden: ls skips them and ls -a shows them. ls -l gives one line per file with its size and date, and ls -lh writes sizes as 4.0K or 2.1M instead of in bytes.

Practice

Which command prints the folder you're in?

More info

Quick reference

pwdPrint the folder you're in.
ls, ls -la, ls -lhList files; long list with hidden ones; sizes in K and M.
cd folderMove into a folder. `cd` alone goes home, `cd -` goes back.
/The root, the top of the tree.
. and ..This folder, the folder above.
.nameA hidden file or folder.

The other Linux courses