user system
- useradd username management
- /home/username create directory
- /etc/passwd
- /etc/shadow User password related files
- id
- userdel username -r (adding -r will delete the corresponding home directory)
- usermod -d can modify the location of the user's home directory userod -d /home/w1 w(usermod -g group2 user2)
- change Modify the user's lifecycle
- groupadd groupdel(useradd -g group1 user2)
- su - username Temporary user switching
- sudo administrator authorization to normal users. The root user can add command authorization through visudo
- /etc/passwd
wilson:x:1000:1000::/home/wilson:/bin/bash :x(x代表切换用户需要输入密码,为空则不需要密码):uid:gid:comment:家目录位置:用户登录后的命令解释器 (如果设置为 /sbin/nologin 则用户不能登录)
Pipelines and Redirection
- pipes and pipe symbols
- Like signals, pipes are also one of the ways of process communication
- Anonymous pipe (pipe symbol) is a communication tool often used in Shell programming
- The pipe symbol is "|", which transfers the execution result of the previous command to the following command
- redirect
- A process will open standard input, standard output, and error output three file descriptors by default.
- Enter the redirection symbol "<"
- Output redirection symbols ">" (clear input), ">>" (append), "2>" (only output error content), "&>" (output all content)
The above script will generate a new file, which contains a line of I am xx characters#!/bin/bash cat > /path/to/a/file << EOF I am $USER EOF
variable assignment
-
Interactive variable assignment read var
-
variable name = variable value
a=123 (There can be no spaces on both sides of the equal sign)
-
Use let to assign values to variables
let a=10+20 (not recommended, because bash's computing performance is very poor)
-
assign command to variable
l=ls
-
To assign the command result to a variable, use $() or ``
letc=$(ls -l /etc)
-
The variable value can be included in " " or ' ' by special characters such as spaces
-
The content of the output variable is quoted using $, such as echo $var
-
variable reference
${变量名}
$变量名
-
If you need to append content after the variable output result, you need to use the first type, otherwise it will be recognized as another variable name
-
The default scope of the variable (only valid in its own scope)
-
Use source or . to execute the .sh script in the current environment
- variable export
- export (variables can be exported to allow subprocesses to read variables)
- variable export
- unset
- variable export
- system environment variable
- Environment variables: Variables that can be obtained every shell open
- set (see more variables – predefined convenience and environment variables) env (see all environment variables)
- View only one variable echo $USER
- $PS1 console log output format
- $? Is the previous command executed correctly [return 0 for correct execution, 1 for abnormal execution] $$ pid $0 the name of the current process
- Parameter position $1 $2 ... ${10}
- Environment variables: Variables that can be obtained every shell open
- array type
- Define the array: IPTS=( 10.0.0.1 10.0.0.2 )
- There are spaces between brackets and content, and spaces are used to separate elements
- display all elements of an array
- echo ${IPTS[@]}
- Display the number of array elements
- echo ${#IPTS[@]}
- display the first element of the array
- echo ${IPTS[0]}
- Define the array: IPTS=( 10.0.0.1 10.0.0.2 )
-
Special characters: a character not only has literal meaning, but also meta-meaning
#
note- ; semicolon - separates statements
- \ escape symbol
- " and ' quotes
- "Double quotes do not fully quote variables
- ' Single quotes fully quote the variable
- ` Backticks - can execute a command
-
Operators (the shell only supports integer arithmetic)
- assignment operator
- = assignment
- unset cancel assignment
- expr performs arithmetic assignment
- Symbols and operators must have spaces
- arithmetic operator
- numeric constant
- double parentheses
- (( a++))
- assignment operator
-
special symbols
- quotation marks
- 'Full quote
- "Incomplete quote
- `execute command
- brackets
- ()(()) $()
- Parentheses alone produce a shell
- Array initialization is also done with parentheses IPS=( 21.23 23.23 )
- [] [[]]
- for testing
>
<
input and output- echo {0…9} outputs numbers from 0 to 9
- && ||
- & Background process
- ()(()) $()
vim, sed, awk editor
- vim is a full text editor sed, awk is a line editor
- sed awk is a non-interactive text editor
- sed awk processes text line by line
- Introduction to sed
- Read file into memory (pattern space) in units of lines
- Each script with sed operates on the line
- Output the line after processing is complete