File and Directory Questions

This section looks at some questions about files and directories. These questions include issues with specific commands and examples that illustrate the use of commands to solve particular problems.

How do I determine the absolute pathname of a directory?

Shell scripts that work with directories often need to determine the absolute pathname of a directory to perform the correct operations on these directories.

You can determine the absolute pathname of a directory by using the cd and pwd commands as follows:

ABSPATH=`(cd dir 2> /dev/null && pwd ;)`

Here dir is the name of a directory. This command changes directories to the specified directory, dir, and then displays the full pathname of the directory using the ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.