* * Common commands for basic Linux operations (III)
* * Linux Packages
Linux software is divided into "source package" and "binary package"
SOURCE Bundle: Free, open source
Binary Package: System default package, ie RPM package (last section we unloaded over OpenJDK by RPM), more commonly used
Characteristics:
* After compiling
* Install, uninstall, upgrade, query directly using the command to operate
* Installation speed is faster than the source package, omitting the compilation process.
* Installation has dependencies
For example: Install a package 03, if you need to install a package 02, and install a package 02, and need to install a package 01 in advance, that is, in the installation package 03 o'clock, if the first few packages are not installed, then the package 03 can not be installed directly.
* * RPM Command 1, the main CentOS management method: RPM2, RMP management of the end of the package rpm (next we want to use this command to install a RPM program to try) 3, mount the optical drive
mount/dev/cdrom/media/
Mount Optical drive to mount point media
After the mount succeeds, it appears:
Optical drive file is read-only, not writable 4, enter the CD, that is, switch to the CD-ROM mount point directory
cd/media/
Then use the Ls-l command to view the file structure under the optical drive:
Switch to the Packages directory, view the directory file, and you will find all the installation packages that end in. RPM:
Here you can use LS | Wc-l to see the total number of RPM installation packages 5, installation
Use command: RPM-IVH zlib-devel-1.2.7-15.el7.x86_64.rpm
ZLIB-DEVEL-1.2.7-15.EL7.X86_64.RPM for an installation package, remember to use the TAB key to complete the smart, otherwise you need to play the file name.
Parameter explanation:
-I: Installation
-VH: Shows the progress at the time of installation
6. Uninstall
Rpm-e zlib-devel-1.2.7-15.el7.x86_64
Rpm
Parameter explanation:
-E: Uninstall
7. Enquiry
Rpm-qa See which RPM packages are already installed on the current system
-q:query Query
-a:all All
8, the query file belongs to which RPM installation package
Rpm-qf/etc/ntp.conf
Parameter explanation:
-f:file file
* * Yum command 1, batch solve RPM dependency problem
When we use the RPM command to install a file, we need to solve a series of dependency problems, namely, install package 03, need to find and install package 02, install package 02, need to find and install package 01, this operation is cumbersome and inefficient, yum command can automatically find and install all dependencies, very convenient.
2. Enquiry
Yum List
This command lists the RPM packages for all installed packages in the system, for example:
3, the update on the right indicates that the installed package has updates available 4, installation
Yum-y install httpddevel.x86_64, which is installed httpddevel.x86_64
The installation process relies on speed 5, uninstall
Yum-y Remove httpddevel.x86_64
(Scream Hint:-y indicates yes, that is, there is a confirmation prompt, yes or no,-y, that is, all yes, simple rough) when installing a dependent package in bulk
6. Yum Warehouse
Path:/etc/yum.repos.d/
Configuration: Centos-base.repo is the end of the. Repo
Gpgcheck=1 representative whether to open the school check (0 is not open)
Gpgkey= the location of the public key of the school check
7. Common errors:
* External network is different: Check the network card settings, check the IP settings, check the DNS settings
* Cannot download: Check whether the warehouse is correct
* * Shell Programming
What is shell, I suggest you Baidu a bit.
In short: the shell interpretation layer, for the outer application and memory interaction, for example, you use the LS command, is a LS script, which is named LS shell script, ls is a command, it can be understood that LS is a file, the file is saved a series of code, The code is called a shell script, and the process of using the LS command is the process of executing a script with the file name LS.
Displays the shell environment supported by the current system:
One of the most commonly used shells in Linux is bash
1. Environment variables
Save environment variables when the system is running
User variables:
. bash_profile
Each user has an environment variable to hold each user, not shared with other users
System variables:
/etc/profile
The system is globally active, and all users under the system share the file
(Scream hint: this is the same as the admin mode under Windows)
2. Position variable
The parameters passed to the script are saved in the location variable to facilitate reference to the parameters in the script, similar to the formal parameters of the function in programming.
9 positional variables are defined in bash: $1.....$9$0 represents the script name
Now create a. Sh script, such as VI zz01.sh, with the following:
#!/bin/bash
Echo
Echo
echo $
echo $
Passing parameters are separated by a space,
#!/bin/bash This sentence means: Identify the current SH script as Bash
Next, execute the script, sh zz01.sh aa bb cc DD
where the AA BB cc DD is the parameter, the output result:
DD is actually passed in, but in the 4th position, and our script does not use Echo to print the fourth position of the parameters, so no display, you can find a careful comparison of the law.
3. Pre-defined variables
$: Current script name
$!: Process PID, each process has a number
$$: Current Process ID number
$#: Number of parameters for the current shell
$*: Show all parameter contents (whole)
[Email protected]: Show all parameter contents (read one by one)
$?: The delegate that represents the exit of the program (returns 0 for success, returns non 0 for failure)
4. Custom variables
Syntax format:
Name=[value]
There can be no spaces on either side of the equal sign, the variable name is case sensitive, and the value of the variable is called later using the $ variable name
Example: a=2 echo $a
5, logical symbol &&: Logic and
CMD1 && CMD2
Has a short circuit effect
For example:
CAT/ETC/PASSWD && mkdir zzz/
Explain:
If the file is not successful (for example, the file does not exist), then the mkdir zzz/command is not executed and the command is executed instead
|| : Logical OR
cmd1 | | Cmd2
Has a short circuit effect
For example:
cat/etc/passwd | | mkdir zzz/
Explain:
If the file is viewed successfully, the mkdir zzz/directive will not execute directly, or vice versa, then execute the command behind it.
No logical symbols
CMD1; cmd2
For example:
CAT/ETC/PASSWD; mkdir zzz/
Explain:
Execute the two commands sequentially
6. Arithmetic arithmetic
Format:
1, $ ((expression)) 2, $[expression] 3, expr expression
For example:
a=10
B=20
1. Echo $ ((a+b))
echo $ (($a + $b))
2. Echo $[a+b]
echo $[$a + $b]
3. Expr A+b
Expr $a + $b
Multiplication: expr $a \* $b
Note: \* There are spaces between the left and right sides
7, built-in test to determine the numerical test:
-eq: Equals
-ne: Not equal to
-le: Less than or equal to
-ge: greater than or equal to
-LT: Less than
-GT: Greater Than
For example: [2-eq 2] Returns the result as true, and so on
String test:
=: Equals is True
! =: Unequal is true
-Z: null string length is True
-N: True if string length is not empty
File test:
-e File name: True if the file exists
-r file Name: True if the file exists and is readable
-W file name: True if the file exists and is writable
-X File Name: True if the file exists and is executable
-S file name: True if the file exists and has at least one character
-D file Name: True if file exists and is directory
-F file Name: True if the file exists and is a normal file
-C file Name: True if the file exists and is a character-specific file
-B file Name: True if the file exists and is a block special file
Linux also offers non-(! ), or (-O), and (-a) three logical operators to connect the test conditions to the order of precedence:! >-a >-o8, Time command
Date: Time command to view the current system time, for example:
Modification Time:-S, for example:
Date-s "2015-05-09 10:20:30",
View time:
Date "+%y%m%d%h%m",
Which YMDHM each representative what, their own control can understand.
Time Operation:
Back to 5 days ago:
Date-d ' 5 day ago ' +%y%m%d%h%m ',
Other usages can be viewed using the man command, and if you forget, swipe to the bottom of the page to view 9, writing the specifications of the shell script
* generally end with. SH for easy identification of file types
* General Opening annotated: #!/bin/bash to indicate that this is a bash shell
(Scream tip: The bash shell is the default shell environment for the CentOS system)
10. For loop Syntax 1: Syntax 2:
Example 1:vi for01.sh, edit the following:
Execution: Sh for01.sh, the result is as follows:
Example 2:vi for02.sh, edit the following:
\ t is a tab table
(Scream tip: If do and for are not on one line, you can omit semicolons;)
Execution: Sh for02.sh, the result is as follows:
11. While loop Syntax 1: Syntax 2:
Example 1:vi while01.sh, edit the following:
Execution: Sh while01.sh, the result is as follows:
Let keyword explanation:
If they are just let a=1 and a=1, they are no different, but lets can also be used for operations with assignments, such as
Let A=1+5
Echo $a
The results of the calculation are 6, and
A=1+5
Echo $a
Get a string 1+5
Example 2:vi while02.sh, which reads as follows:
The script reads every line of the passwd file and prints it out
Execution: Sh while02.sh, the result is as follows:
12. awk command
This command can not be explained clearly in two words, please refer to the blog (to respect the author, please link the past)
Http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html
Simple example:
cat/etc/passwd | Awk-f ': ' {print $ \ t '
13. If command Syntax 1: Syntax 2:
Example 1:vi if01.sh, edit the following:
Execution: Sh if01.sh, the result is as follows:
For example 2:vi if02.sh, the content is edited as follows:
Functional explanation: Whether there is a directory./123, if present, lists the files under that directory, and if not, creates the directory
Execution: sh.if02.sh, the results are as follows:
You can see that this directory was created with 123
14. Case statement Syntax 1:
Syntax 2:
Example 1:vi case01.sh, edit the following:
Execution: Sh case01.sh gameover,
If an incoming parameter does not match to a case, the default execution *) is a wildcard condition. (AAA parameters, for example)
* * Extra:
(Scream tip: Use the man command to see specific help for a command)
(Scream hint: use the which command to see the exact location of the command, such as: Which VI,)
(Scream hint: Use the RPM-QF command to pass in a specific location, you can view the command path of the installation package,)
* * Summary
Judging the test may be more fragmented, not easy to remember, more operations can be. Circular grammar and the like, understand that 1, 2 can comprehend by analogy, heavy in understanding.
Personal micro-Blog: http://weibo.com/seal13
QQ Big Data Technology Exchange Group (ADS do not enter): 476966007
Z The best
Links: Https://www.jianshu.com/p/21cd6afa40f7
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Linux Fundamentals 03