- List Files and Folders
- List the Contents of Other Folders
- List Folder Contents Using Wildcards
- View a List of Files in Subfolders
- View a List of Contents in a Single Column
- View Contents As a Comma-Separated List
- View Hidden Files and Folders
- Visually Display a File's Type
- Display Contents in Color
- List Permissions, Ownership, and More
- Reverse the Order Contents Are Listed
- Sort Contents by Date and Time
- Sort Contents by Size
- Express File Sizes in Terms of K, M, and G
- Display the Path of Your Current Directory
- Change to a Different Directory
- Change to Your Home Directory
- Change to Your Previous Directory
- Conclusion
Display the Path of Your Current Directory
pwd
Of course, while you’re listing the contents of directories hither and yon, you might find yourself confused about just where you are in the file system. How can you tell in which directory you’re currently working? The answer is the pwd command, which stands for print working directory.
The pwd command displays the full, absolute path of the current, or working, directory. It’s not something you’ll use all the time, but it can be incredibly handy when you get a bit discombobulated.
$ pwd /home/scott/music/new
There is one thing you should be aware of, however, and this can really confuse people. In Chapter 3 you’re going to find out about the ln command (“Create a Link Pointing to Another File or Directory”), so you might want to skip ahead and read that to fully understand what I’m about to show you. Assuming you have, check out the following:
# ls -l lrwxrwxrwx scott scott websites -> /var/www/ $ cd websites $ pwd /websites $ pwd -P /var/www
So there’s a soft link with a source websites that points at a target /var/www. I cd using the soft link and enter pwd. Notice what comes back: the logical directory of /websites, the source of the soft link, which isn’t the actual working target directory of /var/www. This is the default behavior of pwd, equivalent to entering pwd -L (or --logical).
On the other hand, if you enter pwd -P (or --physical), you instead get back the target of the soft link, which is /var/www.
I don’t know about you, but when I use pwd, I usually want to get back the actual physical location (the target), not the logical location (the source). Since I actually prefer the -P option as the default, I like to use an alias in my .bash_aliases file (discussed in Chapter 12’s “Create a New Permanent Alias” section) that looks like this:
alias pwd="pwd -P"
Now you understand not only how to use pwd, but also the gotchas you might run into when you use it.