Linux Bible. Christopher Negus

Чтение книги онлайн.

Читать онлайн книгу Linux Bible - Christopher Negus страница 22

Linux Bible - Christopher Negus

Скачать книгу

you are using Linux from a graphical desktop, you will probably most often access the shell from a Terminal window.

      Using virtual consoles

      Most Linux systems that include a desktop interface start multiple virtual consoles running on the computer. Virtual consoles are a way to have multiple shell sessions open at once in addition to the graphical interface you are using.

      You can switch between virtual consoles by holding the Ctrl and Alt keys and pressing a function key between F1 and F6. For example, in Fedora, press Ctrl+Alt+F1 (or F2, F3, F4, and so on up to F6 on most Linux systems) to display one of seven virtual consoles. The first virtual workspace in Fedora is where the GUI is and the next six virtual consoles are text-based virtual consoles. You can return to the GUI (if one is running) by pressing Ctrl+Alt+F1. (On some systems the GUI runs on the virtual console 5 or 6. So you'd return to the GUI by pressing Ctrl+Alt+F5 or Ctrl+Alt+F6.)

      Try it right now. Hold down the Ctrl+Alt keys, and press F3. You should see a plain-text login prompt. Log in using your username and password. Try a few commands. When you are finished, type exit to exit the shell. Then press Ctrl+Alt+F1 to return to your graphical desktop interface. You can go back and forth between these graphical consoles as much as you like.

      Choosing Your Shell

      In most Linux systems, your default shell is the bash shell. To find out what your default login shell is, type the following commands:

      The who am i command shows your username, and the grep command (replacing chris with your name) shows the definition of your user account in the /etc/password file. The last field in that entry shows that the bash shell (/bin/bash) is your default shell (the one that starts up when you log in or open a Terminal window).

      It's possible, although not likely, that you might have a different default shell set. To try a different shell, simply type the name of that shell (examples include ksh, tcsh, csh, sh, dash, and others, assuming they are installed). You can try a few commands in that shell and type exit when you are finished to return to the bash shell.

      You might choose to use different shells for the following reasons:

      ● You are used to using UNIX System V systems (often ksh by default) or Sun Microsystems and other Berkeley UNIX-based distributions (frequently csh by default), and you are more comfortable using default shells from those environments.

      ● You want to run shell scripts that were created for a particular shell environment, and you need to run the shell for which they were made so you can test or use those scripts from your current shell.

      ● You simply prefer features in one shell over those in another. For example, a member of my Linux Users Group prefers ksh over bash because he doesn't like the way aliases are used with bash.

      Although most Linux users have a preference for one shell or another, when you know how to use one shell, you can quickly learn any of the others by occasionally referring to the shell's man page (for example, type man bash). The man pages (described later in the “Getting Information about Commands” section) provide documentation for commands, file formats, and other components in Linux. Most people use bash just because they don't have a particular reason for using a different shell. The rest of this section describes the bash shell.

      Bash includes features originally developed for sh and ksh shells in early UNIX systems, as well as some csh features. Expect bash to be the default login shell in most Linux systems you are using, with the exception of some specialized Linux systems (such as some that run on embedded devices) that may require a smaller shell that needs less memory and requires fewer features. Most of the examples in this chapter are based on the bash shell.

      TIP

      The bash shell is worth knowing not only because it is the default in most installations, but because it is the one you will use with most Linux certification exams.

      Running Commands

      The simplest way to run a command is to type the name of the command from a shell. From your desktop, open a Terminal window. Then type the following command:

      Typing the date command, with no options or arguments, causes the current day, month, date, time, time zone, and year to be displayed as just shown. Here are a few other commands you can try:

      The pwd command shows your current working directory. Typing hostname shows your computer's hostname. The ls command lists the files and directories in your current directory. Although many commands can be run by just typing command names, it's more common to type more after the command to modify its behavior. The characters and words you can type after a command are called options and arguments.

      Understanding command syntax

      Most commands have one or more options you can add to change the command's behavior. Options typically consist of a single letter, preceded by a hyphen. However, you can group single-letter options together or precede each with a hyphen, to use more than one option at a time. For example, the following two uses of options for the ls command are the same:

      In both cases, the ls command is run with the -l (long listing), -a (show hidden dot files), and -t options (list by time).

      Some commands include options that are represented by a whole word. To tell a command to use a whole word as an option, you typically precede it with a double hyphen (-). For example, to use the help option on many commands, you enter -help on the command line. Without the double hyphen, the letters h, e, l, and p would be interpreted as separate options. (There are some commands that don't follow the double hyphen convention, using a single hyphen before a word, but most commands use double hyphens for word options.)

      NOTE

      You can use the -help option with most commands to see the options and arguments that they support: for example, try typing hostname – help.

      Many commands also accept arguments after certain options are entered or at the end of the entire command line. An argument is an extra piece of information, such as a filename, directory, username, device, or other item that tells the command what to act on. For example, cat /etc/passwd displays the contents of the /etc/passwd file on your screen. In this case, /etc/passwd is the argument. Usually, you can have as many arguments as you want on the command line, limited only by the total number of characters allowed on a command line.

      Sometimes, an argument is associated with an option. In that case, the argument must immediately follow the option. With single-letter options, the argument typically follows after a space. For full-word options, the argument often follows an equal sign (=). Here are some examples:

      In the

Скачать книгу