learn.colinkim.dev

Navigating the filesystem

Learn to move around the filesystem with confidence: pwd, ls, cd, absolute and relative paths, shortcuts like ~ and .., tab completion, and common gotchas.

This is the single most important terminal skill. Everything else builds on it.

The filesystem is a tree of directories. At any moment, your shell has a current working directory — the place it considers “here.” Most commands operate relative to that location.

Where am I? — pwd

pwd

pwd prints the present working directory — the full path to where you currently are.

/Users/alex/Downloads/chess-game

What is here? — ls

ls

ls lists the files and directories in the current directory.

ls /tmp          # list a specific directory
ls -la           # long format, include hidden files
ls src/*.ts      # list only .ts files in src/

Common flags:

  • -l — long format (shows permissions, owner, size, date)
  • -a — show hidden files (those starting with .)
  • -h — human-readable file sizes (used with -l)

Move to a directory — cd

cd src/content

cd changes the current working directory.

cd ..            # go up one level
cd               # go to your home directory
cd ~             # same, go to your home directory
cd /tmp          # go to an absolute path
cd -             # go back to the previous directory

The root directory

On macOS and Linux, the top of the filesystem is /, called the root directory. Every absolute path starts here.

/
/Users/
/Users/ezhang/
/Users/ezhang/Library/

On Windows, each drive has its own root. The root of the C drive is C:\.

The home directory

Your home directory is where your user session starts. On macOS and Linux it is typically /Users/yourname or /home/yourname.

The tilde character ~ is a shortcut for your home directory:

cd ~             # go home
cd ~/Desktop     # go to Desktop

Absolute vs relative paths

An absolute path starts from the root. It begins with / on Unix or a drive letter on Windows. It means the same thing no matter where you are.

/Users/jgreen7/learn/project/src
C:\Users\emily\Programming\learn\src

A relative path is interpreted from your current directory. It does not start with / or a drive letter.

src/content/lessons

If you are in /Users/jgreen7/learn/project, then src/content/lessons resolves to /Users/jgreen7/learn/project/src/content/lessons.

. and ..

Two special directory references:

  • . — the current directory
  • .. — the parent directory (one level up)
./README.md      # README.md in the current directory
../package.json  # package.json in the parent directory

You rarely need ./ for simple commands, but it becomes important when running scripts (covered later).

Hidden files

Files whose names start with a dot . are hidden by convention. They do not appear in a plain ls output.

ls -a            # show hidden files

Common hidden files: .gitignore, .zshrc, .env, .bashrc.

Hidden files are not secret — just conventionally out of the way.

Tab completion

Press Tab while typing a path or command and the shell will attempt to complete it.

cd src/con<Tab>  # completes to src/content/ if unambiguous

If there are multiple matches, pressing Tab twice shows them. Tab completion prevents typos and saves time. Use it constantly.

Case sensitivity

On macOS and Linux, File.txt and file.txt are different files. On Windows, they are usually treated as the same.

This matters when you move between systems. A script that works on your Mac might fail on a Linux server if the case does not match exactly.

Trailing slashes

A trailing slash on a directory path is often optional, but it can change behavior:

ls src           # lists the directory entry itself in some contexts
ls src/          # lists the contents — more explicit that it is a directory

When copying, a trailing slash on the source can mean “copy the contents of” rather than “copy the directory”:

cp -r src/ dest/    # copies contents of src/ into dest/
cp -r src dest/     # copies src/ as a subdirectory inside dest/

The behavior varies slightly between systems. When in doubt, check the result with ls after running the command.

Practice exercise

Try this sequence in your terminal:

pwd              # where are you?
cd ~             # go home
pwd              # confirm
ls -a            # see hidden files
cd Desktop
pwd
cd ..
pwd
cd /tmp
pwd
cd -             # go back to where you were
pwd

The main idea to carry forward

The filesystem is a tree. You are always at one node in that tree. Paths are addresses that tell the shell where to look, and they can be absolute (from the root) or relative (from where you are). Tab completion, ., .., and ~ are navigation shortcuts. Once you internalize this model, moving around becomes automatic.

Progress

Quick checks

No quick checks in this lesson.

Mark lesson manually or answer quick checks to track progress.