16 16. Moving Around: pwd, ls, and cd
Three commands do most of the work of getting around in Bash: pwd shows where you are, ls shows what is there, and cd moves you somewhere else. This page walks through them with the practice files from Files, Folders, and Paths.
To follow along, open Bash (Terminal on a Mac, Git Bash on Windows - see Getting Bash on Your Computer) and unzip the practice files into your Documents folder, so that you have the folder ~/Documents/bash-tutorial-files: Download the practice files (zip). The outputs below come from Maria’s Mac; Git Bash shows the same information with small differences, which are pointed out along the way.
16.1 Where am I? pwd
pwd stands for print working directory. It prints the full path of your current working directory - the “you are here” marker. A new terminal window usually starts in your home directory:
pwdOutput:
/Users/maria
/c/Users/sam
Whenever you are unsure where you are, run pwd. Many beginner mistakes come from running a command in the wrong folder.
16.2 What’s here? ls
ls (short for list) shows the contents of the current folder:
lsOutput (Maria’s home folder):
Desktop Downloads Movies Pictures
Documents Library Music Public
Your list will be different. On Windows you will see more entries, including a few system files such as NTUSER.DAT - leave those alone.
16.2.1 Look inside another folder without moving
Give ls a path as an argument, and it lists that folder instead. A relative path (starting from where you are, the home folder):
ls Documents/bash-tutorial-filesOutput:
README.txt documents music pictures projects
A full path, starting with ~, works no matter where you are:
ls ~/Documents/bash-tutorial-files/musicOutput:
song1.mp3 song2.mp3
- Git Bash puts a
/after every folder name (documents/), because it is set up to runls -Fwhenever you typels(-Fis explained below). lsarranges names in columns that fit your window, so the layout varies. The order can vary too: a Mac lists capitalized names such asREADME.txtfirst; Git Bash may list it last.
16.3 Moving around: cd
cd (change directory) makes another folder your current working directory. Like most commands, it prints nothing when it works. From your home folder, go into the practice files (a relative path) and check where you are:
cd Documents/bash-tutorial-files
pwdOutput:
/Users/maria/Documents/bash-tutorial-files
Now go two levels down and look around:
cd documents/notes
pwd
lsOutput:
/Users/maria/Documents/bash-tutorial-files/documents/notes
ideas.txt meeting-notes.txt
16.3.1 Going up with ..
.. means “the parent folder” (one level up). You can use it alone or inside a longer relative path:
$ cd ..
$ pwd
/Users/maria/Documents/bash-tutorial-files/documents
$ cd ../projects/website
$ pwd
/Users/maria/Documents/bash-tutorial-files/projects/website
$ cd ../..
$ pwd
/Users/maria/Documents/bash-tutorial-files
../projects/website means “up one level (to bash-tutorial-files), then down into projects/website”. ../.. means “up two levels”.
16.3.2 Full paths, home, and back again
| Command | Takes you to |
|---|---|
cd /Users/maria/Documents |
A full path - works from anywhere. (Sam would type cd /c/Users/sam/Documents.) |
cd ~/Documents |
The same folder, using ~ for the home folder. |
cd ~ |
Your home folder. |
cd (nothing after it) |
Also your home folder. |
cd - |
Back to the folder you were in just before; the shell prints its path. |
$ cd ~/Documents/bash-tutorial-files/pictures
$ cd
$ pwd
/Users/maria
$ cd -
/Users/maria/Documents/bash-tutorial-files/pictures
In zsh (the Mac’s default shell), cd - shows the same path written with ~: ~/Documents/bash-tutorial-files/pictures.
16.4 More ls options
These examples run inside ~/Documents/bash-tutorial-files.
| Option | Meaning |
|---|---|
-F |
Add a symbol that shows the type: / after folders (and * after programs). |
-a |
Show all items, including hidden ones whose names start with a dot. |
-l |
Long format: one item per line, with details. |
-t |
Sort by time last modified, newest first. |
-r |
Reverse the sort order. |
-h |
With -l, show sizes in human-readable units (4.0K, 2.4M, 1.1G) instead of bytes. |
Short options can be combined in any order: ls -la, ls -lh, ls -ltr.
16.4.1 ls -F: which names are folders?
ls -FOutput:
README.txt documents/ music/ pictures/ projects/
16.4.3 ls -l: the long listing
ls -lOutput:
total 0
-rw-r--r-- 1 maria staff 0 Oct 22 2025 README.txt
drwxr-xr-x 4 maria staff 128 Oct 22 2025 documents
drwxr-xr-x 4 maria staff 128 Oct 22 2025 music
drwxr-xr-x 4 maria staff 128 Oct 22 2025 pictures
drwxr-xr-x 4 maria staff 128 Oct 22 2025 projects
Here is how to read the README.txt line:
| Part | Example | Meaning |
|---|---|---|
| First character | - |
- = a regular file, d = a directory (folder). |
| Next nine characters | rw-r--r-- |
Permissions: who may read, change, or run it (see the deeper dive below). |
| Number | 1 |
Number of links. You can ignore it. |
| Owner and group | maria staff |
The user who owns the item, and a group of users. |
| Size | 0 |
Size in bytes (the practice files are empty). For a folder, this is not the size of what is inside. |
| Date | Oct 22 2025 |
When it was last modified. Recent changes show the time of day instead of the year (anything older than about six months shows the year). |
| Name | README.txt |
The file or folder name. |
You can ignore the total line. Your dates will differ - they depend on when and how you unzipped the files. On a Mac you might see an @ right after the permissions (-rw-r--r--@): it means macOS has attached extra information to the file, for example that it was downloaded from the internet. In Git Bash the columns are the same, but the owner and group may look different.
16.4.4 -t, -r, and -h
ls -ltlists the most recently changed items first. Add-rto reverse that:ls -ltrputs the newest item at the bottom, right above your next prompt - handy in a folder with many files.ls -lhshows sizes such as2.4Minstead of a long number of bytes.
The practice files are empty and all have the same date, so -t and -h change little there. Try them on your Downloads folder instead: ls -lth ~/Downloads.
rwxr-xr-x)
The nine permission characters are three groups of three: what the owner may do, what the group may do, and what everyone else may do. In each group, r means read, w means write (change or delete), and x means execute (run it as a program; for a folder, x means you may enter it). A dash means “not allowed”.
-rw-r--r--: a file that the owner can read and change, and that everyone else can only read.drwxr-xr-x: a folder; the owner can do everything, others can list it and enter it but cannot change it.
You will give a file the x permission with chmod +x in Bash Scripts. In Git Bash these letters are only an approximation of Windows’ own permission system.
16.5 When cd or ls fails
Run from inside bash-tutorial-files, these two commands fail:
$ cd notes
bash: cd: notes: No such file or directory
$ cd README.txt
bash: cd: README.txt: Not a directory
- No such file or directory: nothing with that name exists here. Check for a typo, and check where you are with
pwdandls. In this case,notesis insidedocuments, so you needcd documents/notes. - Not a directory: you tried to
cdinto a file. You can onlycdinto folders.
In zsh (the Mac default) the same errors read cd: no such file or directory: notes and cd: not a directory: README.txt. ls complains about a missing name too: ls: musik: No such file or directory on a Mac, or ls: cannot access 'musik': No such file or directory in Git Bash.
16.6 Work faster: Tab, the up arrow, and clear
- Tab completion. Type the first few letters of a file or folder name and press
Tab- the shell fills in the rest. In your home folder, typingcd Docand pressingTabgivescd Documents/. If several names match, the shell completes as much as it can and can list the choices: in Git Bash, pressTaba second time; zsh on a Mac shows the list right away (more in Getting Help and Working Faster). Tab completion saves typing and prevents typos, including wrong capitalization. - Command history. Press the up arrow (
↑) to bring back earlier commands, and the down arrow (↓) to go forward again. Edit a command with←and→, then pressEnterto run it. clear(orCtrl+L) wipes the screen. It doesn’t change any files.
More shortcuts are in Getting Help and Working Faster.
16.7 Getting help for ls
ls has many more options. In Git Bash, ls --help lists them all. On a Mac, ls --help doesn’t work: the Mac’s ls is a different version (the “BSD” version), which doesn’t understand --help or most other long options. Use man ls instead (scroll with the arrow keys, press q to quit). Git Bash, in turn, does not include man.
16.8 Command summary
| Command | What it does |
|---|---|
pwd |
Print the full path of the current folder. |
ls / ls path |
List the current folder / list another folder. |
ls -F, ls -a, ls -l |
Mark folders with /; include hidden items; long format. |
ls -ltr, ls -lh |
Oldest first (newest at the bottom); human-readable sizes. |
cd path |
Go to a folder (relative or full path). |
cd .., cd ../.. |
Go up one level, two levels. |
cd, cd ~ |
Go to your home folder. |
cd - |
Go back to the previous folder. |
Practice Questions
Unless a question says otherwise, Maria’s practice files are in /Users/maria/Documents/bash-tutorial-files (see the tree on Files, Folders, and Paths).
Easy
Question 1 · Short answer
What does pwd stand for, and what does it print?
Question 2 · Multiple choice
Which command moves you to the parent of the current folder?
cd .cd ..cd ~cd -
Question 3 · True or false
Typing cd with nothing after it does nothing.
Question 4 · Matching
Match each ls option with what it does.
| Option | Effect | |
|---|---|---|
1. -a |
A. reverse the sort order | |
2. -l |
B. sizes like 4.0K or 2.4M (with -l) |
|
3. -t |
C. show hidden items too, including . and .. |
|
4. -r |
D. mark folders with a trailing / |
|
5. -h |
E. sort by time modified, newest first | |
6. -F |
F. long format with details |
Question 5 · Short answer
What does cd - do? What does it print?
Question 6 · Multiple choice
In the output of ls -l, what does a line that starts with d describe?
- A deleted file
- A directory (folder)
- A document
- A hidden file
Medium
Question 7 · Write the command
Maria is in bash-tutorial-files. Write one command that lists the contents of projects/website without changing her current folder.
Question 8 · Predict the output
Maria is in bash-tutorial-files and runs:
cd documents/reports
cd ../notes
pwdWhat does pwd print?
Question 9 · Write the command
Maria is in documents/notes. Using a relative path, write one command that takes her to projects/data-analysis.
Question 10 · Write the command
Sam (Windows, Git Bash) unzipped the practice files into C:\Users\sam\Documents. Write two different commands that take him to the bash-tutorial-files folder from anywhere.
Question 11 · Compare
What is the difference between ls -lt and ls -ltr? Which one shows the most recently changed file at the bottom of the list?
Question 12 · Short answer
Read this line from ls -l:
drwxr-xr-x 4 maria staff 128 Oct 22 2025 projects
Is projects a file or a folder? Who owns it? Does 128 mean the files inside it take up 128 bytes?
Question 13 · Multiple choice
Which command shows hidden files such as .gitignore?
ls -hls -als -lls -F
Question 14 · Fill in the blank
Maria is in bash-tutorial-files.
cd pictures/family.jpgfails with the error “______”, becausefamily.jpgis a file.cd picture(missing thes) fails with the error “______”.
Hard
Question 15 · Find the bug
Maria opens a new terminal window and types:
cd bash-tutorial-filesShe gets a “No such file or directory” error, although the folder definitely exists. Explain why, and give two commands that work.
Question 16 · Scenario
Sam (Git Bash) types ls in bash-tutorial-files and sees documents/, music/ and so on, with slashes. Maria types the same command on her Mac and sees no slashes. Who is right, and why the difference?
Question 17 · Predict the output
Maria runs these four commands. What appears on the screen?
cd ~/Documents/bash-tutorial-files/music
cd ../pictures
cd -
pwdQuestion 18 · Scenario
Maria types ls --help on her Mac and gets an error instead of a help text. Sam types man ls in Git Bash and gets command not found. Explain both and say what each of them should do instead.
Question 19 · Compare
From bash-tutorial-files, compare:
ls documents
cd documentsfollowed byls
Do they show the same names? What is different afterwards?
Question 20 · Ordering
Maria is in her home folder. Put these commands in an order that (1) goes to documents/notes, (2) shows a long listing including hidden items, (3) returns to the home folder, and (4) confirms where she is.
pwdls -lacd ~/Documents/bash-tutorial-files/documents/notescd
Question 21 · Long answer
Why is it a good habit to run pwd (and often ls) before running a command that creates, moves, or deletes files - whether you type the command yourself or an AI agent suggests it?