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.
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 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 means “change directory.” In this case, you’ve asked to change to the root directory.
This verifies that you’re working in the root directory.
Lets you see what’s in /.
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.
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.
Changes the directory to practice.
Creates a subdirectory of practice.
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.
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).
Verifies that the original looks just like the copy you made.
mv stands for “move.” You’ve moved the file profile from the current directory into the subdirectory you created earlier.
Verifies that profile is no longer in the current directory.
Verifies that profile has moved to mysubdirectory.
Changes to the subdirectory.
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.
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.
Changes directories to the parent directory – in this case practice, where you just put 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 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.
This moves out of the current directory, and into its parent directory. Now you can type the following:
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.