Debian GNU/Linux : Guide to Installation and Usage

Chapter 5

Chapter 53,880 wordsPublic domain

If you’ve entered several commands, you can keep pressing the Up Arrow key to go back through them. This feature is handy if you’re doing the same thing several times, or if you type a command incorrectly and want to go back to fix it. You can press the Down Arrow key to move in the other direction, toward your more recent commands. If there are no more commands to move to, the computer will beep.

You can also move around on the command line to make changes. The easiest way is with the Left and Right Arrow keys. Try typing whoasmi instead of whoami, and then use the Left Arrow key to move back to the s. You can erase the s with the Backspace or Delete keys.

There are more advanced features as well (no need to memorize them all now, though). Try pressing Ctrl-a. This moves you to the beginning of the line. Ctrl-k (the k stands for “kill”) deletes all characters until the end of the line; try it from the middle of the command line. Using Ctrl-a followed by Ctrl-k, you can delete the entire command line. Ctrl-y pastes the last thing you killed, reinserting it at the current cursor position (y stands for “yank,” as in “yank it back”). Ctrl-e will move the cursor to the end of the command line.

Go ahead and play around with command-line editing to get a feel for it. Experiment.

4.3 Working as Root

Because Debian is a multiuser system, it’s designed to keep any one user or program from breaking the entire system. The kernel will not allow normal users to change important system files. This means that things stay the way they’re supposed to, safe from accidents, viruses, and even malicious pranks. Unlike other operating systems, Debian is safe from these threats. You won’t need an anti-virus program.

However, sometimes you need to change important system files; for example, you might want to install new software or configure your network connection. To do so, you have to have greater powers than a normal user; you must become the _root user_ (also called the _superuser_).

To become root, just log on with the username root and the root password; this was set during installation, as described in section 3.15 on page [*].

At many sites, only the system administrator has the root password, and only the system administrator can do the things that one must be root to do. If you’re using your own personal computer, _you_ are the system administrator, of course. If you don’t have root privileges, you will have to rely on your system administrator to perform any tasks that require root privileges.

Sometimes you’ll have the root password even on a shared corporate or educational server, because the system administrator trusts you to use it properly. In that case, you’ll be able to help administer the system and customize it for your needs. But you should be sure to use the password responsibly, respecting other users at all times.

If you have the password, try logging on as root now. Enter the whoami command to verify your identity. Then _log out immediately_. When you’re root, the kernel will not protect you from yourself, because root has permission to do anything at all to the system. Don’t experiment while you’re root. In fact, don’t do anything as root unless absolutely necessary. This isn’t a matter of security, but rather of stability. Your system will run much better if it can keep you from making mistakes.

You may find the su command more convenient than logging in as root. su allows you to assume the identity of another user, usually root unless you specify someone else. (You can remember that su stands for Super User, though some say it stands for Set UserID.)

Here’s something to try. Log on as yourself—that is, not as root. Then your session will look something like the one in Figure 4.1.

When you’re doing system administration tasks, you should do as much as possible as yourself. Then use su, do the part that requires root privileges, and use the exit command to turn off privileges so you can no longer harm anything.

You can use su to assume the identity of any user on the system, not just root. To do this, type su _user_ where _user_ is the user you want to become. You’ll have to know the user’s password, of course, unless you’re root at the time or the user has no password.

4.4 Virtual Consoles

The Linux kernel supports _virtual consoles_. These provide a way of making your single screen and keyboard seem like multiple terminals that are connected to the same system. Thankfully, using virtual consoles is one of the simplest things about Debian: There are “hot keys” for switching among the consoles quickly. To try it, log in to your system and press Alt-F2 (simultaneously press the left Alt key, and F2, that is, function key number 2).

You should find yourself at another login prompt. Don’t panic: You are now on virtual console (VC) number 2! Log in here and do some things—more whoami commands or whatever—to confirm that this is a real login shell. Now you can return to virtual console number 1 by pressing Alt-F1. Or you can move on to a _third_ virtual console, in the obvious way (Alt-F3).

Debian comes with six virtual consoles enabled by default, which you access with the Alt key and function keys F1 through F6. (Technically, there are more virtual consoles enabled, but only six of them allow you to log in. The others are used for the X Window system or other special purposes.)

If you’re using the X Window system, it will generally start up on the first unused virtual console—probably VC 7. Also, to switch from the X virtual console to one of the first six, you’ll have to add Ctrl to the key sequence. So that’s Ctrl-Alt-F1 to get to VC 1. But you can go from a text VC to the X virtual console using only Alt. If you never leave X, you won’t have to worry about this; X automatically switches you to its virtual console when it starts up.

Once you get used to them, virtual consoles will probably become an indispensable tool for getting many things done at once. (The X Window system serves much the same purpose, providing multiple windows rather than multiple consoles.) You can run a different program on each VC or log on as root on one VC and as yourself on another. Or everyone in the family can use his or her own VC; this is especially handy if you use X, in which case you can run several X sessions at once on different virtual consoles.

4.5 Shutting Down

_Do not just turn off the computer! You risk losing valuable data!_

If you are the only user of your computer, you might want to turn the computer off when you’re done with it.

To avoid possibly weakening some hardware components, only turn off the computer when you’re done for the day. Power up and power down are the two greatest contributors to wear and tear on computer components. Turning the computer on and off once a day is probably the best compromise between your electric bill and your computer’s lifespan.

It’s a bad thing to just press the power switch when you’re done using the computer. It is also bad to reboot the machine (with the Reset button) without first taking proper precautions. The Linux kernel, in order to improve performance, has a disk cache. This means it temporarily stores information meant for permanent storage in RAM. Because memory is thousands of times faster than a disk, this makes many file operations move more quickly. Periodically, the information Linux has in memory is actually written to the disk. This is called _syncing_. In order to turn off or reboot the computer safely, you’ll have to tell the computer to clear everything out of memory and put it in permanent storage.

To reboot, just type reboot or press Ctrl-Alt-Del (that’s Ctrl, Alt, and Delete).

To shut down, you’ll have to log in as root. As root, just type the command shutdown -h now. The sytem will go through the entire shutdown procedure, including the sync command, which clears the disk cache as described above. When you see System halted, it’s safe to turn off the computer. If you have Advanced Power Management (APM) support in your kernel and BIOS, the computer might shut itself off and save you the trouble. APM is common in laptops and is also found in certain desktop mainboards.

5. The Basics

It’s now time to explore the system in more detail. You’ve seen how to log in and shut down the system. In this chapter, we explore the Linux comand line, how Linux deals with files and directories, and some basics on identifying yourself to others.

5.1 The Command Line and Man Pages

We’ve already discussed the command line—that is, commands you type after the shell prompt. This section describes the structure of more complicated command lines.

A minimal command line contains just a command name, such as whoami. But other things are possible. For example, you might type: man whoami. This command requests the online manual for the whoami program (you may have to press the space bar to scroll through the documentation or press q to quit). A more complicated example is man -k PostScript. This command line has three parts. It begins with the command name, man. Then it has an _option_ or _switch_, -k, followed by an _argument_, PostScript. Some people refer to everything except the command name as the _parameters_ of the command. So, options and arguments are both parameters.

Options change the behavior of a command, switching on particular features or functionality. They usually have a - before them. The GNU utilities also have “long forms” for the options; the long form of -k is -apropos. You can enter man -h or man -help to get a full list of options for the man command. Every command will have its own set of options, though most have -help and -version options. Some commands, such as tar, do not require the “-” before their options for historical reasons.

Anything that isn’t an option and isn’t the command name is an _argument_ (in this case, PostScript). Arguments can serve many purposes; most commonly, they are filenames that the command should operate on. In this case, PostScript is the word you want man to search for. In the case of man whoami, the argument was the command you wanted information about.

Here’s a breakdown of the man -k PostScript command line:

man. The command name, tells the computer to look at the manual pages. These provide documentation for commands. For example, man whoami will give you documentation on the whoami command.

-k. The option, changes the behavior of man. Normally man expects a command name, such as whoami, for an argument and looks for documentation of that command. But with the -k or -apropos option, it expects the argument to be a keyword. It then gives a list of all manual pages with that keyword in their description.

PostScript. is the argument; because we used the -k option, it’s the keyword to search for.

-k and PostScript are both parameters.

Go ahead and type man -k PostScript, and you will see a list of all the manual pages on your system that have something to do with PostScript. If you haven’t installed much software, you might see the message PostScript: nothing appropriate instead.

5.1.1 Describing the Command Line

Note: You can skip this section if you want to move on.

There’s a traditional, concise way of describing command _syntax. Syntax_ means the correct ways to combine various options and arguments. For example, if you type man man to get the manual page about man, you’ll see several syntax descriptions beginning with the command name man. One of them will look like this: man -k [-M path] keyword ...

Anything in brackets ([]) is an optional unit. In this case you don’t have to use the -M option, but if you do, you must use a path argument. You must use the -k option and the keyword argument. The ... means that you could have more of whatever came before it, so you could look up several keywords.

Let’s look at one of the more complex descriptions from the man manual page:

man [-c|-w|-tZT device] [-adhu7V] [-m system[,...]] [-L locale] [-p string] [-M path] [-P pager] [-r prompt] [-S list] [-e extension] [[section] page ...] ...

There’s no need to go through all of this (and don’t worry about what it all means), but do pay attention to the organization of the description.

First, clusters of options usually mean you can use one or more of them in different combinations, so -adhu7V means you can also use -h. However, you can’t always use all combinations; this description doesn’t make that clear. For example, -h is incompatible with other options, but you could do man -du. Unfortunately, the description’s format does not make this clear.

Second, the | symbol means “or.” So you can use the -c, the -w, _or_ the -tZT option, followed by a device argument.

Third, notice that you can nest the brackets, because they indicate optional _units_. So if you have a section, you must also have a page, because e page is not optional within the [[section] page] unit.

There’s no need to memorize any of this, just refer to this section as you read documentation.

5.2 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:

◼ Filenames are case-sensitive. That is, MYFILE and MyFile are _different_ files. ◼ The root directory is referred to as simply /. Don’t confuse this “root” with the root user, the user on your system with “super powers.” ◼ Every directory has a name, which can contain any letters or symbols _except_ /. The root directory is an exception; its name is / (pronounced “slash” or “the root directory”), and it cannot be renamed. ◼ While you can use almost any letters or symbols in a filename, in practice it’s a bad idea. It is better to avoid characters that often have special meanings on the command line, including: { } ( ) [ ] ’ ‘ " \/ > < | ; ! # & ^ * % ◼ Also avoid putting spaces in filenames. If you want to separate words in a name, good choices are the period, hyphen, and underscore. You could also capitalize each word, LikeThis. ◼ Each file or directory is designated by a _fully-qualified filename, absolute filename_, or _path_, giving the sequence of directories which must be passed through to reach it. The three terms are synonymous. All absolute filenames begin with the / directory, and there’s a / before each directory or file in the filename. The first / is the name of a directory, but the others are simply separators to distinguish the parts of the filename. ◼ The words used here can be confusing. Take the following example: /usr/share/keytables/us.map.gz. This is a fully-qualified /filename; some people call it a _path_. However, people will also refer to us.map.gz alone as a filename. ◼ There is also another use for the word “path.” The intended meaning is usually clear from the context. ◼ Directories are arranged in a tree structure. All absolute filenames start with the root directory. The root directory has a number of branches, such as /etc and /usr. These subdirectories in turn branch into still more subdirectories, such as /etc/init.d and /usr/local. The whole thing together is called the “directory tree.” ◼ You can think of an absolute filename as a route from the base of the tree (/) to the end of some branch (a file). You’ll also hear people talk about the directory tree as if it were a _family_ tree: Thus subdirectories have “parent,” and a path shows the complete ancestry of a file. ◼ There are also relative paths that begin somewhere other than the root directory. More on this later. ◼ No directory corresponds to a physical device, such as your hard disk. This differs from DOS and Windows, in which all paths begin with a device name such as C:\. The directory tree is meant to be an abstraction of the physical hardware, so you can use the system without knowing what the hardware is. All your files could be on one disk—or you could have 20 disks, some of them connected to a different computer elsewhere on the network. You can’t tell just by looking at the directory tree, and nearly all commands work just the same way no matter what physical device(s) your files are really on.

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

5.2.1 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