Running Linux, 5th Edition - Matthias Kalle Dalheimer [73]
As you can see, the components of a directory are separated by slashes. The term pathname is often used to refer to this slash-separated list.
What directory is /home in? The directory named /, of course. This is called the root directory. We have already mentioned it when setting up filesystems.
When you log in, the system puts you in your home directory. To verify this, use the "print working directory," or pwd , command:
$ pwd
/home/mdw
The system confirms that you're in /home/mdw.
You certainly won't have much fun if you have to stay in one directory all the time. Now try using another command, cd , to move to another directory:
$ cd /usr/bin
$ pwd
/usr/bin
$ cd
Where are we now? A cd with no arguments returns us to our home directory. By the way, the home directory is often represented by a tilde (~). So the string ~/programs means that programs is located right under your home directory.
While we're thinking about it, let's make a directory called ~/programs. From your home directory, you can enter either:
$ mkdir programs
or the full pathname:
$ mkdir /home/mdw/programs
Now change to that directory:
$ cd programs
$ pwd
/home/mdw/programs
The special character sequence .. refers to the directory just above the current one. So you can move back up to your home directory by typing the following:
$ cd ..
You can also always go back to your home directory by just typing:
$ cd
no matter where in the directory hierarchy you are.
The opposite of mkdir is rmdir, which removes directories :
$ rmdir programs
Similarly, the rm command deletes files . We won't show it here because we haven't yet shown how to create a file. You generally use the vi or Emacs editor for that (see Chapter 19), but some of the commands later in this chapter will create files too. With the -r (recursive) option, rm deletes a whole directory and all its contents. (Use with care!)
At this point, we should note that the graphical desktop environments for Linux, such as KDE and GNOME, come with their own file managers that can perform most of the operations described in this chapter, such as listing and deleting files, creating directories, and so forth. Some of them, like Konqueror (shipped with KDE) and the web browser in that environment, are quite feature-rich. However, when you want to perform a command on many files, which perhaps follow a certain specification, the command line is hard to beat in efficiency, even it takes a while to learn. For example, if you wanted to delete all files in the current directory and all directories beneath that which start with an r and end in .txt, the so-called Z shell (zsh) would allow you to do that with one line:
$ rm **/r*.txt
More about these techniques later.
Listing Files
Enter ls to see what is in a directory. Issued without an argument, the ls command shows the contents of the current directory. You can include an argument to see a different directory:
$ ls /home
Some systems have a fancy ls that displays special files—such as directories and executable files—in bold, or even in different colors. If you want to change the default colors, edit the file /etc/DIR_COLORS, or create a copy of it in your home directory named .dir_colors and edit that.
Like most Unix commands, ls can be controlled with options that start with a hyphen (-). Make sure you type a space before the hyphen. One useful option for ls is -a for "all," which will reveal to you riches that you never imagined in your home directory:
$ cd
$ ls -a
. .bashrc .fvwmrc
.. .emacs .xinitrc
.bash_history .exrc
The single dot refers to the current directory, and the double dot refers to the directory right above it. But what are those other