[Introduction to Linux Shell Use the shell and environment configuration

Every time we must re-learn environment configuration once again Linux. . This is because a lot of times we need to configure the environment variables, however, if Linux did not understand the words, a lot of instruction in what to do, we do not know, which is very uncomfortable. Moreover, the "Bird Brother Linux private kitchens" is written on CentOS Red Hat environment configuration of the system, I'm using Ubuntu Debian system, both of which there are some differences in the file system, so there will simply remember what about Ubuntu configuration of a variety of environments, the way a brief Shell.

 

A. Terminal, shell with tty

In Linux we often encounter terminal, shell and tty three concepts, what is the difference between these three concepts do? We start talking about the beginning of the last century.

Unix operating system was initially designed to be a multi-user operating system. Each user is not operating on the host, the terminal (terminal) connected to the host, but the operation . Since that time no keyboard and screen, so they are using a typewriter (Teletype) . There are a host administrator to operate, this is called the host console (Console) . Thus, historically, terminal, teletype and console are hardware-level concepts.

Subsequent history we all know, keyboard and monitor to get the invention, GUI instead of CIL. In the X window, we can not type the appropriate character to execute our command, and if I still want to perform the corresponding command, then how to do it? At this time, terminal emulator (terminal emulator) appeared to open the terminal emulator, type the characters entered, we will be able to execute the corresponding command . Ubuntu pre-installed desktop is GNOME, so we use the gnome-terminal. This is why the black box called the cause of the terminal. In short, the current environment is a text terminal input and output.

So shell what is it? As we all know , shell and core is used to interact. Enter your command in the terminal, it will be handed over to the last shell, shell called the kernel, then returns the results to your terminal. To sum up, shell is used to process the results of your commands. We often say that bash is actually a shell.

As for the tty, also a terminal emulator (terminal emulator) fills, use Ctrl + Alt + F1 to enter the graphical interface in Ubuntu, others such as Ctrl + Alt + F2 and so on is to get tty interface.

 

Two. History function

Here's what some of the features of bash, one of the more important feature is the history function. This feature is designed to record your history instruction.

Note that when you log in, your command history is recorded in memory, only cancellation or execution history -w time will be recorded in the ~ / .bash_history in .

Finally, tell us about the history of a few tips:

  1.  The direction selection key recently executed instructions.
  2.  By! Number to select the number of instruction execution history history instruction returned.
  3.  By! Command to run the command with a recent history of command.

 

Three. Alias ​​function

also built bash alias feature, we can develop new command by the alias, such as:

alias lm='ls -al'

If you want to cancel alias, with unalias on the line:

unalias lm

But it is worth noting that this alias when you logout becomes ineffective, Here are some how to make this thing permanent.

 

Four. Bash environment configuration

After the above introduction, we already know are gnome-terminal and tty terminal, the last is input to the command shell process. So from the point of view of the shell with a gnome or no difference with tty.

In order to understand the environment configuration bash, we had to learn some of the basics of the front, such as:

  1. non-login shell: by definition, does not require login shell, such as a user you are logged in using a graphical interface, open a terminal in the graphical interface, you do not need to enter your user name and password again, this is the non- login shell.
  2. login shell: Similarly to tty, for example, its graphical interface and the login process exactly the same (note that we Ctrl + Alt + F1, also need to login again) , but he was logged in the terminal there, like this need to get bash complete the login process, we called him for the login shell.

The reason to mention the two shell, because the two shell reads the configuration file is not the same.

(1). non-login shell

This is our most popular shell, he would only read the contents of ~ / .bashrc in . Here, the term is actually reading this script to parse the command file Bale. (This may also explain why, when we open the terminal too some time to display the prompt, because the implementation of these script files )

As for the ~ / .bashrc will not read the contents of other files (such as in Ubuntu or CentOS is /etc/bash.bashrc in the / etc / bashrc), we must look at how to write a specific script.

Basically only two cases we will modify the contents of ~ / .bashrc in:

  1.  Set the environment variable : We hope we set the environment variable permanent, it would have to be added in the /.bashrc: export environment variable = ...
  2.  Set Alias : if some command is too long, we can also add in /.bashrc the alias = ...

(2). login shell

In contrast, login shell login process is slightly more complicated. The following is a showcase of non-login shell of the Red Hat CentOS series of login process.

"Login shell" image search results

This figure also little mistakes that we read in the second step is not necessarily the ~ / .bash_profile.

It is mainly in order to read, the reading order of ~ / .bash_profile-> ~ / .bash_login-> ~ / .profile

If the shell found one file on this order, he will not seek a down.

Like Ubuntu is to have my own ~ / .profile file, so he would find ~ / .profile file in the second step. (Specific contents of the file or use vim continue to view)

 

V. About source

Many times we have written correspondence related to the configuration file, you also need to perform source filename to be effective, which is why?

Because only the appropriate configuration file will be read when bash starts, so you have to modify in the bash re-import the configuration file.

source is used to doing this sort of thing.

 

Published 137 original articles · won praise 19 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_43338695/article/details/103851695