Lesson 2: Find where you are and move around
Lesson objectives:
- Know what your current working directory is.
- Use
pwdto print your current location,lsto list contents, andcdto change folders.- Predict what folder you will be in after each command.
Prerequisites: Lesson 01 (opening the terminal, reading the prompt, running a command) | Previous << 01 | Next 03 >>
Lost in the maze of folders
Your computer stores files in a tree of folders. When you open a terminal, you are standing in one specific folder. That folder is called your current working directory 1. If you do not know where you are, commands that read or write files will act on the wrong place.
Three commands solve this:
pwd(print working directory) tells you where you are 21.ls(list) shows the files and folders in your current directory 23.cd(change directory) moves you to a different folder 21.
Think of pwd as checking your street address, ls as looking around the room, and cd as walking through a door.
Worked example (follow along)
Open your terminal and run these three commands one at a time. Press Return after each.
What happened:
pwdshowed you were in/Users/alex.lsshowed the folders inside it.cd Desktopmoved you into theDesktopfolder.pwdnow prints/Users/alex/Desktop.lsshows the files on the Desktop.
Your turn (faded example)
You are in /Users/alex. You want to move into the Documents folder and list its contents. Fill in the blanks:
Answer: cd Documents, then ls.
Summary + what's next
You now know how to check where you are (pwd), look around (ls), and walk through a door (cd). In Lesson 3, you will learn the two ways to describe a folder's location: absolute paths and relative paths.
Footnotes
-
William Shotts, Learning the Shell: Navigation — https://linuxcommand.sourceforge.io/lc3_lts0020.php ↩ ↩2 ↩3
-
UC Berkeley SCF: Using the bash (and zsh) shell — https://computing.stat.berkeley.edu/tutorial-using-bash/ ↩ ↩2 ↩3
-
MDN: Command line crash course — https://developer.mozilla.org/en-US/docs/Learn_web_development/Getting_started/Environment_setup/Command_line ↩