Pipe and job control, shell variables, environment variable profiles

Source: Internet
Author: User

One, pipe and operation control

Pipe character |: To pass the output of a file to the following command
grep: A command used to filter a specified keyword
Application Examples:
[[email protected] ~]# ls |wc-l//list How many rows are in the current directory
8
[[email protected] ~]# Find/-type f//List all files in the current directory
./.bash_logout
./.bash_profile
./.BASHRC
./.CSHRC
./.TCSHRC
./.bash_history
./.ssh/known_hosts
./.ssh/authorized_keys
./anaconda-ks.cfg.1
./2.txt
./11.txt
./.lesshst
./1.txt
./1.txt.zip
./.viminfo
./3.txt
./4.txt
[[email protected] ~]# Find/-type f |wc-l//You can use the pipe to view the number of files
17

CTRL + Z shortcut key: Temporarily pause the current task
FG N Command (abbreviated to foreground foreground): Restarts the current task that was just paused, calls back, n represents the ID number, such as calling a process with a pause ID of 1, which can be invoked using #fg
Jobs: List the stopped tasks
BG n command (abbreviation for background background): Drop the task into the background and run, n represents the ID number, such as #bg 1, throw process 1 into the background and run
#sleep & command: Means to drop the Sleep 100 command into the background and run the command +& format
#ps aux |grep sleep//view sleep process

Second, shell variables

#env//View system built-in environment variables
#set//Not only to view the system built-in variables, but also to view user-defined variables
[Email protected] ~]# a=111//Custom environment variables, such as a=111
[Email protected] ~]# echo $a
111
#set |grep 111//Use the SET command to view a custom variable 111
Variable name rules: Letters, numbers, underscores, the first cannot be numbers

Variable values have special symbols that need to be enclosed in single quotes, for example: #a = ' A b C
[[email protected] ~]# a= ' a b C '
[Email protected] ~]# echo $a
A b C

Accumulation of variables: for example, variable a b accumulates
[Email protected] ~]# a=1
[Email protected] ~]# b=2
[Email protected] ~]# echo $a $b
12

[[email protected] ~]# c= "A$BC"//Recognized as $BC
[Email protected] ~]# echo $c
A
[[email protected] ~]# c= "a$b" c//need to write $b and C separately, variable complex when using single or double quotation marks
[Email protected] ~]# echo $c
A2c

[[email protected] ~]# c=a "$b" c//assignment with complex variables enclosed in double quotes
[Email protected] ~]# echo $c
A2c

W command: View the user who is currently logged on to the system
[[Email protected] ~]# w//View the user who is currently logged on to the system
22:20:03 up min, 2 users, load average:0.00, 0.01, 0.06
USER TTY from [email protected] IDLE jcpu PCPU
Root pts/0 192.168.238.1 21:56 3.00s 0.22s 0.06s W
Root pts/1 192.168.238.1 22:19 6.00s 0.06s 0.06s-bash
[[email protected] ~]# echo $SSH _tty//To see which users are logged in
/dev/pts/0

Define global variables: formats such as: Export b=2
[[email protected] ~]# export hll=linux define global variables Hll=linux
[Email protected] ~]# echo $HLL
Linux
[[email protected] ~]# Bash//new open a child shell, directly run #bash,echo $hll or can output Linux, this is the global variable
[Email protected] ~]# echo $HLL
Linux

There is no Pstree command in the system, you can use the # yum install Psmisc #using Psmisc package for pstree installation

The Pstree command gives you a visual view of the directory structure, and you can see that Pstree is running in the new bash, Echo $hll, which is the same as the global variable, which takes effect down, and the parallel bash does not take effect.

unset custom variable name//Cancel custom variable
#bash//Enter a new sub-shell

III. environment variable configuration file

environment variable configuration file/etc/profile and/ETC/BASHRC belong to the system level, generally do not modify;
Can modify the user's home directory ~/.BASHRC ~/.bash_profile These belong to the user level, can be set to a single user

[Email protected] ~]# vim. Bash_profile//Editor home directory. Bash_profile
[[email protected] ~]# source. Bash_profile or #. Bash_profile//After editing, you need to have the configuration file take effect immediately, you can use source or. , here. As with the source effect, the configuration file configuration is loaded

In the ~/.bash_logout file, you can define a command history that allows a user to exit the login, and a command to delete the history command in this configuration file

About PS1
The PS1 can be
[[Email protected] ~]//From left to right, followed by the current user, @, hostname, current directory
[Email protected] ~]# cd/etc/sysconfig/network-scripts/
[Email protected] network-scripts]# echo $PS 1
[\[email protected]\h \w]\$//\u is user,\h is hostname,\w is the current directory
#PS1 = ' [\[email protected]\h \w]\$ '//If w is changed to lowercase w then it will display an absolute path
Instance:
[[email protected] network-scripts]# ps1= ' [\[email protected]\h \w]\$ '//change W to lowercase W
[[Email protected]/etc/sysconfig/network-scripts]#//will be displayed as an absolute path

[[email protected]/etc/sysconfig/network-scripts] #PS1 = ' <\[email protected]\h \w> \$ '//Can be modified [] for < >
<[email protected]/etc/sysconfig/network-scripts> #//after modification [] it becomes <>
$ sign, root user is #, other normal user is $
[[email protected] network-scripts] #PS1 = ' [\033[01;32m]\[email protected]\h[\033[00m]:[\033[01; 36m]\w[033[00m]\$] ' Modify Color

PS2: Enter MySQL to enter the small terminal of MySQL, into the PS2
[[email protected] network-scripts] #echo $PS 2

Pipe and job control, shell variables, environment variable profiles

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.