From: http://www.ixpub.net/thread-619016-1-1.html
Tar command
[Root @ Linux ~] # Tar [-cxtzjvfppn] file and directory ....
Parameters:
-C: Create a parameter command for the compressed file );
-X: Unlock the parameter command of a compressed file!
-T: view the files in the tarfile!
Note that C/X/T can only exist under the parameter! Cannot exist at the same time!
Because it is impossible to simultaneously compress and decompress.
-Z: does it have the gzip attribute at the same time? That is, do I need to use gzip for compression?
-J: Does it have Bzip2 attributes at the same time? That is, do I need to use Bzip2 for compression?
-V: The file is displayed during compression! This is common, but it is not recommended to use it in the background execution process!
-F: use the file name. Please note that the file name should be followed immediately after F! Do not add parameters!
For example, using "Tar-zcvfp tfile sfile" is an incorrect method.
"Tar-zcvpf tfile sfile" is correct!
-P: use the original attributes of the original file (the attributes will not be changed based on the user)
-P: absolute paths can be used for compression!
-N: a new date (yyyy/mm/DD) will be packed into the new file!
-- Exclude file: do not pack the file during compression!
Example:
Example 1: package all the files in the/etc directory into/tmp/etc.tar
[Root @ Linux ~] # Tar-CVF/tmp/etc.tar/etc <= package only, do not compress!
[Root @ Linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= compressed with Gzip
[Root @ Linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= compressed with Bzip2
# Note that the file name after parameter F is obtained by ourselves. We use. tar for identification.
# If the Z parameter is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~
# If you add the J parameter, use .tar.bz2 as the file name ~
# A warning message is displayed when the preceding command is executed:
# "Tar: removing leading '/' from Member names" is a special setting for absolute paths.
Example 2: Check the files in the above/tmp/etc.tar.gz file?
[Root @ Linux ~] # Tar-ztvf/tmp/etc.tar.gz
# When we use gzip to compress the files in the TAR file,
# Add the Z parameter! This is important!
Example 3: Decompress the/tmp/etc.tar.gz file under/usr/local/src.
[Root @ Linux ~] # Cd/usr/local/src
[Root @ Linux SRC] # tar-zxvf/tmp/etc.tar.gz
# By default, We Can uncompress files anywhere! In this example,
# First, I will transform the working directory to the/usr/local/src directory, and unlock/tmp/etc.tar.gz,
# The unlocked directory will be in/usr/local/src/etc! In addition, if you enter/usr/local/src/etc
# The file attributes in this directory may be different from those in/etc!
Example 4: Under/tmp, I only want to unbind the etc/passwd in/tmp/etc.tar.gz.
[Root @ Linux ~] # Cd/tmp
[Root @ Linux TMP] # tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can use tar-ztvf to check the file name in the tarfile. If you only need one file,
# You can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!
Example 5: Back up all the files in/etc/and save their permissions!
[Root @ Linux ~] # Tar-zxvpf/tmp/etc.tar.gz/etc
# This-P attribute is very important, especially when you want to keep the attributes of the original file!
Example 6: only new files in/home are backed up.
[Root @ Linux ~] # Tar-N '2014/1/01'-zcvf home.tar.gz/home
Example 7: I want to back up/home,/etc, but not/home/dmtsai
[Root @ Linux ~] # Tar -- exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc
Example 8: package/etc/and unpack it under/tmp without generating a file!
[Root @ Linux ~] # Cd/tmp
[Root @ Linux TMP] # tar-CVF-/etc | tar-xvf-
# This action is a bit like CP-r/etc/tmp ~ It is still useful!
# Note that the output file is changed to-and the input file is changed to-, and there is another file | Yes ~
# This represents standard output, standard input, and pipeline commands respectively!
# This part will be explained again when we mention this command in bash shell!
Gzip and zcat commands
[Root @ Linux ~] # Gzip [-CDT #] File Name
[Root @ Linux ~] # Zcat file name .gz
Parameters:
-C: outputs compressed data to the screen and can be processed through data stream redirection;
-D: extract parameters;
-T: it can be used to check the consistency of a compressed file ~ Check whether the file has any errors;
-#: Compression level.-1 is the fastest, but the compression ratio is the worst.-9 is the slowest, but the compression ratio is the best! Default Value:-6 ~
Example:
Example 1: Convert/etc/man. config to/tmp and compress it with Gzip
[Root @ Linux ~] # Cd/tmp
[Root @ Linux TMP] # cp/etc/man. config.
[Root @ Linux TMP] # gzip man. config
# At this time, man. config will become man.config.gz!
Example 2: Read the content of Example 1!
[Root @ Linux TMP] # zcat man.config.gz
# The man.config.gz extracted file content is displayed on the screen !!
Example 3: Decompress the file in Example 1
[Root @ Linux TMP] # gzip-D man.config.gz
Example 4: compress man. config unlocked in Example 3 with the optimal compression ratio and keep the original file
[Root @ Linux TMP] # gzip-9-C man. config> man.config.gz
Bzip2, bzcat command
[Root @ Linux ~] # Bzip2 [-CDZ] File Name
[Root @ Linux ~] # Bzcat file name .bz2
Parameters:
-C: output the data generated during the compression process to the screen!
-D: extracted Parameters
-Z: Compression Parameters
-#: Same as gzip, it is used to calculate the compression ratio.-9 is the best, and-1 is the fastest!
Example:
Example 1: compress/tmp/man. config with Bzip2
[Root @ Linux TMP] # Bzip2-Z Man. config
# At this time, man. config will become man.config.bz2!
Example 2: Read the content of Example 1!
[Root @ Linux TMP] # bzcat man.config.bz2
# The man.config.bz2 extracted file content is displayed on the screen !!
Example 3: Decompress the file in Example 1
[Root @ Linux TMP] # Bzip2-D man.config.bz2
Example 4: compress man. config unlocked in Example 3 with the optimal compression ratio and keep the original file
[Root @ Linux TMP] # Bzip2-9-C man. config> man.config.bz2
Compress command
[Root @ Linux ~] # Compress [-DCR] file or directory
Parameters:
-D: extract parameters.
-R: It can be compressed together with files in the directory!
-C: Output compressed data to standard output (output to the screen)
Example:
Example 1: Convert/etc/man. config to/tmp and compress it
[Root @ Linux ~] # Cd/tmp
[Root @ Linux TMP] # cp/etc/man. config.
[Root @ Linux TMP] # compress man. config
[Root @ Linux TMP] # ls-l
-RW-r -- 1 Root 2605 Jul 27 :43 man. config. Z
Example 2: Unlock the compressed file
[Root @ Linux TMP] # compress-d man. config. Z
Example 3: compress man. config into another file for backup
[Root @ Linux TMP] # compress-C man. config> man. config. Back. Z
[Root @ Linux TMP] # ll man. config *
-RW-r -- 1 Root 4506 Jul 27 :43 man. config
-RW-r -- 1 Root 2605 Jul 27 :46 man. config. Back. Z
# This-C parameter is interesting! He will output the data from the compression process to the screen, instead of writing the data
# File. Z file. Therefore, we can output data to another file name through data stream redirection.
# Concerning data stream redirection, we will discuss it in detail in bash shell!
dd command
[root @ Linux ~] # Dd If = "input_file" of = "outptu_file" BS = "block_size" \
COUNT = "Number"
parameter:
if: input File ~ It can also be a device!
of: output file ~ It can also be a device.
BS: the size of a planned block. If no value is set, the default value is 512 bytes.
count: the number of BS.
example:
Example 1: Back up/etc/passwd to/tmp/passwd. Back
[root @ Linux ~] # Dd If =/etc/passwd of =/tmp/passwd. back
3 + 1 records in
3 + 1 records out
[root @ Linux ~] # Ll/etc/passwd/tmp/passwd. back
-RW-r -- 1 Root 1746 Aug 25/etc/passwd
-RW-r -- 1 Root 1746 Aug 29/ TMP/passwd. back
# Take a closer look. The size of my/etc/passwd file is 1746 bytes, because I have not set BS,
# therefore, the default value is 512 bytes. Therefore, the above 3 + 1 indicates that three complete bytes exist.
#512 bytes, and the meaning of another block under 512 bytes!
# In fact, it seems like the CP command ~
Example 2: backup/dev/hda MBR
[Root @ Linux ~] # Dd If =/dev/hda of =/tmp/MBR. Back BS = 512 COUNT = 1
1 + 0 records in
1 + 0 records out
# You have to understand this ~ We know that the MBR of the entire hard disk is 512 bytes,
# It is the first sector on the hard disk. Therefore, I can use this method
# Record all the data in the MBR. It's really amazing! Pai_^
Example 3: Back up the entire/dev/hda1 partition.
[Root @ Linux ~] # Dd If =/dev/hda1 of =/Some/path/filenaem
# This command is amazing! Back up all the content of the entire partition ~
# The following of must not be in the/dev/hda1 directory ~ Otherwise, you cannot finish reading ~
# This action is very useful. If you need to complete the content of the entire partition in the next day,
# You can use dd If =/Some/file of =/dev/hda1 to write data to the hard disk.
# If you want to back up the entire hard disk, it is similar to Norton's ghost software,
# From disk to disk, hey ~ You can use dd ~ Amazing!
cpio command
[root @ Linux ~] # Cpio-covb> <= backup
[root @ Linux ~] # Cpio-icduv <= restore
parameter:
-O: copy the data to a file or device.
-I: copy the information from the file or device to the System
-T: view the file or device content created by cpio
-C: A newer portable format storage method
-V: enables the file name to be displayed on the screen during storage
-B: increase the preset blocks value to 5120 bytes. The default value is 512 bytes!
This improves the storage speed of large files (refer to I-nodes).
-D: automatically create a directory! The contents of cpio may not be in the same directory.
in this case, there may be problems in the reverse backup process! When-D is added,
the required directory can be automatically created!
-u: automatically overwrites older files!
example:
Example 1: Write all data on the system to the tape drive!
[root @ Linux ~] # Find/-print | cpio-covb>/dev/st0
# generally, the tape drive using the SCSI interface is coded as/dev/st0!
Example 2: Check the files on the tape drive?
[root @ Linux ~] # Cpio-icvt [root @ Linux ~] # Cpio-icvt /tmp/content
# in the first action, the files in the tape drive are listed on the screen, however, we can use the second action to
# record all file names to the/tmp/content file!
Example 3: Restore the information on the tape ~
[Root @ Linux ~] # Cpio-icduv </dev/st0
# Generally, the serial number of the tape drive using the SCSI interface is/dev/st0!
Example 4: Back up all the "Files" under/etc to/root/etc. cpio!
[Root @ Linux ~] # Find/etc-type F | cpio-o>/root/etc. cpio
# Back up data ~ You can also use cpio-I </root/etc. cpio
# Capture the information !!!!