Labs ICT
⭐ Pro Login

File Paths

2 min read | Unix Tutorial
⭐

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

To navigate well, you need to understand paths. Every file and directory in Unix has an address. Paths come in two flavors — absolute and relative — and knowing the difference keeps you from getting lost.

Absolute paths

An absolute path starts from the root of the file system — the very top. The root is represented by a single forward slash: /.


/home/you/Documents/file.txt
/etc/nginx/nginx.conf
/usr/bin/python3
    

Everything after the first / is a directory or file along the chain. Absolute paths work from anywhere — they don't depend on where you're currently sitting.

Relative paths

A relative path starts from your current working directory. It doesn't begin with /.


$ pwd
/home/you
$ cd Documents
    

When I typed cd Documents, that was a relative path — it assumed I meant /home/you/Documents because /home/you was my current location.

Using . and .. in paths

Relative paths often use the special entries from earlier:


$ pwd
/home/you/Documents
$ cd ../Downloads
$ pwd
/home/you/Downloads
    

That .. says "go up one level to /home/you, then into Downloads." You can chain this:


$ cd ../../var/log
    

That goes up two levels from wherever you are, then down into /var/log.

The home shortcut: ~

The tilde ~ is shorthand for your home directory. These are all equivalent:


$ cd /home/you
$ cd ~
$ cd
    

You can also use ~ in longer paths:


$ ls ~/Documents/projects
    

That lists the contents of projects inside your Documents directory, no matter where you currently are in the file system.

Quick tip: when to use which

Use absolute paths when you want to be precise — in scripts or when telling someone else the exact location of a file. Use relative paths when you're working interactively and want less typing. Tab completion works with both, so you rarely need to type more than a few characters either way.