UNIX Shell: Find Out Real Path Of File or Directory

https‮www//:‬.lautturi.com
UNIX Shell: Find Out Real Path Of File or Directory

To find out the real path of a file or directory in a Unix shell, you can use the realpath command. This command resolves any symbolic links and returns the actual path to the file or directory.

For example, if you have a symbolic link named link that points to the file /path/to/file, you can use the following command to find out the real path of the file:

realpath link

Output:

/path/to/file

You can also use the readlink command to find out the real path of a symbolic link. This command returns the target of the symbolic link.

For example:

readlink link

Output:

/path/to/file

You can also use the pwd command to find out the real path of the current working directory. This command returns the absolute path of the current directory, resolving any symbolic links.

For example:

pwd

Output:

/path/to/current/directory

Keep in mind that the realpath and readlink commands may not be available on all Unix systems. In such cases, you can use the ls -l command to find out the real path of a file or symbolic link. This command displays the details of a file or symbolic link, including the real path.

For example:

ls -l link

Output:

lrwxrwxrwx 1 user user 11 Sep 15 14:37 link -> /path/to/file

The real path of the symbolic link link is /path/to/file.

Created Time:2017-10-30 14:27:22  Author:lautturi