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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.