Linux System Management----Storage Management (III)

Source: Internet
Author: User
Tags bz2 compress archive

Compression and decompression tools commonly used in Linux systems:
Compression: An operation that takes time to change space;
Implementation of compression: Tag + Replace
Compression ratio: The ratio of a file to the size of a file after the compress operation, and the larger the ratio, the smaller the compression result.
Generally speaking, the compression of plain text files is larger;

Compression tools commonly used in Linux:
Compress/uncompress (relatively coarse, less compact)
Is incremented after the file name. The suffix name of z; (XXX. Z)
Gzip/gunzip
Adds the suffix name of the. GZ after the file name; (xxx.gz)
Bzip2/bunzip2
Adds the suffix name of the. bz2 after the file name; (xxx.bz2)
XZ/UNXZ (currently a better compression tool)
The suffix name of the. XZ is incremented after the file name; (XXX.XZ)
Zip/unzip
Adds a. zip suffix name after the package name is compressed; (Xxx.zip)
Note: Keep the original file and create an additional compressed package file;


Gzip Tool
gzip, gunzip, Zcat-compress, unzip, view text content in a compressed state
Common options:
-D: Decompression, equivalent to Gunzip;
-#: Specifies the compression ratio used when compressing, valid range: 1-9;--fast =-1,--best = 9; default is-6;
-C: Output the compression results to the standard output, but not the original file compression processing;

BZIP2 Tools
BZIP2, Bunzip2-a block sort file compression software
Bzcat-Unzip the file to standard output
Bzip2recover-Recover corrupted bzip2 files
Common options:
-K: Do not delete the original file
-D: Unzip
-C: Output the compression results to the standard output, but not the original file compression processing;
-#: Specifies the compression ratio used when compressing, valid range: 1-9;--fast =-1,--best = 9; default is-9;

XZ Tool-A better compression tool (high compression will consume CPU too much)
XZ, Unxz, Xzcat, compressing, decompressing, viewing text content in a compressed state
Common options:
-D: Unzip
-K: Do not delete the original file
-#: Specifies the compression ratio used when compressing, valid range: 0-9, default is-6;
-C: Output the compression results to the standard output, but not the original file compression processing;

Zip tool
Zip-package and Compress (archive) files
Format:
Zip [options] [zip‐file [File ...]]
Common options:
-P: Compress and set the password

Unzip-l: View a list of files in a compressed package;


Tar command: Archive

Options:
Main options:
-C: Create an archive file
-R: Adds a new file to the end of an already existing archive file;
-T: The list shows the contents of a file;
-u: only append files to the end of the archive file that are newer than the content in the archive file;
-X: Get files from file, release files;
Accessibility Options:
-F: The option to indicate the file name when using the archive file;
-C: When releasing files in the file, do not release to the current directory, but specify an additional path to store the released files;
-j: Use the BZIP2 tool to compress the archive file when it is used to create the archive file;
-j: Use the XZ tool to compress an archive file when it is used primarily to create an archive file;
-Z: Use the gzip tool to compress the archive file when it is used to create the archive file;
-Z: Use compress tool to compress archive files when used to create archive files;
-K: When releasing files in the file, if the target location has the same name as the file, the file is not released, and the files in the file system will not be overwritten by the files with the same name;
-V: Shows the detailed process;
--exclude=pattern: Files that are PATTERN-matched when releasing files in the file will not be released;

(When using the TAR command, the main option after it is not used-)

Cpio Command-----
Copy files to and from archives



Write a script: Prompt the user to enter some path of the file, and let the user choose the compression method, according to user needs to archive the selected files compressed, if the user does not select the compression method is only archive uncompressed;




Two special types of files:
1. device files (Mknod command to create device files)
Its metadata is used to save the database block pointer location, storage is the device number information;
2. Symbolic Connection File
Its metadata is used to hold the data block pointer location, the other file is stored in the access path;

Link file:
Link: The process of associating the metadata portion of a file with the data part;
Access the path of a file
Hard Link: The data block pointer in the inode points to a link to the data block, called a hard link, and can also be interpreted as a different block of data for the same block of data pointer;
The data content of a file can be more than one meta-data, so there can be multiple hard links; The data represented by this file can be accessed using different paths;

Hard Link Features:
1. Cannot create hard links across file systems;
2. You cannot create a hard link to a directory;
3. Each time a hard link is established to the target file, its link count automatically increases the Inode reference count;

Symbolic links (soft links):
Stand-alone files
A file used to store access path information for a linked file;
Symbolic Link Features:
1. You can create symbolic links across file systems
2. Directories can also create symbolic links
3. The process of finding the data content of linked files through symbolic links becomes more cumbersome, because two sets of path information need to be found;


ln command
Establish a connection between files
Format:
ln [opition] ... [-T] Target Link-name
Common options:
-S: Create a symbolic link, or create a hard link if you do not add this option;
-V: Show Link creation process

Version Management for application publishing:
The different versions of the application are stored in different directories, linked to a version of the application directory through symbolic links, if the new version of the application problems, simply link the symbolic link file to a previous stable version to implement the application rollback;


Replace and find in Vim's last-line mode:
Or Perform pattern lookups;
The S command in the last command is the command to replace; s is the first to find and then replace according to the pattern;
: [Address]s/pattern/string/control
[Address]: Addresses delimiter
1. If omitted, indicates the line where the cursor is located;
2.# the line number represented by the number
3.$ represents the last line of the current document; $-1,$-2. second to third;
4.m,n from the first few lines to the first few lines;
5.m,+n n rows from the beginning of line m;
6./pattern/rows to which the pattern is matched
7./pattern1/,/pattern2/from the line that matches the pattern 1 to the end of the line to which the pattern 2 matches;
8.% all rows;
Pattern: The content to be replaced must be matched by pattern;
String: A pure string that does not recognize the metacharacters of the regular expression; (replaced by what)
CONTROL:
G: All matching characters in the current line are replaced;
C: Manual control of the replacement operation;


SED command
Sed:stream Editor, Stream editors
Line editing Operation Tool;
Sed in the implementation of text file processing, is the behavior unit one or more files for editing processing, each SED will process a given file in a row of content;

When working with a text file, sed stores the current row being processed in a temporary memory buffer, called the pattern space, which is the main work shop of the SED command, and for cached rows, using the given pattern to match, if the match succeeds, The corresponding command is used for editing, and if the match is unsuccessful, it is sent directly to the standard output; Continue processing the next line until the end of the document;

By default, the contents of the files processed by SED are done in memory and do not affect the contents of the files stored on the disk;

Sed has the meaning of loop traversal by default; sed can be used to simplify the loop traversal of files;

---stream editor for filtering and transforming text
Format:
sed [OPTION] ... ' Script ' [Inputfile][input-file] ...
Common options:
-N: For lines that cannot be matched by pattern are not sent to standard output;
-e script,--expression=script: multi-conditional editing;
-F Script-file,--file=script-file: reads the contents of the script from the specified file in the edit;
Note: Script-file is best specified with absolute path;
-i[suffix],--in-place[=suffix]: Directly modify the contents of the original document;
-r: Enables SED to support extended regular expressions;

Script:addresscommand (Address delimitation + command)
Address: Location Delimitation
1. Empty address: Represents all lines of the specified file;
2. Single address: SED handles the only row that can match the address;
#: Indicates the specified line number
/pattern/: All rows that can be matched to a pattern
$: Indicates the last line of the specified file; $-1 is not supported
3. Address range:
M,n:m rows to n rows; (including m,n rows)
M~n: Starting with M line, with N as step, all rows passed; (eg:1~2 = 1,3,5,7 ... line)
M,+n: N rows from the beginning of line m, (including m rows)
M,~n: Starting with M lines, looking backwards for m*n lines; (including M rows)
4./pattern1/,/pattern2/:
From the line that was first matched by the PATTERN1, to the end of the line that was PATTERN2 the first match, and then continues to match whether there is a line ending with the PATTERN1 match PATTERN2;

Command: Commands
1.=: Displays the line number of the line that is matched by pattern;
2.a \test: Append the test content after the line is matched by the pattern, and support "\ n" line wrapping, so as to realize the addition of multiple lines of information;
3.I \test: Inserts the test content before the line that is matched by the pattern, and supports "\ n" line wrapping, which enables the addition of multiple lines of information;
4.c \test: Modify the content of the pattern match to test content, support "\ n" line wrapping, so as to modify the original content as multi-line information;
5.D: Delete the matched rows in the pattern space (does not show the rows that are matched)
Note: the-n option is not recommended when using the D command, otherwise there will be no result;
6.P: Outputs the pattern matching rows in the pattern space to the standard output;
Note: It is generally recommended to use the-N option when using the P command;
7.W Filename:filename is a path; The W command stores pattern-matching rows in the pattern space into the specified file; (equivalent to Save As)
Note: It is generally recommended to use the-N option when using the W command;
8.R Filename:filename is a path; the r command adds the specified file contents to the line following the pattern match;

! Command: Lines in pattern space that are matched by pattern do not execute the specified command;

s///: Find and replace, separators can replace any symbol, but must be consistent;
S/regexp/replacement/[control]
RegExp: Regular expression, or pattern, the content that the plan finds and replaces is the content that can be matched by regexp;
Replacement: The result to replace, a plain string, and a back reference (S/\ (string\)/$/) | (S/\ (string\)/\1/)

Advanced Editing Commands:
H: Store the contents of the pattern space in the hold space, and overwrite the original content in the preserving space;
H: Store the contents of the pattern space in the hold space, and append to preserve the original content in the space;
G: Remove data from the hold space to the pattern space, and overwrite the original content in the pattern space;
G: Remove data from the hold space into the pattern space and append to the original content in the pattern space;
X: The content in the space and pattern space of the exchange;
N: Reads the next row of the line that is pattern matched and overwrites the pattern space;
N: Reads the next row of the line that is pattern matched and appends to the pattern space;
D: Delete all rows in the pattern space;

Linux System Management----Storage Management (III)

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.