Linux Common commands:
1.tab after the first word, for the completion of the command; After the second word, to complete the file
2.LS-AL/USR list all files and attributes (including hidden files) in this directory
LL list more information
3.* wildcard characters
4.man Bash Bash description file man:manual
The help command is used to display helper information inside the shell. The help command can only display command assistance information inside the shell. The Help information for external commands can only be viewed using the man or Info command.
5. Whether the query instruction is built-in command: type
6. \enter \ Jump off the next character immediately following
7. Shortcut key Delete
8. Variable access: Echo $PATH or $path use the man echo to see the other uses of Echo
Path is a variable
9. See if Jdk:rpm-qa|grep-i Java is installed
RPM Management Command, query all installed software Red Hat Package Manager Packages management tool
-qa Find all RPM packages
| Pipe symbol, the output of the previous command (that is, the result) as input to the next command
grep Lookup String
-I indicates ignoring case
RPM and Yum differences: RPM can only install RPM packages that have been downloaded on this machine, and Yum can install RPM online
RPM Redhat Package Manager Red Hat Pack Manager
10. Find Java related lists online via yum–y list java*
Yum's command form is generally as follows: Yum [options] [command] [package ...]
The options are optional, including-H (Help),-y (when the installation process prompts you to select all "Yes"),-Q (does not show the installation process), and so on. [command] for the action you want to take, [package ...] Is the object of the operation.
11. Exit Edit: Q or: Wq or: q! : Wq means to exit after saving: q! means not saving direct exit
12. Switch between multiple edit files Ctrl+w
Installation of RPM I-
Confirm with V
H-progress bar
E-Uninstall
Q-Query
A-all
L--Displays the files in RPM.
13. See if Tomcat starts #ps –ef|grep Tomcat
PS View PID number associated with the process
-e displays information for each process that is currently running
-F Displays a complete list
14. Abort process kill-9 pid-9 indicates forced abort
15. Set Boot Systemctl enable XX
Stop booting from systemctl disable XX
Service Start/stop/View status Systemctl [Status|restart|start|stop] XX
Check to see if you are joined to boot Systemctl--list-units type=service
16. Download the file from the specified URL, support wget (option) (parameter)
wget default to the last character followed by the following characters, you can use Wget-o wordpress.zip http://www.linuxde.net/download.aspx?id=1080 to specify the download file name
17.tar with the tar command, you can package a whole bunch of files and directories into a single file, which is useful for backing up files or combining several files into one file for easy network transmission.
TAR-ZXVF zookeeper-3.3.6.tar.gz-c/home/
X: Extract the files from the tar package
Z: Indicates that the TAR package is compressed by gzip, so it needs to be decompressed with Gunzip
V: Show more information
F xxx.tar.gz: Specifies that the file being processed is xxx.tar.gz
18.MKDIR–P/XX indicates that a top-level directory is created without a top-level directory
19.chmod permission to change a file or directory
Change mode
chmod +x./test.sh
Ls-l.
21.pwd view the full path to the current working directory
Print Working Directory
Nohup command nohup= No hangup
Purpose: To run the command without hanging off.
23.tail–f Log Real-time view refresh log F:fresh
Tail 2 Log View last two records
CTRL + C exit View log, etc.
Vim View a file
: q! Force exit
: Wq Save and exit
ESC Exit Edit
I enter edit mode
Tab press once to complete the file name without knocking the hand
Ps-f |grep fee to see if a program is running and PID number process status
24.chown Change Owner
Rmdir:removedirectory (delete directory) MV move mobile
Cat:concatenate chain Cat File1file2>>file3 combines the contents of files 1 and 2 into File3
Cp:copy file
25. Script Jenkinsdeploy.sh
#!/bin/sh #解释此脚本的shell的路径, if there is no declaration, the script will execute in the default shell
Pid= ' Ps-ef|grep tomcat|grep Java|awk ' {print $} ' # | represents a pipeline; Print$2: Prints the second field separated by each line; awk reads the specified file in a row, with a space as a delimiter
If [-N ' $pid '];then #-n means not NULL
Kill-9 $pid
Fi
Cd/home/apache-tomcat-8.0.44/webapps
If [-F $1.war];then #-f If $1.war is a file, true
RM-RF $1.war #-r Delete all files under current directory-F ignore nonexistent files
Fi
Mv/home/jenkinstemp/$2.war $1.war
Service TOMCATD Start
26.
/denotes root mesh
Cd.. Back to the top level directory
CD/back to the root directory
Cd. Back to current directory
27.find
Mv
Cp
Shell Script
- Simple script
- First line #! /bin/bash program language interpreter, declaring language type
- I/O redirection
- , used to separate multiple commands in the same line, and the shell executes the commands back one time.
Beginner's Tutorial
- Adding {} When referencing a variable is clearer, only = no spaces between variables and assignments
- Create a file and edit VI test.sh
- Execute shell Script
= = = "First CD to the appropriate directory, then chmod +x test.sh The script has execute permission and then runs./test.sh
= = = "Directly run/bin/sh test.sh
- String suggested double quotes, double quotes inside can have variable/escape character/double quotation mark
- Shell passed parameter $ $ to execute the file name $ $ for the first argument
- Only one-dimensional arrays are supported, ${array_name[index when referenced]}
- Basic operator expr and awk, note that expressions are enclosed in single quotation marks. There are spaces between the expression and the operator, such as 2 + 2.
Conditional expressions are placed between square brackets and have spaces, for example: [$a = = $b] is wrong and must be written as [$a = = $b].
Multiplication sign (*) must be added in front of the backslash (\) to achieve multiplication, such as val= ' expr $a \* $b '
- File Test operators:
If [w $file]
Then
echo "File writable"
Else
echo "File not writable"
Fi
- Escape character \ "Pair" escaped \ n newline \c non-newline-e-turn on line break
echo "\" It is a test\ ""
Output results
"It is a test"
15. The read command indicates that a row is read from the standard input and the received standard input is stored in the variable name
Read name
$ $ cannot get the tenth parameter, and the tenth parameter requires ${10}. When n>=10, you need to use ${n} to get the parameters
- Output redirection: Command > File if you want to add new content to the end of the file, use the >> operator
Input redirection: Command < file
It is important to note that the file descriptor 0 typically a standard input ( STDIN ), 1 is the standard output ( STDOUT ), 2 is the standard error output ( STDERR )
- How to set up SSH remote control for Linux http://www.linuxidc.com/Linux/2016-03/129204.htm
- Enter Rpm-qa |grep ssh to find out if the current system has SSH installed
- Anti-single quotes ' function, anti-single quotes ' content will be executed first as CD ' Uname-r ' will go into the kernel directory
- $ about the shell PID Echo $$ can query the shell PID
- ? About the callback of the last execution instruction worth after we have executed an instruction, this command will return an executed code. In general, if executed successfully, it will return 0. If an error is performed, the error code is returned, typically expressed as a value other than 0. echo $?
- After using the read parameter [-p], it is allowed to follow a string after [-p] followed by a string of n shell variables. n Shell variables to receive strings entered from the Shell interface
[-p] Usage: read–p "string" Var1 var2...varn echo ${var1} ${var2}
- echo-e plus back \ plays an escape function, such as \ n for carriage return
- Date–help can get a help document for a command (note that two consecutive dashes--)
- View the network IP of the virtual Machine connection: Enter Ifconfig.
- Touch is primarily used to modify the file timestamp, creating a nonexistent file
- The/ETC/INIT.D directory contains the start-and-stop scripts for various services in the Linux system. Service startup: service** (script) Start
- chmod 777-r bbb/aaa/This command changes all the files under the directory and subdirectories.
- netstat–nlp|grep8080 to see if the port is occupied (and also see the PID number that occupies the port)
- RM–RF XXX Delete all files under its directory and sub-directory
- Nohup./gas.sh & Background Boot gas.sh file (its output is recorded in the Nohup.out file)
- Cat Nohup.out viewing log records
- Ps-ef querying all running processes
- Ps-ef|grep java* queries All processes that contain Java
- Systemctl Status Firewalld View firewall status
- The way to kill the process in one step:
<1>$ Pgrep Firefox | Xargs Kill-s 9 pgrep is specifically used to query the process PID, the Xargs command is used to put the output of the preceding command (PID) as a parameter of the "Kill-s 9" command, and execute the command. "Kill-s 9" will forcibly kill the specified process.
<2>$ Ps-ef | grep Firefox | awk ' {print $} ' | Xargskill-9 the role of awk ' {print $} ' is to print out the contents of the second column, and the second column is exactly the PID number
<3> $kill-S 9 ' pgrep Firefox '
<4> $pkill-9 Firefox Pkill=pgrep+kill
36.iptable
37.cat can view the file, the whole file will be displayed in full;
More file name: The system pauses when displaying a full screen, use a space to turn pages, and use the Q key to exit.
Less file name: The system also pauses when displaying a full screen, but you can use the upper and lower keys to roll the screen, when the end only need to enter Q after:
38.
Grep–n: Display matching line and line numbers
39.cut takes part of a line of information, and grep takes a row or rows of analysis out of many rows
Second, shell script scripts
1. The System service services startup interface is under the/etc/init.d/* directory. (centos6.x)
2. The script that starts MySQL will automatically log in with a blank password.
3. Run the script: The common method is = = = Enter the directory where the script is located, run./xxx.sh (. = current directory)
4.exit allows the program to interrupt and return a value to the system
5.$? The execution of the previous command is displayed, and the system default of 0 indicates a successful execution, and a non-0 indicates a failure
6.read–p "Pleaseinput:" Var1 var2 (remember that there must be a space between the message and the variable)
Read means reading a line from standard input,-p for "prompt statement, present", var1 var2 to represent the variable
"Read the variable var can be only one or more, if you enter more than one data, then the first data to the first variable, the second data to the second variable, if the number of input data too many, then all the last value will be given to the last variable"
7.${} can be used to take variable values
Generally there is a read-p "Please enter a parameter:" fileuser (variable parameter)
That is, when you are prompted to enter parameters, but you enter directly, this time Fileuser is empty.
The above sentence means: Fileuser variable is not set or empty, filename takes "-" the value behind; otherwise filename= $fileuser
9.$ (date +%y%m%d) is the result of executing the code inside, ${} is a parameter
Date=${date–d "1 days Ago" +%y%m%d} can get the day before
var=$ (Operation content) operation content can be subtraction, etc.
11.echo–e back to escape function
Note: When using SH or./execute script, the system will give a new bash subroutine to execute the instruction, and when the subroutine executes, the variables in the subroutine will not be passed back to the parent program.
Test-f aaa.sh && echo "Exist" | | echo "not exist" test file exists, result output exists or does not exist
13. Judgment symbol: [], note that each component of the brackets requires a space character to interval [${home}]
(more commonly used in if......then ...) In
14.shell default variable (built-in variable): ${0} or $ A to indicate the script name; ${1} or $ = first parameter of script (total 0-9 total 10 parameters supported)
Shift can move the parameter, followed by a number. The representative takes away the meaning of the first few parameters
Sh aaa.sh a b c d E F: Indicates that several parameters (a B c D E F) are given aaa.sh when running aaa.sh
15. Conditional Judgment Type
Declare can be used to define a parameter
16.function: The function is set in front of the program so that it can be called
function PrintIt () {
Program Segment
}
When invoked: Use PrintIt; Can
function also has built-in variables, but its built-in variables are obtained from the arguments immediately following the function name at the time of invocation.
Until do done (indeterminate loop)
18.for do-Done (fixed loop)
19. $ () and ' (anti-quote) are used for command substitution.
$ (date-d "last Sunday" +%y-%m-%d)
$ (()) is used for integer arithmetic.
$ (($a + $b * $c))
20.
Third, regular expression
Linux Common commands