Module brief#
Master “where am I?” and “how do I point at a file?” Absolute vs relative paths, confident cd, and the ls flags you will use every day.
Learning objectives#
- Print the working directory with
pwd - Choose absolute or relative paths appropriately
- Move around with
cd,.,.., and/ - List directories using
ls,-l,-a,-i,-ld,-R,-F - Identify file kinds with
ls -Fandfile
1. Working directory and pwd#
The shell always has a current working directory. Commands that take a relative path start from here.
pwd
/tmp/linux-lab-pushpjeet
If you ever feel lost: run pwd, then ls.
2. Absolute vs relative paths#
An absolute path starts at / and names every step:
/tmp/linux-lab-pushpjeet/notes.txt
A relative path starts from your current directory:
notes.txt
./notes.txt
project/src
../linux-lab-pushpjeet/notes.txt
Useful shorthand:
| Token | Meaning |
|---|---|
. |
Current directory |
.. |
Parent directory |
/ at the start |
Absolute path from the tree root |
~ |
Your home directory (expanded by the shell) |
Examples from the lab folder:
cd /tmp/linux-lab-pushpjeet
pwd
ls ./project/src
ls ../ # parent of the lab dir — often /tmp
Absolute paths are unambiguous in scripts. Relative paths are shorter while you explore.
3. Moving with cd#
cd /tmp/linux-lab-pushpjeet/project
pwd
cd ..
pwd
cd ~
pwd
cd - # jump back to the previous directory (bash)
Tips:
cdalone orcd ~returns home- Tab-completion reduces typos — press Tab after typing a unique prefix
- If
cdfails with “No such file or directory,” checkpwdand spelling
4. Everyday ls options#
Create a small playground if you still have the course lab dir:
cd /tmp/linux-lab-pushpjeet
ls
a.txt b.txt empty.dat hard-notes notes.txt project readme.txt sample.log soft-notes
Long listing: -l#
ls -l soft-notes notes.txt project
-rw-r--r-- 2 box box 49 Sep 26 11:04 notes.txt
drwxr-xr-x 5 box box 4096 Sep 26 11:04 project
lrwxrwxrwx 1 box box 9 Sep 26 11:04 soft-notes -> notes.txt
Hidden entries: -a#
Names starting with . are hidden from plain ls:
ls -a
. .. a.txt b.txt empty.dat hard-notes notes.txt project readme.txt sample.log soft-notes
. and .. always appear with -a.
Classify at a glance: -F#
ls -F
a.txt b.txt empty.dat hard-notes notes.txt project/ readme.txt sample.log soft-notes@
Trailing / marks a directory; @ marks a symlink (GNU ls).
Directory itself, not contents: -ld#
ls -ld project
drwxr-xr-x 5 box box 4096 Sep 26 11:04 project
Without -d, ls -l project lists what is inside project.
Inodes: -i#
ls -i notes.txt hard-notes soft-notes
1084900 hard-notes
1084900 notes.txt
1084906 soft-notes
Same inode number means the same underlying file (hard links — Module 6).
Recursive: -R#
ls -R project
project:
data docs src
project/data:
project/docs:
project/src:
Combine flags freely: ls -la, ls -li, ls -lF.
5. The file command#
file notes.txt /bin/ls soft-notes project /dev/null
notes.txt: ASCII text
/bin/ls: ELF 64-bit LSB pie executable, x86-64, ...
soft-notes: symbolic link to notes.txt
project: directory
/dev/null: character special (1/3)
Use file when an extension is missing or misleading.
Practice: MCQs#
Q1. Which path is absolute?
- A)
../docs - B)
notes.txt - C)
/home/student/notes.txt - D)
./project
Answer
C. Absolute paths begin with /.
Q2. You are in /tmp/linux-lab-pushpjeet/project. What does cd .. do?
- A) Goes to
/ - B) Goes to
/tmp/linux-lab-pushpjeet - C) Goes to your home directory
- D) Deletes the project folder
Answer
B. .. is the parent directory.
Q3. Why use ls -ld dirname?
- A) To delete the directory
- B) To list information about the directory itself
- C) To show only empty directories
- D) To follow every symlink on the system
Answer
B. -d prevents descending into the directory’s contents.
Q4. ls -a is useful because:
- A) It sorts by file size only
- B) It shows entries whose names start with
. - C) It disables colours permanently
- D) It prints absolute paths for every file
Answer
B. Dotfiles and the . / .. entries become visible.
Q5. Two names share the same inode in ls -i. That suggests:
- A) They are on different disks always
- B) They are hard links to the same file data
- C) One of them must be a directory
- D)
lsis broken
Answer
B. Hard links share an inode. Module 6 goes deeper.
Practice: Match the columns#
| Flag / token | Meaning (scrambled) |
|---|---|
1. ls -l |
A. Show hidden names |
2. ls -a |
B. Long / detailed listing |
3. ls -R |
C. Classify with / and @ markers |
4. ls -F |
D. Recurse into subdirectories |
5. ls -ld |
E. Details of a directory inode itself |
6. .. |
F. Parent directory |
Answer key
1 → B, 2 → A, 3 → D, 4 → C, 5 → E, 6 → F
Practice: Fill in the blank#
- Print working directory:
___ - List all files including hidden:
ls ___ - Long listing of the
projectdirectory entry itself:ls ___ project - Relative path to a file in the current directory:
___/notes.txtor simplynotes.txt - Absolute path example for a lab notes file:
/tmp/linux-lab-pushpjeet/___
Answers
pwd-a(or-la)-ld.notes.txt
Practice: Mini terminal challenge#
Challenge: Absolute and relative navigation#
Goal: Reach the same file two ways.
Setup:
mkdir -p /tmp/linux-lab-pushpjeet/nav/{one,two}
echo hi > /tmp/linux-lab-pushpjeet/nav/one/hello.txt
Tasks:
cd /tmp/linux-lab-pushpjeet/nav/two- Display the file using a relative path with
.. - Display it again with an absolute path
- Run
ls -F ..and confirmone/appears
Verify: Both cat commands print hi.
Stretch: From nav/two, use cd only with relative paths to land in nav/one, then pwd.
Hands-on lab#
Goal: Fluent navigation and listing.
Steps:
- From your home directory,
cdinto the lab folder using an absolute path;pwd. cdintoproject/docsusing a relative path;pwd.- Compare
ls,ls -l,ls -la, andls -lFon the lab root — note differences in your notes. - Run
fileon one text file and one binary (/bin/lsor$(which ls)).
Verify: Your notes include one absolute and one relative path that both refer to the same file.
Stretch: Use ls -R on a small tree and redraw it as an indented outline by hand.
Common mistakes#
- Mixing up
ls project(contents) withls -ld project(the directory itself) - Forgetting that relative paths depend on
pwd - Typing spaces in paths without quoting (Module 9 covers quoting; for now avoid spaces in lab names)
- Assuming
~works inside every program the same way — the shell expands it before most commands run
Summary#
You can locate yourself with pwd, speak in absolute or relative paths, move with cd, and read rich directory listings. That navigation skill is the foundation for viewing and changing files next.