coreutils: Realpath usage examples
1
1 18.5.1 Realpath usage examples
1 ------------------------------
1
1 By default, ‘realpath’ prints the absolute file name of given files
1 (symlinks are resolved, ‘words’ is resolved to ‘american-english’):
1
1 cd /home/user
1 realpath /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
1 ⇒ /usr/bin/sort
1 ⇒ /tmp/foo
1 ⇒ /usr/share/dict/american-english
1 ⇒ /home/user/1.txt
1
1 With ‘--relative-to’, file names are printed relative to the given
1 directory:
1
1 realpath --relative-to=/usr/bin \
1 /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
1 ⇒ sort
1 ⇒ ../../tmp/foo
1 ⇒ ../share/dict/american-english
1 ⇒ ../../home/user/1.txt
1
1 With ‘--relative-base’, relative file names are printed _if_ the
1 resolved file name is below the given base directory. For files outside
1 the base directory absolute file names are printed:
1
1 realpath --relative-base=/usr \
1 /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
1 ⇒ bin/sort
1 ⇒ /tmp/foo
1 ⇒ share/dict/american-english
1 ⇒ /home/user/1.txt
1
1 When both ‘--relative-to=DIR1’ and ‘--relative-base=DIR2’ are used,
1 file names are printed relative to DIR1 _if_ they are located below
1 DIR2. If the files are not below DIR2, they are printed as absolute
1 file names:
1
1 realpath --relative-to=/usr/bin --relative-base=/usr \
1 /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
1 ⇒ sort
1 ⇒ /tmp/foo
1 ⇒ ../share/dict/american-english
1 ⇒ /home/user/1.txt
1
1 When both ‘--relative-to=DIR1’ and ‘--relative-base=DIR2’ are used,
1 DIR1 _must_ be a subdirectory of DIR2. Otherwise, ‘realpath’ prints
1 absolutes file names.
1