-
-
Notifications
You must be signed in to change notification settings - Fork 3
Linux realpath Guide
Mattscreative edited this page Nov 20, 2025
·
3 revisions
Complete beginner-friendly guide to realpath on Linux, covering Arch Linux, CachyOS, and other distributions including resolving absolute paths, canonical paths, and path normalization.
realpath resolves absolute canonical paths.
Uses:
- Absolute paths: Get full path
- Resolve symlinks: Follow all links
- Normalize paths: Clean up paths
- Scripts: Use in automation
Why it matters:
- Path resolution: Get real paths
- Symlink resolution: Follow all links
- Scripting: Reliable paths in scripts
Basic usage:
# Resolve path
realpath file.txt
# Shows absolute canonical pathResolve relative:
# Resolve relative path
realpath ../file.txt
# Converts to absoluteResolve links:
# Follow all symlinks
realpath link.txt
# Resolves entire chainDon't follow:
# Don't resolve symlinks
realpath -s file.txt
# -s = no symlinksUse in scripts:
#!/bin/bash
SCRIPT_DIR=$(realpath "$(dirname "$0")")
echo "Script directory: $SCRIPT_DIR"Clean paths:
# Normalize path
realpath ./.././file.txt
# Removes . and ..Check path:
# Verify file exists
ls -la file.txt
# Check permissions
stat file.txtThis guide covered realpath usage, path resolution, and canonical paths for Arch Linux, CachyOS, and other distributions.
- readlink Guide - Read link targets
- pwd Guide - Current directory
- cd Guide - Change directory
-
realpath Documentation:
man realpath
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.