info > realpath

📖 NAME

realpath — Print the resolved file name.

🚀 Quick Reference

Use CaseCommandDescription
🔗 Resolve symbolic links to absolute pathrealpath FILEExpands all symlinks, resolves ., .., and extra /
✅ Ensure all components existrealpath -e FILEFail if any component is missing or unavailable
❓ Treat missing components as directoriesrealpath -m FILEAllow missing path components (treat as directory)
📂 Get relative path from a directoryrealpath --relative-to=DIR FILEPrint resolved path relative to DIR
🔀 Conditional relative/absoluterealpath --relative-base=DIR FILERelative if under DIR, else absolute
🔇 Suppress errorsrealpath -q FILESuppress diagnostic messages for missing files
🔗 No symlink resolutionrealpath -s FILEOnly resolve ., .., and extra /

📝 DESCRIPTION

realpath expands all symbolic links and resolves references to /./, /../ and extra / characters. By default, all but the last component of the specified files must exist.

realpath [OPTION]... FILE...

The file name canonicalization functionality overlaps with that of the readlink command. This is the preferred command for canonicalization as it's a more suitable and standard name. In addition this command supports relative file name processing functionality.

⚙️ OPTIONS

🚪 Exit Codes

📚 EXAMPLES

📖 Realpath usage examples

By default, realpath prints the absolute file name of given files (symlinks are resolved, words is resolved to american-english):

cd /home/user
realpath /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
=> /usr/bin/sort
=> /tmp/foo
=> /usr/share/dict/american-english
=> /home/user/1.txt

With --relative-to, file names are printed relative to the given directory:

realpath --relative-to=/usr/bin \
         /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
=> sort
=> ../../tmp/foo
=> ../share/dict/american-english
=> ../../home/user/1.txt

With --relative-base, relative file names are printed if the resolved file name is below the given base directory. For files outside the base directory absolute file names are printed:

realpath --relative-base=/usr \
         /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
=> bin/sort
=> /tmp/foo
=> share/dict/american-english
=> /home/user/1.txt

When both --relative-to=DIR1 and --relative-base=DIR2 are used, file names are printed relative to DIR1 if they are located below DIR2. If the files are not below DIR2, they are printed as absolute file names:

realpath --relative-to=/usr/bin --relative-base=/usr \
         /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
=> sort
=> /tmp/foo
=> ../share/dict/american-english
=> /home/user/1.txt

When both --relative-to=DIR1 and --relative-base=DIR2 are used, DIR1 must be a subdirectory of DIR2. Otherwise, realpath prints absolute file names.

realpath
📖 NAME 🚀 Quick Reference 📝 DESCRIPTION ⚙️ OPTIONS 🚪 Exit Codes 📚 EXAMPLES
📖 Realpath usage examples

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-31 09:10 @216.73.217.152
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^