I. Packaging and compression of files
1.compress/uncompress
Compress [Options] file *. Z
-D: Uncompressed, equivalent to uncompress
-C: Output to screen
-R: Compressed directory
Zcat file. Z > File
2.gzip/gunzip
gzip [options] File *.gz
-C: Output to screen
-D: Unzip
-K: Keep source files
-#: Determine compression ratio, 1-9,1 is the worst 9 is best, default is 6
Gzcat: Uncompressed Preview Compressed file contents
Gzip can decompress Z-compressed files
3.bzip2
bzip2 [Options] File *.bz2
-C: Output to screen
-D: Unzip
-K: Keep source files
-#: Compression ratio, with GZ
Bzcat: With Gzcat
4.xzip
xzip [Options] File *.xz
-C
-D
-K
-#: Ibid.
Xzcat: Ibid.
Should be the latest compression decompression program, all the compressed size is the smallest
5.zip
Zip[options] File compressed after name file
-R: Compressed directory
Support for redirection, pipeline support
Cat/path/to/file | Zip Name-| Cat/path/to/file
-meaning to refer to the contents of the front
Unzip file decompression
The above centralized compression program, the most is GZ, with the most is bzip2, the latest is xzip,compress basically is not applicable, even if there is, you can also use a few other decompression
Two. Packaging Compressed files
1.tar: Packaging compression program, key program
tar [options] File/dir
There is a multi-option and a lot of common, but basically applies to packaging compression decompression, because the above compression program does not support the directory by default
So you need to use a tar program to package many files into a large file for compression
Mainly remember the following usage
TAR-CVF files/dir: File packaging
TAR-GCVF: Packaging compressed into GZ format
TAR-JCVF: Packaging compressed into bz2 format
TAR-JCVF: Package compressed into XZ format
TAR-TVF: Previewing compressed file contents
TAR-XVF: Unzip the following add-C to specify the location of the decompression
TAR-ZPVF: Backup
Sometimes a compressed file, we only need a part of it, tar can also be done
First, look at the contents of the file, search for the files you need, support pipeline
TAR-TVF File | grep "XXX"
After locating the file name
TAR-XVF file Target file
2.cpio Program: Same as package compression program, CPIO support redirection, and also support to unzip only some files
Cpio xxxx > equipment or files
Cpio xxxx < equipment or files
Basically use the following
Cpio-iov file > device or file backup files
-iv/idv Extracting files
-tv Preview File
The main thing is to support redirection
Two. Status Receipts
echo $? Each command executed will have a status receipt indicating whether the previous command was successful
The number of receipts is 2 in the case
0: Previous command executed successfully
1-255: The previous command failed to execute
Many times, we don't care about the results of the command itself, just want to know if the command is successful.
Executed, this time you can use a redirect to output the result to/dev/null and then view the variable $?
The value of the receipts is not successful execution, and to make judgments, scripts commonly used in
Custom Receipt Values
Exit # In the script, this is often used to determine the direction of the next step, and this value can be customized,
Add a number to the exit and the number will be the value of the successful receipt.
Three. Conditional Judgment (individual)
ture:0
False:1
Judging format
Test expression
[Expression] Two spaces
[[expression]] two spaces
1. Numerical determination of the size of the two sides of the value of the relationship
-eq: Equal values on both sides
-ne: The values on both sides are unequal
-lt: Left less than right
-le: Left less than equals right
-GT: Left Big and right
-ge: Left big equals to right
2. The relationship between string judgments and judging strings
[n "Variable"]: Determine whether the variable is empty, is empty for the true
[z "variable]: Determine if the variable is not empty, is not NULL for the true
= =: Judge whether the strings on both sides want to wait
! =: Determine if the strings on both sides are not equal
<: Determine if the ASCII code of the left string is less than the right, less than the true
: Determine if the ASCII code of the left string is greater than the right, greater than the true
~=: Determines if the left string is matched to the pattern on the right.
3. File type, existence judgment
-A/-E: Judging whether a file is present, exists as true
-[FDBCLPS]: Determine what type of file is, is true
4. Authority judgment
-R: Determine if the file has Read permission, there is a true
-W: Write
-X: Execute
5. Special Authority judgment
-U: To determine whether the file has suid special permissions, there is a true
-G: Determine if a file or directory has sgid special permissions
-K: Determine if the directory has sickty special permissions
6. Judgment of the genus Group
-N: Determine if the file has been modified since the last read, there is a true
-O: Determines whether the current user is the owner of the file, is true
-G: Determines whether the user group of the current user is a group of files
7. File Time judgment
-EF: Determine whether the left and right two files are the same file, that is, the same partition of the same node file
-ot: The time to determine the left file is not the right file early, modify the time Mtime
-nt: The time to judge the left file is not more than the right night, modify the time Mtime
Four. Conditional judgment (plural direction)
1.&& and | | Or! Non -
Format Command1 && Command2
Command1 | | Command2
! Command
About && | | ! Plus the relationship between the different or ^ mentioned before
&&:
1&&1 really
1&&0 Fake
0&&1 Fake
0&&0 false can be seen, the current side of the command is false, the following command does not need to run, because the result must be false, so the command behind
The operating condition is to ensure that the front command is true
|| :
1| | 1 true
1| | 0 true
0| | 1 true
0| | 0 false can be seen, the current side of the command is false, want to know the final result is not really, need to run behind the command, but the former
Side of the command if it is true, then you do not need to run the following command, so the command to run, the need to ensure that the front and the command is False
The above two relationships are often used in commands or scripts to actually judge the execution of that subsequent command, such as the script below
#!/bin/bash
#author
#version
#description
[-e/etc/nologin] && rm-f/etc/nologin | | Touch/etc/nologin
The content of the above script means
[-e/etc/nologin] View/etc/nologin This file is not present
&& rm-f/etc/nologin If, existing, that is, the front [-e/etc/nologin] is true, then you must run && the command behind it to delete Nologin
If, does not exist, is the front [-e/etc/nologin] is false, then the RM command behind will not run
|| Touch/etc/nologin if Nologin exists, that is to say [-e/etc/nologin] is true, it will run RM, then | | The command at the front is true,
Touch commands are real and true, so the touch command is not necessary and will not run
If Nologin does not exist, [-e/etc/nologin] is false, then RM will not run, then, | | All the front is false
So long you need to run the touch command to create a nologin
! : The meaning of right and wrong
XOR: The symbol of XOR is ^, meaning that the contents of both sides of the command are true, then the final result will be false, when both sides of the content has a false, then the last
The result is true, just say to ask for a different side of the line
For example [-W file2] && [-R File2] File2 has read and write permission, there is a true, there is no false for
[-W file2] | | [-R File2] File2 has read or write permission, neither is false, the rest is true
[ ! -R File2] File2 does not have Read permission, there is false, no for true
2.-a-o!
These characters are mentioned in the Find command, and the usage is basically equivalent,-A is and means,-o is or means,! The meaning of right and wrong (!) The place to express non-meaning has so far learned a lot, but
Only in the SED command,! It is written in the back of the address to indicate the non-meaning, the rest is written in the front)
format [expression-a-expression]
[Expression-o-expression]
! [Expression-a/-o expression] Notice that almost all places have a space
There is no change in the meaning, just two [] parts are written in one,! Also placed in the [] outside, it is worth noting! Effects on-A and-o within []
To consider Morgan's law.
Five. Not finished with rpm
RPM Simple to understand the installer installation package program, similar to the window on the download function of a software manager
Basically remember that the following usage is
Rpm-ivh
I: is interactive mode
V: is verbose, show the specific process
H: To make a progress bar with the # sign
Such a ###########################################>100%
The rest is written together with Yum.
Six. Read command
The read command is used to assign values to variables in bulk.
Enter interactive mode when the Read xx1 xx2 xx3 is entered
----------Screen Show this thing let you enter the content, the input will correspond to the contents of the variable xx, enter the end, multiple variable spaces separated
However, one of the problems is that read has multiple variable contents separated by spaces when it is assigned to variables in bulk, so it is easy to read errors, such as
Read Xx1 xx2 xx3 xx4
A B c D f
echo $xx 1
A
Echo $xx 2
B
Echo $xx 3
C
Echo $xx 4
Df
The rest of the content is assigned to the last variable by default, so it is necessary to have a variable of one content, not more
-P "Content": Displays the prompts to be made to appear
-T: Give a cutoff time, how long does not enter the assignment value, the default is the second unit. There seems to be no change to units.
This article from "Blog Work First Edition" blog, declined reprint!
0527 Nineth Session