In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the commands for backing up files in linux. The content of the article is of high quality, so I share it with you for reference. I hope you can get something after reading this article.
1.tar (Compression and decompression)
-c: create compressed files
-x: decompression
-t: view content
-r: appends files to the end of the compressed archive file
-u: update the files in the original package
These five are independent commands, one of which should be used for compression and decompression, which can be used with other commands, but only one of them can be used.
The following parameters are optional when compressing or decompressing files as needed.
-z: with gzip attribute
-j: with bz2 attribute
-Z: with compress attribute
-v: show all processes
-O: unlock files to standard output
The following parameter-f is required
-f: use the file name and remember that this parameter is the last parameter and can only be followed by the file name.
# tar-cf all.tar * .jpg
This command is to type all .jpg files into a package called all.tar. -c means to generate a new package, and-f specifies the file name of the package.
# tar-rf all.tar * .gif
This command adds all .gif files to the all.tar package. -r means to add files.
# tar-uf all.tar logo.gif
This command updates the logo.gif file in the original tar package all.tar, and-u means to update the file.
# tar-tf all.tar
This command lists all the files in the all.tar package.-t means to list files.
# tar-xf all.tar
This command is to unlock all the files in the all.tar package,-t means to unlock
Compress
Tar-cvf jpg.tar * .jpg / / package all jpg files in the directory into tar.jpg
Tar-czf jpg.tar.gz * .jpg / / package all jpg files in the directory into jpg.tar and compress them with gzip and name them jpg.tar.gz
Tar-cjf jpg.tar.bz2 * .jpg / / package all jpg files in the directory into jpg.tar and compress them with bzip2 and name them jpg.tar.bz2
Tar-cZf jpg.tar.Z * .jpg// packages all the jpg files in the directory into jpg.tar and compresses them with compress, which is named jpg.tar.Z
For rar a jpg.rar * .jpg / / rar format, you need to download rar for linux first.
For compression in zip jpg.zip * .jpg / / zip format, you need to download zip for linux first
Decompression
Tar-xvf file.tar / / extract the tar package
Tar-xzvf file.tar.gz / / decompress tar.gz
Tar-xjvf file.tar.bz2 / / decompress tar.bz2
Tar-xZvf file.tar.Z / / decompress tar.Z
Unrar e file.rar / / decompress rar
Unzip file.zip / / decompress zip
Summary
1. Tar is decompressed with tar-xvf
2. *. Gz is decompressed with gzip-d or gunzip
3. * .tar.gz and * .tgz are decompressed with tar-xzf
4. * .bz2 decompress with bzip2-d or bunzip2
5. * .tar.bz2 decompress with tar-xjf
6. * .Z decompress with uncompress
7. Tar.Z is decompressed with tar-xZf
8. *. Rar decompressed with unrar e
9. *. Zip decompressed with unzip
Example: compress a directory
Tar-cvf package name Project name
Tar-cvf AppStore_180808.tar AppStore
Example: decompress a tar package
Tar-xvf package name
Tar-xvf AppStore_180808.tar
2.cp (copy)
Cp copies a file or directory
Grammar
Cp [options] Source File destination File
Common options:
-a: equivalent to pdr
-d: copy the linked file, and the target file is also a linked file or directory that points to the source file link.
-I: when the target file already exists, it will be asked whether to overwrite
-p: copied along with the properties of the file. Often used for backup
-r: recursive replication, used to copy directories
-s: copy as a symbolic link file, that is, a shortcut, the linked file is deleted, and the symbolic link file is invalid.
-l: create a hard-linked file instead of copying the file itself. the source file is deleted and the target file is still there.
Source file:
For a single file or directory, copy the directory with the r option.
When multiple files or directories, multiple files or directories, the target file must be an existing directory.
Note:
Under the non-privileged user root, when an average user uses cp, you need to pay attention to whether the parent directory of the source file has rx permission. Whether the file has r permission.
When the general user uses the option-a, the permission time is copied to the performance, but the user and group properties cannot be copied to.
Example:
Root permissions to back up test1 files
Cp-a test1. / beifen
If you back up the directory directly, you can do the following
The instructions are as follows:
Cp-pdf + files to be backed up + files after backup
Extend:
How to use redirect command
1. Display normal strings:
Echo "It is a test"
The double quotation marks here can be omitted, and the following command has the same effect as the above example:
Echo It is a test
two。 Show escape characters
Echo "\" It is a test\ ""
The result will be:
"It is a test"
Similarly, double quotation marks can also be omitted
3. Display variable
The read command reads a row from the standard input and assigns the value of each field of the input line to the shell variable
#! / bin/shread name echo "$name It is a test"
The above code is saved as a variable that test.sh,name receives standard input, and the result will be:
[root@www ~] # sh test.shOK # standard input OK It is a test # output above is the command to back up files in linux. Have you learned anything after reading it? If you want to know more about it, you are welcome to follow the industry information. Thank you for reading.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.