Git & Command Line Tutorial · Command Line Basics · Lesson 2 of 20

Navigating the File System

Know where you are with pwd, list files with ls, move around with cd, and understand absolute vs relative paths, ~ and ..

Create a free account to save this page, take notes and track your progress. Sign in

Where am I?

  • pwd prints the working directory (where you are).
  • ls lists files; ls -a includes hidden files (names starting with .); ls -F marks folders with /; ls -l shows details.
  • cd folder moves into a folder; cd .. goes up one level; cd ~ (or just cd) goes home; cd - returns to the previous folder.

Paths

  • Absolute paths start at the root: /home/ana/projects.
  • Relative paths start from where you are: projects/blog, ../notes.
  • . means "this folder", .. "the parent", ~ "my home folder".

Press Tab to auto-complete file names, and the up arrow to repeat earlier commands.

Moving around with ls, cd and relative paths
mkdir demo && cd demo        # start in an empty folder
mkdir -p projects/blog/posts projects/shop notes
touch projects/blog/README.md .secret-config

ls -F                 # folders end with /
ls -a | head -4       # hidden files too (. and .. are this folder and its parent)
cd projects/blog
pwd | sed 's#.*/projects#.../projects#'
cd ../shop            # relative: up one, then into shop
pwd | sed 's#.*/projects#.../projects#'
cd ../..              # back to where we started
ls -F projects

Output

notes/
projects/
.
..
.secret-config
notes
.../projects/blog
.../projects/shop
blog/
shop/

Run this on your computer — see “Get Started” for setup.

Test yourself

Which command moves you up one folder?

  1. cd /
  2. cd ..
  3. cd ~
  4. up
Show answer

Answer: cd ..

Was this page helpful?