CompTIA Linux+ Powered by Linux Professional Institute Study Guide. Richard Blum

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

Читать онлайн книгу CompTIA Linux+ Powered by Linux Professional Institute Study Guide - Richard Blum страница 15

CompTIA Linux+ Powered by Linux Professional Institute Study Guide - Richard Blum

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

non-Linux Unix-like OSs, they may be more familiar with these other shells. You can change a user's default shell by editing their account, as described in Chapter 7, “Administering the System.”

      Be aware that there are two types of default shells. The default interactive shell is the shell program a user uses to enter commands, run programs from the command line, run shell scripts, and so on. The other default shell type is a default system shell. The default system shell is used by the Linux system to run system shell scripts, typically at startup.

      The file /bin/sh is a pointer to the system's default system shell – normally /bin/bash for Linux. However, be aware that, on some distributions, the /bin/sh points to a different shell. For example, on Ubuntu, /bin/sh points to the dash shell, /bin/dash.

      Using a Shell

      Linux shell use is fairly straightforward for anybody who's used a text-mode OS before: You type a command, possibly including options to it, and the computer executes the command. For the most part, Linux commands are external – that is, they're programs that are separate from the shell.

      A few commands are internal to the shell, though, and knowing the distinction can be important. You should also know some of the tricks that can make using the command shell easier – how to have the computer complete a long command or filename, retrieve a command you've recently run, or edit a command you've recently used (or haven't yet fully entered).

      Starting a Shell

      If you log into Linux using a text-mode login screen, you have logged into a virtual console terminal and, most likely, you'll be dropped directly into your default shell. The shell program is what presents the prompt and accepts subsequent commands.

      If you log into Linux using a graphical user interface (GUI) login screen, you'll have to start a terminal emulator manually in order to reach your default shell. Some GUIs provide a menu option, such as xterm or terminal, to start a terminal emulator program. These programs enable you to run text-mode programs within Linux, and by default they come up running your shell. If you can't find such a menu option, look for a menu option that enables you to run an arbitrary command. Select it, and type xterm or konsole as the command name. This will launch a terminal emulator program that will run a shell.

      Once you start a terminal or log into a virtual console terminal, the shell will provide you with a prompt for entering commands. Remember that the shell is a program providing you with an interface to the Linux system.

      A good first command to try, uname, will show what operating system is being run:

      That's not too interesting. You can find out additional information by tacking on the -a option to the command. Be sure to include the necessary space between the command and the option:

      The uname – a command provides a lot more information, including the current Linux kernel being used (2.6.32) as well as the system's hostname (server01.class.com). The uname command is an external command. The shell also provides internal commands. It's important to know the difference between the two command types, as explained in the next section.

      Using Internal and External Commands

      Internal commands are, as you might expect, built into the shell program. Thus they are also called built-in commands. Most shells offer a similar set of internal commands, but shell-to-shell differences do exist. Internal commands that you're likely to use enable you to perform some common tasks:

      Change the Working Directory

      Whenever you're running a shell, you're working in a specific directory. The cd command changes the current working directory. For instance, typing cd /home/sally changes the current working directory to the /home/sally directory.

      You can use shortcut characters with the cd command as well. The tilde () character is a useful shortcut; it stands for your home directory. Thus typing cd ∼ will have the same effect as typing cd /home/sally if your home directory is /home/sally.

      Display the Working Directory

      The pwd command displays (“prints” to the screen) the current working directory. This command is helpful, especially after you have changed your working directory, to ensure you ended up in the right place.

      Display a Line of Text

      The echo command displays the text you enter. For instance, typing echo Hello causes the system to display the string Hello. This may seem pointless, but it's useful in scripts (described in Chapter 9, “Writing Scripts, Configuring Email, and Using Databases”), and it can also be a good way to review the contents of environment variables (described later in this chapter, in the section “Using Environment Variables”).

      Time an Operation

      The time command times how long subsequent commands take to execute. For instance, typing time pwd tells you how long the system took to execute the pwd command. The time is displayed after the full command terminates. Three times are displayed: total execution time (aka real time), user CPU time, and system CPU time. The final two values tell you about CPU time consumed, which is likely to be much less than the total execution time.

      Set Options

      In its most basic form, the set command displays a wide variety of options relating to bash shell operation. These options are formatted much like environment variables, but they aren't the same things. You can pass various options to set to have it affect a wide range of shell operations.

      Terminate the Shell

      The exit and logout commands both terminate the shell. The exit command terminates any shell, but the logout command terminates only login shells. Login shells are shell programs that are launched automatically when you initiate a text-mode login as opposed to those that run in xterm windows or other terminal emulators.

      The preceding list isn't complete. Later sections of this chapter and later chapters describe some additional internal commands. Consult your shell's documentation for a complete list of its internal commands.

      You can quickly determine if a command is a built-in command by using the type command. Just enter the command type before the name of the command you wish to check:

      Some of these internal commands are duplicated by external commands that do the same thing. But those external commands aren't always installed on all systems. You can see if there are internal commands with installed duplicate external commands by using the -a option on the type command:

      You can see that on this

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