{
    "mode": "info",
    "parameter": "realpath",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/realpath/json",
    "generated": "2026-07-26T23:53:13Z",
    "sections": {
        "File: coreutils.info,  Node: realpath invocation,  Prev: mktemp invocation,  Up: File name manipulation": {
            "content": "",
            "subsections": [
                {
                    "name": "18.5 'realpath': Print the resolved file name.",
                    "content": "'realpath' expands all symbolic links and resolves references to '/./',\n'/../' and extra '/' characters.  By default, all but the last component\nof the specified files must exist.  Synopsis:\n\nrealpath [OPTION]... FILE...\n\nThe file name canonicalization functionality overlaps with that of\nthe 'readlink' command.  This is the preferred command for\ncanonicalization as it's a more suitable and standard name.  In addition\nthis command supports relative file name processing functionality.\n\nThe program accepts the following options.  Also see *note Common\noptions::.\n\n'-e'\n'--canonicalize-existing'\nEnsure that all components of the specified file names exist.  If\nany component is missing or unavailable, 'realpath' will output a\ndiagnostic unless the '-q' option is specified, and exit with a\nnonzero exit code.  A trailing slash requires that the name resolve\nto a directory.\n\n'-m'\n'--canonicalize-missing'\nIf any component of a specified file name is missing or\nunavailable, treat it as a directory.\n\n'-L'\n'--logical'\nSymbolic links are resolved in the specified file names, but they\nare resolved after any subsequent '..' components are processed.\n\n'-P'\n'--physical'\nSymbolic links are resolved in the specified file names, and they\nare resolved before any subsequent '..' components are processed.\nThis is the default mode of operation.\n\n'-q'\n'--quiet'\nSuppress diagnostic messages for specified file names.\n\n'--relative-to=DIR'\nPrint the resolved file names relative to the specified directory.\nNote this option honors the '-m' and '-e' options pertaining to\nfile existence.\n\n'--relative-base=DIR'\nPrint the resolved file names as relative if the files are\ndescendants of DIR.  Otherwise, print the resolved file names as\nabsolute.  Note this option honors the '-m' and '-e' options\npertaining to file existence.  For details about combining\n'--relative-to' and '--relative-base', *note Realpath usage\nexamples::.\n\n'-s'\n'--strip'\n'--no-symlinks'\nDo not resolve symbolic links.  Only resolve references to '/./',\n'/../' and remove extra '/' characters.  When combined with the\n'-m' option, realpath operates only on the file name, and does not\ntouch any actual file.\n\n'-z'\n'--zero'\nOutput a zero byte (ASCII NUL) at the end of each line, rather than\na newline.  This option enables other programs to parse the output\neven when that output would contain data with embedded newlines.\n\nExit status:\n\n0 if all file names were printed without issue.\n1 otherwise.\n\n* Menu:\n\n* Realpath usage examples::              Realpath usage examples.\n"
                }
            ]
        },
        "File: coreutils.info,  Node: Realpath usage examples,  Up: realpath invocation": {
            "content": "",
            "subsections": []
        },
        "By default, 'realpath' prints the absolute file name of given files": {
            "content": "(symlinks are resolved, 'words' is resolved to 'american-english'):\n\ncd /home/user\nrealpath /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt\n=> /usr/bin/sort\n=> /tmp/foo\n=> /usr/share/dict/american-english\n=> /home/user/1.txt\n\nWith '--relative-to', file names are printed relative to the given\ndirectory:\n\nrealpath --relative-to=/usr/bin \\\n/usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt\n=> sort\n=> ../../tmp/foo\n=> ../share/dict/american-english\n=> ../../home/user/1.txt\n\nWith '--relative-base', relative file names are printed if the\nresolved file name is below the given base directory.  For files outside\nthe base directory absolute file names are printed:\n\nrealpath --relative-base=/usr \\\n/usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt\n=> bin/sort\n=> /tmp/foo\n=> share/dict/american-english\n=> /home/user/1.txt\n\nWhen both '--relative-to=DIR1' and '--relative-base=DIR2' are used,\nfile names are printed relative to DIR1 if they are located below\nDIR2.  If the files are not below DIR2, they are printed as absolute\nfile names:\n\nrealpath --relative-to=/usr/bin --relative-base=/usr \\\n/usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt\n=> sort\n=> /tmp/foo\n=> ../share/dict/american-english\n=> /home/user/1.txt\n\nWhen both '--relative-to=DIR1' and '--relative-base=DIR2' are used,\nDIR1 must be a subdirectory of DIR2.  Otherwise, 'realpath' prints\nabsolutes file names.\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}