Linux System Shell Basics (ii)

Source: Internet
Author: User

First, the pipe character

Pipe character: pipe symbol used to pass the result of the previous command to another command
Example:
1. Count the number of rows in a file
Command: CAT/ETC/PASSWD | Wc-l

2. Count the number of files in the current folder
Command: LS | Wc-l

3. Count the total number of files in a directory
Command: Find-type F | Wc-l

Pipe breaks are often used in practical applications.

Second, Operation control

Job control is a bit like the background under Windows, Windows can press Ctrl+tab to switch between different programs, Liunx can also implement similar functions, the execution of the command "hang" to the background.
A terminal has only one front desk, sometimes

Commands involved in Job control
CTRL + Z: Tentative command, stop in the background, available FG recovery
CTRL + C: Terminate command execution
FG: Front Desk
BG: Put the program in the background
Command &: Put commands directly in the background execution
Jobs: Viewing background tasks
Screen

Operation Example
1, the implementation of the VIM command tentative

2. Resuming a paused command

The execution of the command resumed.

3, some command support in the background to continue to run, then we can put the command in the background to run.
They put the Vmstat command in the background.

You can see that he is still running, but we can still enter other commands to operate the system. This is not the same as CTRL + Z, CTRL + Z program will not move.

4, the job command to view the background of the program

A bit messy, but it can be seen that there are three programs running, then we can use FG N (serial number) to the command to the front desk and then shut him down
For example, I transferred the No. 2nd command to the front desk and closed it.

The place where the circles are circled is my command "FG 2" just because the program is running, it seems a bit messy. When you view the job again, program 2 is gone.

5, closed the background of the program
Command
View Process Pid:ps-aux
End process: Kill PID

Explain, kill-9 +pid is mandatory end of the meaning, we force the background of the two commands to turn off, and then use the job can not see the previous two commands in the background.

Third, shell variables

Variables are a common concept in programming, and variables are derived from mathematics and are abstract concepts that can store computational results or represent values in a computer language. Here we understand that variables are the codes of specific values or meanings that the system has already provisioned, and we can refer to them when we write the shell.

1, the system built-in variables
path= command path, builtin command
Home directory of Home user root home is root,
PWD indicates where the current directory is
LOGNAME your login username
histsize Command History Record Count
Shell type of shell current user
HOSTNAME Host Name
2. View System Preset Variables
The values of the above system preset variables can be viewed with the following two commands
ENV command to display the system's preset environment variables

Set command to display all the variables of the system preset

(It's only part of it, it's a long back.)
3, user custom variable, xx=xx custom variable
Variable name rules: Avoid capitalization, many of the system's default variables are uppercase strings, you can use uppercase strings to change the system preset variables,
Attach a 15 best practices for naming variables & Methods (reprinted to LEGENDMOHE.NET/2014/04/15/)
You can have numeric letters and underscores in the name of a custom variable, but the number cannot be the first digit, such as when you write "1a=11".

Examples of custom variables:
1. Input: test=888

Then we see that the value of the variable is 888.

2, the value of the variable has a special symbol should be enclosed in single quotation marks. e.g./. .. These have special meanings, double quotation marks are also OK, but it is recommended to use single quotes, double quotes sometimes problems. Example

3, the value of the variable accumulation, attention is not the meaning of summation, but the variable value of the word display



Note that if you quote in single quotation marks in the above example, the $ will be taken out of the box and the result will become $a $b $c

4, global variables, involving child shells, global variables can be passed to all the shell, can not be used under another terminal.
To supplement the knowledge of the terminal, every time we pass
The W command can see which terminals are logged into the system
Pstree can view

5, unset can cancel the variable

IV. environment variable configuration file

A few important environment variables
/etc/profile Users
/ETC/BASHRC users do not have to log in, the execution shell is effective
~./bashrc
~/,bash_profile
~/.bash_history
~/.bash_logout will execute when launched
Ps1= Defining prefixes

Linux System Shell Basics (ii)

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: info-contact@alibabacloud.com 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.