Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

paths-bash

Paths in Bash

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Paths in Bash: the syntax, patterns, and safety habits you need before advancing in Bash.

Teams still ship Paths in Bash in Bash codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Paths in Bash in contexts like: CI jobs, server maintenance, local dev automation, and Git hooks.

Read each lesson, copy bash examples into your own terminal, and complete the lesson MCQs—there is no in-browser runner for security reasons.

When you can explain the previous lesson's ideas without copying starter code.

Paths describe file locations. Bash distinguishes absolute paths (starting with /) and relative paths (from the current directory).

Navigation

pwd
cd /tmp
pwd
cd -
pwd

cd - jumps to the previous directory—handy when toggling between project roots.

Special path tokens

cd ~
echo "$HOME"
cd .
cd ..
pwd
ls -la .

. is current directory; .. is parent; ~ expands to home.

Basename and dirname

path="/var/log/system.log"
echo "dir: $(dirname "$path")"
echo "file: $(basename "$path")"

Quote variables so paths with spaces survive word splitting.

Important interview questions and answers

  1. Q: Absolute vs relative?
    A: Absolute starts at filesystem root; relative starts from current working directory.
  2. Q: Why quote $path?
    A: Spaces or glob characters in paths break unquoted expansions.

Self-check

  1. What command prints the working directory?
  2. What does .. mean in a path?

Tip: Quote paths: cd "$dir"—spaces in filenames break unquoted expansions.

Interview prep

Absolute path?

Starts at filesystem root /.

dirname/basename?

Split path into directory and file components.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Absolute vs relative?
  • cd - use?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump