Linux main shell command details (top)

Source: Internet
Author: User

[Excerpt from the network]

Kill-9-1 is the implementation of the kill command to exit the system

Linux main shell commands [previous]
The shell is the interface between the user and the Linux operating system. There are multiple shells in Linux, with bash being used by default. This chapter describes how the shell works, the type of shell, the general operation of the shell, and the features of bash.

What is a shell?

The shell of the Linux system is the shell of the operating system, providing the user with an interface to use the operating system. It is the general designation of command Language, command interpreter and programming language.

The shell is the interface between the user and the Linux kernel, and if you think of the Linux kernel as the center of a sphere, the shell is around the outer layer of the kernel. When a command is passed to Linux from a shell or other program, the kernel responds accordingly.

The shell is a command language interpreter with its own built-in shell command set, and the shell can be called by other applications in the system. Commands entered by the user at the prompt are interpreted by the shell before being passed to the Linux kernel.

Some commands, such as changing the Working Directory command CD, are included inside the shell. There are also commands, such as the Copy command CP and the move command RM, which are separate programs that exist in a directory on the file system. For users, there is no need to care whether a command is built inside the shell or a separate program.

The shell first checks whether the command is an internal command, or if it is not checked for an application (the application here can be a utility for Linux itself, such as LS and RM, or it can be a commercially available program such as XV, or free software such as Emacs). The shell then looks for these applications in the search path (the search path is a list of directories that can find executable programs). If the command you typed is not an internal command and the executable file is not found in the path, an error message will be displayed. If a command can be successfully found, the internal command or application is decomposed into a system call and passed to the Linux kernel.
Another important feature of the shell is that it is itself an interpreted programming language, and the Shell programming language supports most of the program elements seen in high-level languages, such as functions, variables, arrays, and program-control structures. The Shell programming language is easy to learn, and any command that can be typed at the prompt can be placed into an executable shell program.

When a normal user logs on successfully, the system executes a program called the shell. It is the shell process that provides the command line prompt. As the default (the default shell of the Turbolinux system is bash), a "$" prompt is used for ordinary users, and "#" is used as a prompt for superuser (root).

Once the shell prompt appears, you can type the command name and the parameters required by the command. The shell executes the commands. If a command takes a long time to run, or produces a lot of output on the screen, you can interrupt it by pressing CTRL + C from the keyboard (abort it before it ends).

When the user is ready to end the logon dialog process, you can type the logout command, Exit command, or file Terminator (EOF) (implemented by Ctrl+d) to end the login.

Let's practice how the shell works.

$ make work

Make:***no rule to do target ' work '. Stop.


Note: Make is the name of a command in the system followed by a command parameter. After receiving this command, the shell executes it. In this case, the execution of the command is stopped after the system returns information because the command parameter entered is incorrect.

In the example, the shell looks for a program called Make and executes it as a work parameter. Make is a program that is often used to compile large programs, which are compiled with parameters as targets. In "Makework", the goal of make compilation is work. Because make cannot find a target with work as its name, it gives the error message that the run failed and the user goes back to the system prompt.

Additionally, if the shell cannot find a program with the name of the command named after the user types the command line, an error message is given. For example, if the user types:

$ myprog

Bash:myprog:command not found


As you can see, the user gets an error message that the command was not found. After the user knocks the wrong command, the system usually gives such error message.

Types of shells

There are several types of shells in Linux, the most common of which are Bourneshell (SH), C Shell (CSH), and KornShell (Ksh). Each of the three shells has advantages and disadvantages. Bourneshell is the first shell used by UNIX and can be used on every UNIX type. Bourneshell is very good at Shell programming, but does not work as well as several other shells in dealing with user interactions. The default shell of the Linux operating system is the Bourneagain shell, which is an extension of the Bourne Shell, called Bash, which is completely backwards compatible with Bourneshell, and adds and enhances many features on the basis of Bourneshell. Bash is featured in/bin/bash, which offers features such as command completion, command editing, and command history tables, as well as many of the benefits of Cshell and KornShell, flexible and powerful programming interfaces, and a friendly user interface.

The C shell is a shell that is more suitable for programming than Bourneshell, whose syntax is similar to that of the C language. Linux provides tcsh for people who like to use the C shell. TCSH is an extended version of Cshell. TCSH includes command-line editing, programmable word completion, spell correction, History command substitution, job control, and C-like syntax, which not only is prompt-compatible with Bashshell, but also provides more prompt parameters than Bashshell.

The Korn shell aggregates the advantages of the C shell and Bourneshell and is fully compatible with Bourneshell. The Linux system provides the Pdksh (Ksh extension), which supports task control, which can be suspended on the command line, executed in the background, woken up, or terminated by the program.

Linux does not snub other shell users, including some popular shells such as Ash, zsh, and so on. Each shell has its purpose, some shells are patented, and some are available from the Internet or other sources. To decide which shell to use, just read the various shell online help and try it out.

The/etc/passwd file is used by the user to determine which shell to use when logging on to Linux. For example:


Lisa:x:500:500:turbolinux User:/home/lisa:/bin/bash

The shell is listed at the end of each row (/bin/bash).

Since bash is the default shell on Linux, this chapter focuses on bash and its related knowledge.

Shell command

Command line C

When a user logs on to a Linux system, they can see a shell prompt that identifies the start of the command line. The user can enter any command and parameters after the prompt. For example:

$ date

211 01:34:58 CST 1999


When the user logs in, it actually enters the shell, which follows a certain syntax to interpret the input commands and pass them on to the system. The first word entered on the command line must be the name of a command, the second word is the option or parameter of the command, and each word in the command line must be separated by a space or tab, in the following format:

$ Command Option Arguments

1. Options and Parameters

Options are code that includes one or more letters, preceded by a minus sign (minus is necessary, Linux uses it to differentiate between options and parameters), and options can be used to change the type of action the command executes. For example:

$ ls

MOTD passwd


This is the LS command without the option to list all the files in the current directory, listing only the names of the individual files, and not displaying any more information.

$ ls-l

Total 2

-rw-r--r--2 Wzh book April 20:37 MOTD

-rw-r--r--2 Wzh book 796 Apr 20:37 passwd


By adding the-l option, a row of information is listed for each file, such as the size of the data and the time the data was last modified.

Most commands are designed to accept parameters. Parameters are one or more words that you type after the options in the command line, such as:

$ ls-l Text

-rw-r--r--2 Wzh book April 20:37 MOTD

-rw-r--r--2 Wzh book 796 Apr 20:37 passwd


All files and their information are displayed in the text directory.

Some commands, such as LS, can take parameters, while some commands may require some minimum number of arguments. For example, the CP command requires at least two parameters, and the shell will give an error message if the number of arguments does not match the command's requirements. For example:

$ cp-i MyData NewData

Note: The option on the command line is preceded by parameter input.
2. Command-line Features

The command line is actually a text buffer that you can edit, and you can edit the input text before you press ENTER. For example, the use of the BACKSPACE key can delete the characters you just typed, you can delete the whole row, you can also insert characters, so that users in the input command, especially complex commands, if there is a typing error, no need to re-enter the entire command, as long as the editing operation, you can correct the error.

Use the UP arrow to re-display the command you just executed, which allows you to repeatedly execute previously executed commands without having to retype the command.

Bash holds a list of previously typed commands, called the Command history table. By pressing the UP arrow, you can display each command on the command line successively. Similarly, pressing the DOWN arrow moves down the command list so that the previous commands can be displayed on the command line and the user can modify and execute the commands. This feature will be discussed in detail in section 10.4.

You can also place multiple commands on one command line, separating the commands with semicolons. For example:

$ ls-f;cp-i MyData NewData

You can also enter a command on several command lines to persist a command line to the next line with a backslash.

$ cp–i




The CP command above is entered in three rows, the first two lines end with a backslash, and three lines are used as a command line.

Linux main shell command details (top)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.