Course / 03 Command line / Lesson 02 of 19

Where you are

Estimated time: 15 min reading · 15 min activity

Before opening a note, you need to know which folder the shell is using. A command such as cat note.txt looks for that name from a starting location called the working directory. The same name can refer to a different file after you change that directory.

A path describes a location in the filesystem. A directory is a folder, and a child directory is a folder inside another folder. Its parent is the folder containing it. In Linux paths, / separates these names. You will use pwd to display the working directory and cd to change it.

Before you begin

Estimated time
15 min reading, 15 min activity. Setup and optional practice may take longer.
Where you work
Use Bash in your owned Ubuntu practice environment as an ordinary user. The supplied text files use UTF-8, a text encoding; where shown, LC_ALL=C requests consistent text ordering. Work only under your own new ~/yanosec-lab directory, never a host share or personal/system file. Refuse an existing exercise destination rather than overwriting it. No account, paid platform, or remote target is required. Optional extensions take about 10–15 minutes and are not part of the time above. A virtual machine is optional. You can also finish the reasoning from the printed evidence.
Without a lab
The page supplies the files, source and text records needed for the activity. Without a shell, follow the numbered steps on paper, label each result as predicted, and use the separate evidence supplied by the question. Running commands can wait until your lab is available. Reading works without JavaScript. Answer checking needs JavaScript and a secure context, such as HTTPS; saving a correct result also needs usable browser storage. Missing tools, managed or mobile hosts, or a deferred guest setup never require buying a service. Keep owned lab files for review; do not use broad deletion.

After this lesson you can:

  • Distinguish absolute and relative Linux paths.
  • Predict the result of entering a child or parent directory.
  • Create a new lab destination or trace its full tree without overwriting work.

01Example

Start in the fictional working directory /home/desk/lab, which contains a child folder named notes. cd changes this shell's directory; pwd displays the resulting absolute path. Read the command and predicted result separately. Your real home path can differ.

Starting directory: /home/desk/lab

Command to type:
cd notes
Command to inspect the result:
pwd
Predicted result:
/home/desk/lab/notes

Next command:
cd ..
Command to inspect the result:
pwd
Predicted result:
/home/desk/lab

02Home is an anchor

An absolute path begins with / and starts at the root directory, the top of the Linux path tree. A relative path begins from the current working directory. From /home/desk/lab, notes means /home/desk/lab/notes. A leading slash changes its meaning: /notes names a location directly under root.

The short path . means the current directory; .. means its parent. cd notes enters a child named notes. cd .. moves to the parent. Check pwd after either action so your next command starts where you intend.

Bash expands ~ at the start of an unquoted path to your home directory. cd with no argument also returns home. Home is usually a personal directory; / is the filesystem root. The root directory is different from the root administrator account.

mkdir creates a directory. Plain mkdir reports a conflict when the requested name already exists. Here that tells you to preserve earlier work. Enter one command at a time and continue only after it succeeds. If a destination exists, choose a new name consistently or use the printed tree.

Relative cd starts at /home/desk/lab; entering notes adds a segment, and .. returns to the parent.Model. A teaching model drawn by hand. It shows the idea, not real tool output.

Read the full explanation below.

cd notes, then pwdcd .., then pwd (after entering notes)

Starting location

/home/desk/lab

Resolve each path segment

homelevel 1desklevel 2lablevel 3
cd notes, then pwd
Current modeled path
/home/desk/lab

Original current directory

Begin at /home/desk/lab before consuming notes.

Follow the explanation

  1. Begin at /home/desk/lab before consuming notes.
  2. cd notes adds the child; pwd would print /home/desk/lab/notes.
  3. After entering notes, .. removes that last segment; pwd would print /home/desk/lab.
Read every state and value

1. Begin at /home/desk/lab before consuming notes.

Action
child
Stack
home · desk · lab
Consumed Count
0
Current Path
/home/desk/lab
Boundary Label
Original current directory

2. cd notes adds the child; pwd would print /home/desk/lab/notes.

Action
child
Stack
home · desk · lab · notes
Consumed Count
1
Current Path
/home/desk/lab/notes
Output Text
/home/desk/lab/notes
Boundary Label
Child notes

3. After entering notes, .. removes that last segment; pwd would print /home/desk/lab.

Action
parent
Stack
home · desk · lab
Consumed Count
2
Current Path
/home/desk/lab
Output Text
/home/desk/lab
Boundary Label
Parent: removed notes
Relative cd starts at /home/desk/lab; entering notes adds a segment, and .. returns to the parent.

03Try a new navigation tree

The worksheet separates an example tree from the question at the end. In the activity, make only the small navigation tree under your own lab directory. Its named folders are enough to practice cd and pwd; you do not need to download an archive.

For the paper route, start at /home/desk/yanosec-lab/navigation. Draw desk-demo with children notes and receipts, then follow the same moves in the numbered steps. Write the complete working path after each move. Creating folders and checking them in a terminal can wait.

Path practice and complete archive inventory

Read this tree before navigating. The archive contains only the files
listed below. For paper practice, begin in the stated activity directory
and record the working path after entering notes and after cd ..

This is a complete printed inventory, not an extraction record.
desk-demo/
  notes/map.txt = route north (newline)
  receipts/item.txt = pencil (newline)
Example working directory: /home/desk/lab
Example action: cd notes -> predicted /home/desk/lab/notes
Activity: navigate desk-demo/notes then cd .. back to desk-demo.
Question current directory: /home/desk/tasks
Question child directory: receipts
Question action: cd receipts
Record the resulting absolute path, not the activity's real home path.

Download the path tree and question case

  1. Use cd with no argument, then pwd. If ~/yanosec-lab is absent, create it with mkdir ~/yanosec-lab. If it already exists, inspect it and use it only when you recognize it as your owned lab; otherwise stop and choose a fresh root name consistently or the paper route.
  2. Enter cd ~/yanosec-lab. Create a new child with mkdir navigation, then cd navigation. If mkdir reports a conflict, stop rather than entering an existing unknown destination.
  3. Create a small tree: mkdir desk-demo, then mkdir desk-demo/notes and mkdir desk-demo/receipts. These create directories only; the optional archive additionally supplies the ordinary data files listed in tree.txt.
  4. Enter cd desk-demo, inspect pwd, then cd notes and pwd. Expected: the working path ends in /navigation/desk-demo/notes. Enter cd .. and inspect pwd again; it ends in /navigation/desk-demo.
  5. Compare these observed suffixes with the fictional example, not with its username. Return using cd ~/yanosec-lab. Retain the tiny tree for later review; no deletion is required.

04An optional archive route

An archive is one file that bundles other files and directories. The optional desk-demo.tar.gz also contains the ordinary data files printed in the worksheet. Read the archive guide before using tar, the program that lists or extracts its entries.

List the archive first and compare every path with the supplied inventory. Extract means write those entries back into directories. Use a new empty destination so extraction cannot replace earlier work. The activity above already practices navigation without extraction.

Read an owned archive before extracting it

An archive bundles named entries. Extracting writes those entries back
to disk. A .tar.gz file uses tar bundling plus gzip compression; neither
operation encrypts the content. Use only the supplied owned archives.

All supplied archives contain original ordinary text files under one
named directory. No symlinks, executables with special modes, devices,
absolute paths or parent traversal entries are authored. Inspect first.
Save the chosen archive in the GUEST Downloads folder. If its actual
location differs, use that quoted absolute path; do not guess.
Use a new destination beneath ~/yanosec-lab, never an existing folder.
Example templates (replace ARCHIVE.tar.gz and NEW-DEST):
tar -tzf ~/Downloads/ARCHIVE.tar.gz
mkdir ~/yanosec-lab/NEW-DEST
tar -xzf ~/Downloads/ARCHIVE.tar.gz -C ~/yanosec-lab/NEW-DEST
Run the extraction only if mkdir succeeded and inventory matches.
t lists; x extracts; z handles gzip; f names archive; -C names target.
Keep original data; do not use sudo, overwrite flags or root extraction.
Stop on an unexpected path/link/member or download you cannot identify.
Fallback: read the full inline tree and contents; predict actions in notes.
Cleanup: leave scoped files for review; restore a guest baseline only
if all subsequent guest work is disposable. No broad rm command.

Download archive handling and text fallback guidance

05Optional challenge

Allow about ten extra minutes. Starting at /home/mila/projects/drafts on paper, compare cd .. with cd /home/mila. The first uses the current location; the second names a destination from root. Explain both resulting paths before checking them against your drawing.

06Fresh cases for the checks

Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.

Navigation card A: trace a fresh treeOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Starting directory: /home/nila/Field
Its child directories are Maps and Reports. Reports contains a child named Final.
Commands, in order: cd Maps; cd ..; cd Reports; cd Final; cd ..
Each listed command succeeds. No symbolic links are involved.

Navigation card B: same name, different locationsOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Starting directory: /home/teo/Projects
Two existing directories: /home/teo/Projects/Archive and /Archive
The learner intends to enter the Archive inside Projects.
Consider cd Archive, cd /Archive and cd .. independently from the same starting directory.
Names and capitals are exact; no symbolic links are involved.

Navigation card C: an existing exercise destinationOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Current directory: /home/ines/owned-lab
Goal: create a NEW empty directory for a file-writing exercise.
Command attempted: mkdir review
Supplied result: creation failed because review already exists.
The contents of review have not been inspected or identified as disposable.

Navigation card D: independent return-home caseOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Account home directory: /home/omar
Current directory: /home/omar/lab/notes
Next command: cd
The command has no argument and succeeds in the stated Bash environment.

07Explain how you would confirm a destination

Optional self-check: explain why a successful cd does not by itself prove that you reached the directory you intended. Add what you would do when an exercise directory already exists.

Review your explanation: distinguish absolute and relative paths, use pwd to check the full location, preserve exact name capitalization, and stop before writing into an unknown existing destination. This explanation is self-reviewed.

08Common mistakes

If a relative path reaches the wrong place, inspect pwd before changing anything. Start from the stated parent and append only the named child; an initial / changes the interpretation.

If a directory is missing or its capitalization differs, list the owned parent with ls -a and inspect names. Linux names are generally case-sensitive; do not create extra guessed folders just to silence a mistake.

If a lab name already exists, preserve it and choose a new unused destination or paper route. Do not use sudo, overwrite flags or broad removal as a navigation fix.

References

  • Ubuntu 24.04 packaged manual: bash(1)

    Shell grammar, quoting, builtins, redirection and job control; use only the sections introduced in this lesson. Use the named command and option sections. This manual describes Ubuntu 24.04 packages; your installed version can differ. The lesson supplies the facts needed for its activity.

  • Ubuntu 24.04 packaged manual: mkdir(1)

    Use the named command and option sections. This manual describes Ubuntu 24.04 packages; your installed version can differ. The lesson supplies the facts needed for its activity.

  • Ubuntu 24.04 packaged manual: tar(1)

    Use the named command and option sections. This manual describes Ubuntu 24.04 packages; your installed version can differ. The lesson supplies the facts needed for its activity.