next up previous contents index
Next: Processes Up: The Basics Previous: The Command Line and   Contents   Index

Subsections


Files and Directories

Files are a facility for storing and organizing information, analogous to paper documents. They're organized into directories, which are called folders on some other systems. Let's look at the organization of files on a Debian system:

/.
A simple / represents the root directory. All other files and directories are contained in the root directory. If you are coming from the DOS/Windows world, / is very similar to what C:is for DOS, that is the root of the filesystem. A notable difference between DOS and Linux however, is that DOS keeps several filesystems: C: (first hard disk), A: (first floppy disk), and D: (either CD-ROM or second hard disk), whereas Linux has all its files organized above the same / root.
/home/janeq.
This is the home directory of user ``janeq.'' Reading left to right, to get to this directory you start in the root directory, enter directory home, and then enter directory janeq.
/etc/X11/XF86Config.
This is the configuration file for the X Window system. It resides in the X11 subdirectory of the /etc directory. /etc is in turn a subdirectory of the root directory, /.
Things to note:

Don't worry if all this isn't completely clear yet. There are many examples to come.

Using Files: A Tutorial

To use your system, you'll have to know how to create, move, rename, and delete files and directories. This section describes how to do so with the standard Debian commands.

The best way to learn is to try things. As long as you aren't root (and haven't yet created any important personal files), you cannot mess up too seriously. Jump in - type each of these commands at the prompt and press Enter.

pwd
One directory is always considered the current working directory for the shell you're using. You can view this directory with the pwd command, which stands for Print Working Directory. pwd prints the name of the directory you're working in - probably /home/yourname.

ls
ls stands for ``list,'' as in ``list files.'' When you type ls, the system displays a list of all the files in your current working directory. If you've just installed Debian, your home directory may well be empty. If your working directory is empty, ls produces no output, because there are no files to list.

cd /
cd means ``change directory.'' In this case, you've asked to change to the root directory.

pwd
This verifies that you're working in the root directory.

ls
Lets you see what's in /.

cd
Typing cd with no arguments selects your home directory - /home/ yourname - as the current working directory. Try pwd to verify this.

Before continuing, you should know that there are actually two different kinds of filenames. Some of them begin with /, the root directory, such as /etc/profile. These are called absolute filenames because they refer to the same file no matter what your current directory is. The other kind of filename is relative.

Two directory names are used only in relative filenames: . and ... The directory . refers to the current directory, and .. is the parent directory. These are ``shortcut'' directories. They exist in every directory. Even the root directory has a parent directory - it's its own parent!

So filenames that include . or .. are relative, because their meaning depends on the current directory. If I'm in /usr/bin and type ../etc, I'm referring to /usr/etc. If I'm in /var and type ../etc, I'm referring to /etc. Note that a filename without the root directory at the front implicitly has ./ at the front. So you can type local/bin, or ./local/bin and it means the same thing.

A final handy tip: The tilde ~ is equivalent to your home directory. So typing cd ~ is the same as typing cd with no arguments. Also, you can type things like cd ~/practice/mysubdirectory to change to the directory /home/yourname/practice/mysubdirectory. In a similar way, ~myuser is equivalent to the home directory of the user ``myuser,'' which is probably something like /home/myuser; so ~myuser/docs/debian.ps is equivalent to /home/myuser/doc/debian.ps.

Here are some more file commands to try out, now that you know about relative filenames. cd to your home directory before you begin.

mkdir practice
In your home directory, make a directory called practice. You'll use this directory to try out some other commands. You might type ls to verify that your new directory exists.

cd practice
Changes the directory to practice.

mkdir mysubdirectory
Creates a subdirectory of practice.

cp /etc/profile .
cp is short for ``copy.'' /etc/profile is just a random file on your system, don't worry about what it is for now. We've copied it to . (recall that . just means ``the directory I'm in now,'' or the current working directory). So this creates a copy of /etc/profile and puts it in your practice directory. Try typing ls to verify that there's indeed a file called profile in your working directory, alongside the new mysubdirectory.

more profile
This lets you view the contents of the file profile. more is used to view the contents of text files. It's called more because it shows one screenful of the file at a time, and you press the space bar to see more. more will exit when you get to the end of the file, or when you press q (quit).

more /etc/profile
Verifies that the original looks just like the copy you made.

mv profile mysubdirectory
mv stands for ``move.'' You've moved the file profile from the current directory into the subdirectory you created earlier.

ls
Verifies that profile is no longer in the current directory.

ls mysubdirectory
Verifies that profile has moved to mysubdirectory.

cd mysubdirectory
Changes to the subdirectory.

mv profile myprofile
Note that unlike some operating systems, there is no difference between moving a file and renaming it. Thus there's no separate rename command. Note that the second argument to mv can be a directory to move the file or directory into, or it can be a new filename. cp works the same way.

As usual, you can type ls to see the result of mv.

mv myprofile ..
Just as . means ``the directory I'm in now,'' .. means ``parent of the current directory,'' in this case the practice directory you created earlier. Use ls to verify that that's where myprofile is now.

cd ..
Changes directories to the parent directory - in this case practice, where you just put myprofile.

rm myprofile
rm means ``remove,'' so this deletes myprofile. Be careful! Deleting a file on a GNU/Linux system is permanent - there is no undelete. If you rm it, it's gone, forever. Be careful! To repeat, deleting a file on a GNU/Linux system is permanent - there is no undelete. If you rm it, it's gone, forever.

rmdir mysubdirectory
rmdir is just like rm, only it's for directories. Notice that rmdir only works on empty directories. If the directory contains files, you must delete those files first, or alternatively you can use rm -r in place of rmdir.

cd ..
This moves out of the current directory, and into its parent directory. Now you can type the following:

rmdir practice
This will delete the last remnants of your practice session.

So now you know how to create, copy, move, rename, and delete files and directories. You also learned some shortcuts, like typing simply cd to jump to your home directory, and how . and .. refer to the current directory and its parent, respectively. You should also remember the concept of the root directory, or /, and the alias ~ for your home directory.


Dot Files and ls -a

When you type ls, files beginning with a dot are not listed. Traditionally, files that contain configuration information, user preferences, and so on begin with a dot; these are hidden and out of your way while you do your day-to-day work. Sample dot files are ~/.emacs, ~/.newsrc, ~/.bashrc, ~/.xsession, and ~/.fvwmrc. These are used by Emacs, news readers, the Bash shell, the X Window system, and the fvwm window manager, respectively. It is conventional to end the dot filename with rc, but some programs don't. There are also directories beginning with a dot, such as ~/.gimp and ~/.netscape, which store preferences for the Gimp and Netscape.

Sometimes a program will create a dot file automatically; for example, Netscape allows you to edit your preferences with a graphical dialog box and then it saves your choices. Other times you will create them yourself using a text editor; this is the traditional way to do it, but you have to learn the peculiar format of each file - inconvenient at first, but it can give you a lot of power.

To see dot files, you must use the -a option to ls. The long form of -a is -all, if you find that easier to remember. You can also use -A or -almost-all, which displays all dot files except . and ... Remember that . is the current directory, and .. is the parent of the current directory; because these are guaranteed to be in every directory, there is no real reason to list them with ls. You already know they are there.


next up previous contents index
Next: Processes Up: The Basics Previous: The Command Line and   Contents   Index
John Goerzen / Ossama Othman