Paths and Links
Absolute vs relative paths, symlinks, hard links, and ln
Skills taught: linux.absolute-paths, linux.relative-paths, linux.symlinks, linux.ln
Absolute vs relative paths
Absolute path — starts from / (the root)
/home/alice/projects/myapp/src/index.js
/etc/nginx/nginx.conf
/usr/bin/python3
→ Always works regardless of where you are
→ Use in scripts and config files for reliability
Relative path — starts from your current directory
src/index.js (from /home/alice/projects/myapp/)
./deploy.sh (./ = current directory explicitly)
../config/settings.py (../ = go up one level)
../../shared/utils (go up two levels)
→ Shorter, but depends on current working directory
→ Use in Makefiles, package.json scripts, Dockerfiles
Special path shortcuts:
~ home directory (/home/alice)
. current directory
.. parent directory
- previous directory (for cd -)
Symbolic links (symlinks)
# Create a symbolic link
ln -s /usr/local/bin/python3.11 /usr/local/bin/python3
# TARGET (real file) LINK (the shortcut)
# Common use: version management
ln -s node_modules/.bin/webpack webpack
# Link a config file
ln -s ~/dotfiles/.bashrc ~/.bashrc # dotfile management
# See what a symlink points to
ls -la /usr/local/bin/python3
# → /usr/local/bin/python3 -> /usr/local/bin/python3.11
# Remove a symlink (do NOT use rm -rf on a dir symlink)
rm link_name # removes the link, not the target
unlink link_name # same thing, more explicit
# Check if something is a symlink
file /usr/local/bin/python3 # 'symbolic link to ...'
readlink -f /usr/local/bin/python3 # print the resolved path
Symbolic link (soft link) Hard link
───────────────────────── ──────────
Points to a PATH Points to the same inode (data)
Can cross filesystems Must be on same filesystem
Can link to directories Cannot link to directories
Broken if target moves/deleted Survives target being renamed/moved
ls shows l in permissions ls shows - (regular file)
Used everywhere in practice Rarely used directly
Frequently Asked Questions
Why do I see -> in ls output?
The -> shows a symlink and its target: lrwxrwxrwx 1 root root 7 Jan 1 /bin -> usr/bin means /bin is a symlink pointing to usr/bin. Many system directories (/bin, /lib, /sbin) are symlinks on modern Linux systems for historical compatibility.