Опубликован: 06.08.2012 | Доступ: свободный | Студентов: 1156 / 24 | Оценка: 5.00 / 5.00 | Длительность: 53:41:00
Лекция 7:

The tools of the trade

Аннотация: Users and groups; Gaining access; The KDE desktop; The fvwm2 window manager; Changing the X display; Getting a shell; Files and file names; Differences from Microsoft; The Emacs editor; Stopping the system.
Ключевые слова: AND, FROM, hard, disk, if, new, First, with, CAN, SEE, NOT, GET, graphical display, still, log, password, WHERE, go, space, this, book, explain, LIKE, transition, Prior, experience, Unix, find, information, power, peek, TIM, edition, release, fact, back, ONE, MS-DOS, attempt, Command, Line, interface, chapter, look, perspective, computer, background, platform, used, graphical interface, very, emphasis, text, primitive, true, point, AS, result, MOST, important, tools, shell, issue, system, editor, difference, PC, USER, TIME, IDEA, ALL, Windows, Active, activity, while, letter, testing, Registered, registration, shoulder, incident, security problem, exploit, current directory, access permission, login, create, choice, Graphics, running, switch, virtual terminal, example, server, conventional, logging, remote system, INTR, control character, pascal program, prompt, environment, default, change, understanding, part, list, high resolution, searching, NEXT, ID, RFC, format, mail, terminal, device, useful, home directory, support, symbolism, enter, re-execute, exclamation mark, screen, startup, empty, documentation, available, VIA, help, icon, Panel, bottom, life, DESCRIPTION, DISTINCT, Top, optional, Menu, reserved, convenience, iconify, terminal emulation, spreadsheet, active window, mouse button, power connector, left button, auxiliary, terminology, title bar, middle button, integrated environment, significant, approach, manager, disk space, processor time, real estate, reason, choose, Basic, style, task bar, cross-hatching, direct access, submenu, tweak, set, specified, resolution, additional, CASE, previous, Left, right, keypad, numeric keypad, keyboard, wrap, keystroke, rendition, display memory, pixel depth, display card, SAW, configuration, Button, mouse, LAWN, hyphen, subdirectory, tab character, behaviour, legitimate, underscore, environment variable, class file, store, Data, directory, period, form, UPPER, lower case, meaning, backslash, programming language, method, Character, EXCEPT, long, alternative, shift, exception, root, addition, binary, ASCII, end, string, input, sensitivity, DID, Web, directory entry, parent directory, root directory, square bracket, input data, output data, abbreviate, write error, output file, output stream, prove, arbitrary, programming model, rewind, executable program, full-screen, time zone, local time, mailing list, compromise, beginner, mistake, type error, core dump, input queue, recall, octal, upper case, fixed-width font, IAD, handbook

So now you have installed FreeBSD, and it successfully boots from the hard disk. If you're new to FreeBSD, your first encounter with it can be rather puzzling. You probably didn't expect to see the same things you know from other platforms, but you might not have expected what you see either:

   FreeBSD (freebie.example.org) (ttyvO)
login:

If you have installed xdm, you'll at least get a graphical display, but it still asks you to log in and provide a password. Where do you go from here?

There isn't space in this book to explain everything there is about working with FreeBSD, but in the following few chapters I'd like to make the transition easier for people who have prior experience with Microsoft platforms or with other favours of UNIX. You can find a lot more information about these topics in UNIX for the Impatient, by Paul W. Abrahams and Bruce R. Larson, UNIX Power Tools, by Jerry Peek, Tim O'Reilly, and Mike Loukides, and UNIX System Administration Handbook, by Evi Nemeth, Garth Snyder, Scott Seebass, and Trent R. Hein. The third edition of this book also covers FreeBSD Release 3.2. See Appendix A, Bibliography, for more information.

If you've come from Microsoft, you will notice a large number of differences between UNIX and Microsoft, but in fact the two systems have more in common than meets the eye. Indeed, back in the mid-80s, one of the stated goals of MS-DOS 2.0 was to make it more UNIX-like. You be the judge of how successful that attempt was, but if you know The MS-DOS command-line interface, you'll notice some similarities in the following sections.

In this chapter, we'll look at FreeBSD from the perspective of somebody with computer experience, but with no UNIX background. If you do have a UNIX background, you may still find it interesting.

If you're coming from a Microsoft platform, you'll be used to doing just about everything with a graphical interface. In this book I recommend that you use X and possibly a desktop, but the way you use it is still very different. FreeBSD, like other UNIX-like systems, places much greater emphasis on the use of text. This may seem primitive, but in fact the opposite is true. It's easier to point and click than to type, but you can express yourself much more accurately and often more quickly with a text interface.

As a result, the two most important tools you will use with FreeBSD are the shell and the editor. Use the shell to issue direct commands to the system, and the editor to prepare texts. We'll look at these issues in more detail in this chapter. In "Тaking control" , Taking control, we'll look at other aspects of the system. First, though, we need to get access to the system.

Users and groups

Probably the biggest difference between most PC operating systems and FreeBSD also takes the longest to get used to: FreeBSD is a multi-user, multi-tasking system. This means that many people can use the system at once, and each can do several things at the same time. You may think "Why would I want to do that?" Once you've got used to this idea, though, you'll never want to do without it again. If you use the X Window System, you'll find that all windows can be active at the same time—you don't have to select them. You can monitor some activity in the background in another window while writing a letter, testing a program, or playing a game.

Before you can access a FreeBSD system, you must be registered as a user. The registration defines a number of parameters:

  • A user name, also often called user ID. This is a name that you use to identify yourself to the systcode.
  • A password, a security device to ensure that other people don't abuse your user ID. To log in, you need to specify both your user ID and the correct password. When you type in the password, nothing appears on the screen, so that people looking over your shoulder can't read it.

    It might seem strange to go to such security measures on a system that you alone use. The incidence of Internet-related security problems in the last few years has shown that it's not strange at all, it's just common sense. Microsoft systems are still subject to a never-ending series of security exploits. FreeBSD systems are not.

  • A shell, a program that reads in your commands and executes them. MS-DOS uses the program COMMAND.COM to perform this function. UNIX has a large choice of shells: the traditional UNIX shells are the Bourne shell sh and the C shell csh, but FreeBSD also supplies bash, tcsh, zsh and others. I personally use the bash shell, and the examples in this book are based on it.
  • A home directory.The system can have multiple users, so each one needs a separate directory in which to store his private files. Typically, users have a directory /home/username, where username is the name they use to login. When you login to the system, the shell sets the current directory to your home directory. In it, you can do what you want, and normally it is protected from access by other users. Many shells, including the bash shell used in these examples, use the special notation ~(tilde) to represent the name of the home directory.
  • A group number. UNIX collects users into groups who have specific common access permissions. When you add a user, you need to make him a member of a specific group, which is entered in the password information. Your group number indirectly helps determine what you are allowed to do in the system. As we'll see on page 181, your user and group determine what access you have to the system. You can belong to more than one group.

    Group numbers generally have names associated with them. The group names and numbers are stored in the file /etc/group. In addition, this file may contain user IDs of users who belong to another group, but who are allowed to belong to this group as well.

    If you find the concept of groups confusing, don't worry about them. You can get by quite happily without using them at all. You'll just see references to them when we come to discuss file permissions. For further information, look at the man page for Group (5).

By the time you get here, you should have defined a user name, as recommended on page 94. If you haven't, you'll have to login as root and create one as described there.

Gaining access

Once you have a user name, you can log in to the system. Already you have a choice: FreeBSD offers both virtual terminals and the X WindowSystem. The former displays plain text on the monitor, whereas the latter uses the system's graphics capabilities. Once running, you can switch from one to the other, but you have the choice of which interface you use first. If you don't do anything, you get a virtual terminal. If you run xdm, you get X.

It's still relatively uncommon to use xdm, and in many instances you may not want X at all, for example if you're running the system as a server. As a result, we'll look at the "conventional" login first.

If you're logging in on a virtual terminal, you'll see something like this:

login:    grog
Password:              password doesn't show on the screen
Last login: Fri Apr 11 16:30:04 from canberra
Copyright (c)  1980, 1983, 1986,  1988, 1990,  1991, 1993, 1994
    The Regents of the University of California. All rights reserved.

FreeBSD 5.0-RELEASE (FREEBIE) #0: Tue Dec 31 19:08:24 CST 2002

Welcome to FreeBSD!

You have mail.
erase ^H, kill ^U, intr ^C, status ^T
Niklaus Wirth has lamented that, whereas Europeans pronounce his name
correctly (Ni-klows Virt), Americans invariably mangle it into
(Nick-les Worth).  Which is to say that Europeans call him by name, but
Americans call him by value.
 === grog@freebie (/dev/ttyv0) ~ 1 ->

There's a lot of stuff here. It's worth looking at it in more detail:

  • The program that asks you to login on a terminal window is called getty. It reads in your user ID and starts a program called login and passes the user ID to it.
  • login asks for the password and checks your user ID.
  • If the user ID and password are correct, login starts your designated shell.
  • While starting up, the shell looks at a number of files. See the man page for your particular shell for details of what they are for. In this case, though, we can see the results: one file contains the time you last logged in, another one contains the Message of the day (/etc/motd), and a third one informs you that you have mail. The shell prints out the message of the day verbatim - in this case; it contains information about the name of the kernel and a welcome message. The shell also prints information on last login time (in this case, from a remote system) and whether you have mail.
  • The line "erase ^H, kill ^U, intr ^C, status ^T" looks strange. It's telling you the current editing control characters. We'll look at these on page 131. At this point, the shell changes the current directory to your home directory.There is no output on the screen to indicate this.
  • The shell runs the fortune program, which prints out a random quotation from a database of "fortune cookies." In this case, we get a message about Niklaus Wirth, the inventor of the Pascal programming language.
  • Finally, the last line is a prompt, the information that tells you that the shell is ready for input.

The prompt illustrates a number of things about the UNIX environment. By default, sh and friends prompt with a $, and csh and friends prompt with a %. You can change it to just about anything you want with the UNIX shells. You don't have to like my particular version, but it's worth understanding what it's trying to say.

The first part, ===, is just to make it easier to find in a large list on an X display. An xterm window on a high resolution X display can contain up to 120 lines, and searching for command prompts can be non-trivial.

Next, grog@freebie is my user ID and the name of system on which I am working, in the RFC 2822 format used for mail IDs. Multiple systems and multiple users can all be present on a single X display. This way, I can figure out which user I am and what system I am running on.

/dev/ttyv0 is the name of the terminal device. This can sometimes be useful.

~ is the name of the home directory. Most shells, but not all of them, support this symbolism.

1 is the prompt number. Each time you enter a command, it is associated with this number, and the prompt number is incremented. One way to re-execute the command is to enter !!1 (two exclamation marks and the number of the command). We'll look at more comfortable ones on page 131.

To start X from a virtual terminal shell, use the startx command:

$ startx

If you use xdm, you bypass the virtual terminals and go straight into X. Enter your user name and password to the login prompt or the xdm login screen, and press Enter. If you use the xdm login, you'll go straight into X.

Either way, assuming that you've installed and configured kde, you'll get a display similar to that in Figure 7-1 . This example includes four windows that are not present on startup. On startup the central part of the screen is empty. We'll look at the windows further below.

Владимир Шишкин
Владимир Шишкин
Россия, Киров
Олег Страхов
Олег Страхов
Россия