-->
Previous Table of Contents Next


The Home Directory

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 what’s 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 another’s home directory and read (and copy!) the files stored there (although he can’t 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 else’s home directory, just as it’s rude or nosy to poke around in someone’s office while they’re 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 can’t trust the system administrator (who usually has the root password), don’t use the system!


The location of a user’s home directory is specified by Linux and can’t 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 you’re 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.

Navigating the Linux File System

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!

The pwd Command: Where Am I?

Type pwd at the Linux command prompt. You see


darkstar:~$ pwd

/home/fido

darkstar:~$

This tells you that you’re 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 command’s 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 you’ll see in a moment.

Absolute and Relative Filenames

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 can’t find it.

Sometimes you want to specify a file that isn’t 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