If you've ever pasted a file path and had it not work, the absolute/relative distinction is often why. Understanding it takes two minutes and will save you from a common class of errors in scripts, configs, Dockerfiles, CI pipelines, and documentation.

What is an Absolute Path?

An absolute path describes a file's location starting from the root of the filesystem — the very top level. On macOS (and all Unix systems), the root is represented by a forward slash /.

Absolute paths always start with / and include every directory from root to the file:

/Users/alex/Projects/my-app/src/components/Button.tsx

No matter where you are on the filesystem or which user is running a command, this path always refers to the exact same file. That's the key property of an absolute path: it's unambiguous.

The tilde shorthand (~)

macOS (and most Unix shells) let you use ~ as a shorthand for your home directory. So:

~/Documents/report.pdf
# is equivalent to:
/Users/alex/Documents/report.pdf

Note: ~-prefixed paths are technically absolute (they resolve to an absolute path), but they're user-relative — the same string means a different path for different users.

What is a Relative Path?

A relative path describes a file's location relative to the current working directory — wherever you are right now in the filesystem.

If your terminal's current directory is /Users/alex/Projects/my-app, then these are equivalent:

# Absolute path
/Users/alex/Projects/my-app/src/components/Button.tsx

# Relative path (from /Users/alex/Projects/my-app)
src/components/Button.tsx

# Also a relative path (using .. to go up one level)
../my-app/src/components/Button.tsx

Relative paths are shorter and more portable, but their meaning changes depending on where you run them from. That's their key property: they depend on context.

Special relative path tokens

What is a Git-Relative Path?

A git-relative path is a special case of a relative path: it's relative to the root of a Git repository, not to the current working directory.

# Git repo root: /Users/alex/Projects/my-app
# File: /Users/alex/Projects/my-app/src/components/Button.tsx
# Git-relative path: src/components/Button.tsx

Git-relative paths are useful because they stay the same for everyone on the team — regardless of where each person checked out the repo. src/components/Button.tsx means the same thing for Alex on macOS as it does for Brenda on Linux.

Pathly's "Copy Git Path" generates this automatically: right-click any file inside a Git repo, choose Copy Git Path, and Pathly finds the nearest .git folder and computes the relative path from there.

When to Use Each

Scenario Use Absolute Use Relative / Git-Relative
cron jobs & launchd ✓ Always — cron has no predictable working dir ✕ Risky
Shell scripts (system-wide) ✓ Safer ⚠ Only if you set $SCRIPT_DIR first
Shell scripts (repo-local) ⚠ Breaks for other users ✓ Portable
Git commit messages & PRs ✕ Exposes your home dir, breaks cross-OS ✓ Use git-relative path
README & documentation ✕ Won't match other users' setups ✓ Repo-relative paths
Dockerfile / CI configs ⚠ Only for paths inside the container ✓ Relative to repo root
Pasting into Terminal commands ✓ Unambiguous, always works ✓ Works if you're in the right dir
Browser / Electron app file loading ⚠ Use file:// URL instead ✕ Browsers don't have a working dir

Practical macOS Examples

Absolute path — cron job

# In crontab — must use absolute paths because cron's $PATH and $HOME
# are not set to your usual values
0 9 * * * /Users/alex/scripts/backup.sh >> /Users/alex/logs/backup.log 2>&1

Git-relative path — commit message

Fix null check in src/utils/validate.ts

The function was not handling undefined input when called from
components/Form.tsx line 42. See docs/api/validation.md for the
updated contract.

Relative path — Dockerfile

COPY src/ /app/src/
COPY package.json /app/
WORKDIR /app

Portable shell script — using $SCRIPT_DIR

#!/bin/bash
# Get the directory where this script lives
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

# Now use paths relative to it — works for anyone, anywhere
source "$SCRIPT_DIR/config.sh"
cp "$SCRIPT_DIR/template.txt" "$SCRIPT_DIR/../output/"

Copying Paths on macOS — Which Format Do You Need?

When you need a path on Mac, Pathly gives you instant access to all formats from a single right-click:

Never wonder which path format you need — get all five in one right-click, always ready to paste.

Get Pathly — $4.99

Frequently asked questions

What is an absolute path on Mac?

An absolute path starts from the filesystem root (/) and includes every directory down to the file. Example: /Users/alex/Documents/report.pdf. It always refers to the same file, regardless of your current working directory.

What is a relative path on Mac?

A relative path is specified relative to your current working directory. If you're in /Users/alex/Documents, the relative path to report.pdf is simply report.pdf. If you're in /Users/alex, it would be Documents/report.pdf.

Does ~ count as an absolute path?

~ is expanded by the shell to your home directory (/Users/yourname), so ~/Documents/report.pdf resolves to an absolute path. However, because it's user-dependent, it's considered "home-relative" rather than purely absolute — a different user running the same path gets a different file.

Should I use absolute or relative paths in my shell scripts?

For cron jobs, use absolute paths always — cron doesn't set up your normal shell environment. For repo-local scripts meant to be shared, use paths relative to the script's own location (SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"). This makes them portable across different machines and users.