Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

realpath(1) [debian man page]

REALPATH(1)							      Debian							       REALPATH(1)

NAME
realpath - return the canonicalised absolute pathname SYNOPSIS
realpath [-s|--strip] [-z|--zero] filename ... realpath --h|--help realpath --v|--version DESCRIPTION
realpath converts each filename argument to an absolute pathname, which has no components that are symbolic links or the special . or .. directory entries. (See realpath(3) for more information.) Each path component in the filename must exist, otherwise realpath will fail and non-zero exit status will be returned. Please note that mostly the same functionality is provided by the `-e' option of the readlink(1) command. When the -s option is used realpath only removes the . and .. directories, but not symbolic links from filename. If the given filename argument is relative (i.e. does not start with `/'), realpath -s prepends to it the current directory name as obtained from the getcwd(2) system call before further processing. Each converted pathname is output to the standard output, on its own line. OPTIONS
-s, --strip Only strip . and .., components, but do not resolve symbolic links. -z, --zero Separate output filenames with the null character instead of newline, so it can be used with the `-0' option of xargs(1). -h, --help Print short usage information. -v, --version Show realpath's version number. EXAMPLES
For the examples below let's suppose that /usr/bin/X11 is a symbolic link, pointing to directory /usr/bin. Example 1 Regardless of what the current directory is realpath /../usr/bin/X11/./xterm prints /usr/bin/xterm but realpath -s /../usr/bin/X11/./xterm outputs /usr/bin/X11/xterm Example 2 When the current directory is /usr/bin/X11 (which is still a symbolic link to /usr/bin), the output of both realpath ./xterm and realpath -s ./xterm will be /usr/bin/xterm Example 3 Providing that the current directory is /home/user (and the directory exists before and during the realpath run), the command realpath ../path/to/some/./non-existent/./directory/../or/../file will fail with the following error ../path/to/some/./non-existent/./directory/../or/../file: No such file or directory but realpath -s ../path/to/some/./non-existent/./directory/../or/../file will return /home/path/to/some/non-existent/file EXIT STATUS
realpath returns a zero exit code when all pathnames were successfully converted. In case of any errors (e.g. missing or unavailable directories in the path), realpath prints error message to stderr and returns a non-zero exit code. SEE ALSO
basename(1), dirname(1), readlink(1), chase(1), realpath(3) BUGS
Hopefully none :) If you find some, please report them via the normal Debian bug reporting system, see the file /usr/share/doc/debian/bug-reporting.txt in the package doc-debian or the reportbug(1) man page. AUTHOR
Originally written by Lars Wirzenius <liw@iki.fi>, as a part of the dwww package. Robert Luberda <robert@debian.org> currently maintains and extends it. realpath is licensed via the GNU General Public License. While it has been written for Debian, porting it to other systems is strongly encouraged. Debian October 16th, 2011 REALPATH(1)

Check Out this Related Man Page

REALPATH(3P)						     POSIX Programmer's Manual						      REALPATH(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
realpath - resolve a pathname SYNOPSIS
#include <stdlib.h> char *realpath(const char *restrict file_name, char *restrict resolved_name); DESCRIPTION
The realpath() function shall derive, from the pathname pointed to by file_name, an absolute pathname that names the same file, whose reso- lution does not involve '.', '..', or symbolic links. The generated pathname shall be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes, in the buffer pointed to by resolved_name. If resolved_name is a null pointer, the behavior of realpath() is implementation-defined. RETURN VALUE
Upon successful completion, realpath() shall return a pointer to the resolved name. Otherwise, realpath() shall return a null pointer and set errno to indicate the error, and the contents of the buffer pointed to by resolved_name are undefined. ERRORS
The realpath() function shall fail if: EACCES Read or search permission was denied for a component of file_name. EINVAL The file_name argument is a null pointer. EIO An error occurred while reading from the file system. ELOOP A loop exists in symbolic links encountered during resolution of the path argument. ENAMETOOLONG The length of the file_name argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}. ENOENT A component of file_name does not name an existing file or file_name points to an empty string. ENOTDIR A component of the path prefix is not a directory. The realpath() function may fail if: ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument. ENAMETOOLONG Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}. ENOMEM Insufficient storage space is available. The following sections are informative. EXAMPLES
Generating an Absolute Pathname The following example generates an absolute pathname for the file identified by the symlinkpath argument. The generated pathname is stored in the actualpath array. #include <stdlib.h> ... char *symlinkpath = "/tmp/symlink/file"; char actualpath [PATH_MAX+1]; char *ptr; ptr = realpath(symlinkpath, actualpath); APPLICATION USAGE
None. RATIONALE
Since the maximum pathname length is arbitrary unless {PATH_MAX} is defined, an application generally cannot supply a resolved_name buffer with size {{PATH_MAX}+1}. FUTURE DIRECTIONS
In the future, passing a null pointer to realpath() for the resolved_name argument may be defined to have realpath() allocate space for the generated pathname. SEE ALSO
getcwd(), sysconf(), the Base Definitions volume of IEEE Std 1003.1-2001, <stdlib.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 REALPATH(3P)
Man Page