Shell red hat linux

Understanding the Red Hat Linux Shell

Before icons and windows took over computer screens, you typed commands to run most computers. On UNIX systems, from which Red Hat Linux was derived, the program used to interpret and manage commands was referred to as the shell.

The shell provides a way to run programs, work with the file system, compile computer code, and manage the computer. Although the shell is less intuitive than common GUIs, most Linux experts consider the shell to be much more powerful than GUIs. Because shells have been around for so long, many advanced features have been built into them. Many old-school Linux administrators and programmers primarily use a GUI as a way to open lots of shells.

The Red Hat Linux shell illustrated in this chapter is called the bash shell, which stands for Bourne Again SHell. The name is derived from the fact that bash is compatible with the first UNIX shell: the Bourne shell (represented by the sh command). Other popular shells include the C Shell (csh), which is popular among BSD UNIX users, and the Korn Shell (ksh), which is popular among UNIX System V users. Linux also has a tcsh shell (a C shell look-alike) and an ash shell (another Bourne shell look-alike).

Although most Red Hat 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). In Red Hat Linux, the bash shell is roughly compatible with the sh shell.

Источник

The Shell

The shell is a command interpreter that provides a line-oriented interactive and noninteractive interface between the user and the operating system. You enter commands on a command line, they are interpreted by the shell, and then sent as instructions to the operating system. You can also place commands in a script file to be consecutively executed much like a program (see Chapter 40). This interpretive capability of the shell provides for many sophisticated features. For example, the shell has a set of wildcard characters that can generate filenames. The shell can redirect input and output, as well as run operations in the background, freeing you to perform other tasks.

Several different types of shells have been developed for Linux: the Bourne Again shell (BASH), the Public Domain Korn shell (PDKSH), the TCSH shell, and the Z shell. All shells are available for your use, although the BASH shell is the default. You only need one type of shell to do your work. Red Hat Linux includes all the major shells, although it installs and uses the BASH shell as the default. If you use the Red Hat Linux command line shell, you will be using the BASH shell unless you specify another. This chapter discusses the BASH shell that shares many of the same features as other shells.

Читайте также:  Net core service on linux

Note You can find out more about the BASH shell at www.gnu.org/software/bash. A

detailed online manual is available on your Linux system using the man command with the bash keyword.

The Linux command line interface consists of a single line into which you enter commands with any of their options and arguments. Red Hat Linux installs with the BASH shell. From Gnome or KDE you can access the command line interface by opening a terminal window. Should you start Linux with the command line interface, you will be presented with a BASH shell command line when you log in.

By default, The BASH shell has a dollar ($) sign prompt, but Linux has several other types of shells, each with its own prompt. A shell prompt, such as the one shown here, marks the beginning of the command line:

The prompt designates the beginning of the command line. You are now ready to enter a command and its arguments at the prompt. In the next example, the user enters the date command, which displays the date. The user types the command on the first line, and then presses ENTER to execute the command.

Sun July 8 10:30:21 PST 2000

The command line interface is the primary interface for the shell, which interprets the commands you enter and sends them to the system. The shell follows a special syntax for interpreting the command line. The first word entered on a command line must be the name of a command. The next words are options and arguments for the command. Each word on the command line must be separated from the others by one or more spaces or tabs.

$ Command Options Arguments

An option is a one-letter code preceded by a dash that modifies the type of action the command takes. One example of a command that has options is the Is command. The Is command, with no options, displays a list of all the files in your current directory. It merely lists the name of each file with no other information.

With a -1 option, the Is command modifies its task by displaying a line of information about each file, listing such data as its size and the date and time it was last modified. In the next example, the user enters the 1s command followed by a -1 option. The dash before the -1 option is required. Linux uses it to distinguish an option from an argument.

Читайте также:  Посмотреть загрузку системы linux

Another option, -a, lists all the files in your directory, including what are known as hidden files. Hidden files are often configuration files and they always have names beginning with a period. For this reason, hidden files are often referred to as dot files. In most cases, you can also combine options. You do so by preceding the options with an initial dash and then listing the options you want. The options -a1, for example, list information about all the files in your directory, including any hidden files.

Note Another option for the 1s command is -F. With this option, the 1s command displays directory names with a preceding slash, so you can easily identify them.

Most commands are designed to take arguments. An argument is a word you type in on the command line after any options. Many file management commands take filenames as their arguments. For example, if you only wanted the information displayed for a particular file, you could add that file’s name after the -1 option:

The shell you will start working in is the BASH shell, your default shell. This shell has special command line editing capabilities that you may find helpful as you learn Linux. You can easily modify commands you have entered before executing them, moving anywhere on the command line and inserting or deleting characters. This is particularly helpful for complex commands. You can use the CTRL-F or RIGHT ARROW keys to move forward a character, or the CTRL-B or LEFT ARROW keys to move back a character. CTRL-D or DEL deletes the character the cursor is on, and CTRL-H or BACKSPACE deletes the character before the cursor. To add text, you use the arrow keys to move the cursor to where you want to insert text and type in the new characters. At any time, you can press ENTER to execute the command. For example, if you make a spelling mistake when entering a command, rather than reentering the entire command, you can use the editing operations to correct the mistake.

Note The editing capabilities of the BASH shell command line are provided by Readline. Readline supports numerous editing operations. You can even bind a key to a selected editing operation. You can find out more about Readline in the BASH shell reference manual at www.gnu.org/manual/bash.

Читайте также:  Настройка общих папок samba linux

You can also use the UP ARROW key to redisplay your previously executed command. You can then reexecute that command or edit it and execute the modified command. You’ll find this capability helpful when you have to repeat certain operations over and over, such as editing the same file.

Note The capability to redisplay a previous command is helpful when you’ve already executed a command you had entered incorrectly. In this case, you would be presented with an error message and a new, empty command line. By pressing the UP ARROW key, you can redisplay your previous command, make corrections to it, and then execute it again. This way, you would not have to enter the whole command again.

The BASH shell keeps a list, called a history list, of your previously entered commands. You can display each command, in turn, on your command line by pressing the UP ARROW key. The DOWN ARROW key moves you down the list. You can modify and execute any of these previous commands when you display them on your command line. This history feature is discussed in more detail in Chapter 15.

Note Some commands can be complex and take some time to execute. When you mistakenly execute the wrong command, you can interrupt and stop such commands with the interrupt keys-CTRL-C or DEL.

You can enter a command on several lines by typing a backslash just before you press ENTER. The backslash «escapes» the ENTER key, effectively continuing the same command line to the next line. In the next example, the cp command is entered on three lines. The first two lines end in a backslash, effectively making all three lines one command line.

Filenames are the most common arguments used in a command. Often you may know only part of the filename, or you may want to reference several filenames that have the same extension or begin with the same characters. The shell provides a set of special characters called wildcards that search out, match, and generate a list of filenames. The wildcard characters are the asterisk, the question mark, and brackets (*, ?, []). Given a partial filename, the shell uses these matching operators to search for files and generate a list of filenames found. The shell replaces the partial filename argument with the list of matched filenames.

This list of filenames can then become the arguments for commands such as 1s, which can operate on many files. Table 11-1 lists the shell’s wildcard characters.

Источник

Оцените статью
Adblock
detector