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 ..
Where am I?
pwdprints the working directory (where you are).lslists files;ls -aincludes hidden files (names starting with.);ls -Fmarks folders with/;ls -lshows details.cd foldermoves into a folder;cd ..goes up one level;cd ~(or justcd) 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.
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?
cd /cd ..cd ~up
Show answer
Answer: cd ..