-->
Previous | Table of Contents | Next |
Linux provides each user with his or her own directory called the home directory. Within this home directory, users can store their own files and create subdirectories. Users generally have complete control over whats found in their home directories. Because there are usually no Linux system files or files belonging to other users in your home directory, you can create, name, move, and delete files and directories as you see fit.
Warning:
Your home directory does not provide privacy! Normally, any user can go into anothers home directory and read (and copy!) the files stored there (although he cant delete or change the files). When Linux creates your home directory, it in effect provides you with an open office cubicle whose desk and filing cabinet drawers are unlocked.You must lock up everything you want to keep private. (This topic is covered in Chapter 9, File and Directory Permissions.) It is generally considered rude or nosy to poke around in someone elses home directory, just as its rude or nosy to poke around in someones office while theyre away from their desk, but the world is full of nosy and rude people so you must take precautions!
Note that anyone logged in as root can read and manipulate all the files on the system, including files that users have locked up. If you cant trust the system administrator (who usually has the root password), dont use the system!
The location of a users home directory is specified by Linux and cant be changed by the user. This is both to keep things tidy and to preserve system security. The location of your home directory depends on which version of Linux youre using and how the system installed itself, but usually it is something like /home/tim or /usr/tim, where tim is the login name. When you log into the system, you are placed in your home directory by default.
Fortunately, navigating the Linux file system is simple. There are only two commands to be learned, and one of them has absolutely no options or parameters!
Type pwd at the Linux command prompt. You see
darkstar:~$ pwd /home/fido darkstar:~$
This tells you that youre currently in the directory /home/fido. (If you are logged in under a different username, you will see that name in place of fido.) This is your home directory. As we mentioned earlier, when you log in, Linux always places you in your home directory.
The letters pwd stand for print working directory. Again, a commands name or function has been cut down to a few easy-to-type characters. (You will often see the term current directory used in place of working directory.)
You might be wondering what working directory or being in a directory really means. It simply means that Linux commands, by default, perform their actions in your working directory. For instance, when you run ls, you are shown only the files in your working directory. If you want to create or remove files, they will be created or removed in your working directory. You can change your working directory with the cd command, as youll see in a moment.
If you specify only the name of a file, Linux looks for that file in your working directory. For example, more myfile lets you read the contents of the file myfile. But myfile must be in your current working directory or the more command cant find it.
Sometimes you want to specify a file that isnt in your current directory. In this case, you must then specify the name of the directory the file is in, as well as the name of the file itself. If, for example, your current directory has a subdirectory called novel which contains a file called chapter_1, you could type more novel/chapter_1 which tells more that it should look in the subdirectory novel for the file chapter_1. This is called a relative filename. You are specifying the location of chapter_1 relative to where you are now, in the subdirectory novel, which in turn is found in your current directory. If you have changed your working directory, the relative filename will no longer work.
Two special directory specifications are . and ... The single period . always stands for the directory you are currently in, and .. stands for the parent directory of your current directory. (You will see how . and .. are used later in this chapter.) Any filename that includes . or .. is, by definition, a relative filename.
A filename that is valid from any location is called an absolute filename. Absolute filenames always begin with /, signifying the root directory. So if you specify a filename as /home/fido/novel/chapter_1, there is no doubt as to where the file is located. Every file on your system has a unique absolute filename. You can use the absolute filename to figure out what Linux is doing when you specify a filename. In the example just mentioned, Linux will start in the root directory / and look for a subdirectory called home. Linux makes /home the current directory temporarily and looks for a directory called fido, then makes that current, looks for novel and makes that current. Once in novel, Linux looks for a file or directory called chapter_1. You can read the absolute filename like a road map, telling you how to navigate the Linux file system.
Previous | Table of Contents | Next |