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:

pwd

Output:

/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:

ls

Output (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-files

Output:

README.txt      documents       music           pictures        projects

A full path, starting with ~, works no matter where you are:

ls ~/Documents/bash-tutorial-files/music

Output:

song1.mp3       song2.mp3
Git Bash looks slightly different
  • Git Bash puts a / after every folder name (documents/), because it is set up to run ls -F whenever you type ls (-F is explained below).
  • ls arranges names in columns that fit your window, so the layout varies. The order can vary too: a Mac lists capitalized names such as README.txt first; 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
pwd

Output:

/Users/maria/Documents/bash-tutorial-files

Now go two levels down and look around:

cd documents/notes
pwd
ls

Output:

/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 -F

Output:

README.txt      documents/      music/          pictures/       projects/

16.4.2 ls -a: show hidden items

ls -a

Output:

.               README.txt      music           projects
..              documents       pictures

. is the current folder and .. is its parent. Any hidden files would appear here too. On a Mac you may also see .DS_Store, a hidden file that Finder creates to remember how a folder is displayed. It is harmless.

16.4.3 ls -l: the long listing

ls -l

Output:

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 -lt lists the most recently changed items first. Add -r to reverse that: ls -ltr puts the newest item at the bottom, right above your next prompt - handy in a folder with many files.
  • ls -lh shows sizes such as 2.4M instead 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.

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 pwd and ls. In this case, notes is inside documents, so you need cd documents/notes.
  • Not a directory: you tried to cd into a file. You can only cd into 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, typing cd Doc and pressing Tab gives cd Documents/. If several names match, the shell completes as much as it can and can list the choices: in Git Bash, press Tab a 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 press Enter to run it.
  • clear (or Ctrl+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?

Print working directory. It prints the full path of the current working directory - the folder the terminal is “standing in”, for example /Users/maria/Documents/bash-tutorial-files.

Question 2 · Multiple choice

Which command moves you to the parent of the current folder?

  1. cd .
  2. cd ..
  3. cd ~
  4. cd -

b. .. means the parent folder. cd . “moves” to the current folder (so nothing changes), cd ~ goes to your home folder, and cd - goes back to the folder you were in before.

Question 3 · True or false

Typing cd with nothing after it does nothing.

False. cd on its own takes you to your home directory, exactly like cd ~.

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

1 → C, 2 → F, 3 → E, 4 → A, 5 → B, 6 → D.

Question 5 · Short answer

What does cd - do? What does it print?

It takes you back to the folder you were in just before your last cd, and it prints the path of that folder so you can see where you landed (Bash prints the full path; zsh writes your home folder as ~).

Question 6 · Multiple choice

In the output of ls -l, what does a line that starts with d describe?

  1. A deleted file
  2. A directory (folder)
  3. A document
  4. A hidden file

b. The first character shows the type: d for a directory, - for a regular file. Deleted files don’t appear at all, documents are just regular files (-), and hidden files are recognized by a name starting with a dot, not by the first character of the line.

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.

ls projects/website

Giving ls a path lists that folder; Maria stays where she is. (A full path such as ls ~/Documents/bash-tutorial-files/projects/website also works.)

Question 8 · Predict the output

Maria is in bash-tutorial-files and runs:

cd documents/reports
cd ../notes
pwd

What does pwd print?

/Users/maria/Documents/bash-tutorial-files/documents/notes

cd documents/reports goes down two levels. ../notes goes up to documents and then down into notes.

Question 9 · Write the command

Maria is in documents/notes. Using a relative path, write one command that takes her to projects/data-analysis.

cd ../../projects/data-analysis

../.. goes up from notes to documents and then to bash-tutorial-files; from there, go down into 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.

cd /c/Users/sam/Documents/bash-tutorial-files
cd ~/Documents/bash-tutorial-files

Both are full paths, so they work from any folder. In Git Bash, the C: drive is written /c, and ~ is /c/Users/sam.

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?

Both show the long format sorted by modification time. ls -lt puts the newest item first. ls -ltr reverses the order, so the oldest comes first and the newest is at the bottom - right above your next prompt, where it’s easy to see.

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?

It is a folder (the line starts with d). It is owned by the user maria (group staff). No: for a folder, the size column is not the size of its contents - it only describes the folder’s own bookkeeping, so you can ignore it.

Question 13 · Multiple choice

Which command shows hidden files such as .gitignore?

  1. ls -h
  2. ls -a
  3. ls -l
  4. ls -F

b. -a (“all”) includes names that start with a dot. -h is a common trap: it means human-readable sizes, not “hidden”. -l adds details and -F marks folders, but neither shows hidden files.

Question 14 · Fill in the blank

Maria is in bash-tutorial-files.

  • cd pictures/family.jpg fails with the error “______”, because family.jpg is a file.
  • cd picture (missing the s) fails with the error “______”.
  • Not a directory - you can only cd into folders.
  • No such file or directory - nothing named picture exists in the current folder.

Hard

Question 15 · Find the bug

Maria opens a new terminal window and types:

cd bash-tutorial-files

She gets a “No such file or directory” error, although the folder definitely exists. Explain why, and give two commands that work.

A new terminal starts in her home folder, /Users/maria. The relative path bash-tutorial-files is looked up there, but the folder is inside Documents. Either of these works:

cd Documents/bash-tutorial-files
cd ~/Documents/bash-tutorial-files

(The second is a full path, so it works from any folder.) Running pwd and ls first would have shown the problem.

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?

Both are right - they see the same folders. Git Bash is set up so that typing ls actually runs ls -F, which adds a / after each folder name. Maria can get the same display by typing ls -F herself.

Question 17 · Predict the output

Maria runs these four commands. What appears on the screen?

cd ~/Documents/bash-tutorial-files/music
cd ../pictures
cd -
pwd
/Users/maria/Documents/bash-tutorial-files/music
/Users/maria/Documents/bash-tutorial-files/music

The two cd commands print nothing. cd - jumps back to the previous folder (music) and prints its path; then pwd prints the same path again. That is what Bash shows. In zsh, the Mac’s default shell, cd - writes the path with ~, so the first line reads ~/Documents/bash-tutorial-files/music.

Question 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.

The Mac comes with the BSD version of ls, which doesn’t understand the long option --help; Maria should use man ls (and press q to quit). Git Bash comes with the same ls as Linux (the GNU version), which does support ls --help, but Git Bash does not include the man command; Sam should use ls --help. Either of them can also search online or ask an AI - saying which operating system and shell they use.

Question 19 · Compare

From bash-tutorial-files, compare:

    1. ls documents
    1. cd documents followed by ls

Do they show the same names? What is different afterwards?

Both list the same names (notes and reports). The difference is where you end up: after (A) you are still in bash-tutorial-files; after (B) your current working directory is bash-tutorial-files/documents, so relative paths in your next commands start from there.

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.

  • pwd
  • ls -la
  • cd ~/Documents/bash-tutorial-files/documents/notes
  • cd
cd ~/Documents/bash-tutorial-files/documents/notes
ls -la
cd
pwd

The last command prints /Users/maria.

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?

Relative paths are interpreted from the current working directory, so the same command does different things in different folders. A command such as “delete reports” might hit the wrong reports folder - or fail - if you are not where you think you are. pwd confirms the folder; ls confirms that the files you expect are really there. Commands suggested by an AI are written for a particular folder, so checking your location before running them prevents surprises.

© 2025-2026 Y. Rosenthal. All rights reserved.