In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Linux backup and compression command instructions", in daily operation, I believe many people in Linux backup and compression command instructions on the use of doubt, Xiaobian consulted all kinds of information, sorting out simple and easy to use operation methods, I hope to answer "Linux backup and compression command instructions" doubts helpful! Next, please follow the small series to learn together!
tar command
The tar command is used to create archives and extract archives.
Syntax:
grammar is
tar [command switch] [compressed package] [file or directory to be compressed packaged]
Command switches:
-c Create archive, create backup-x Extract archive, restore backup. - f Create an archive given the filename. - tDisplays or lists files in the archive. - u Archive and save to existing archive files. - v Displays archived details. - A. Connect archive files.
Examples:
To archive a file or directory:
tar -cvf backup.tar /etc
This command creates an archive file named backup.tar, which is an archive of the/etc directory.
Here, backup.tar-is the tar file created./ etc-is the directory that is archived.
Archive a directory or file and store it in a storage device:
tar -cvf /dev/fd0 /home/user1/HGB
This command will archive the/etc directory and store it on floppy disk.
Here,/dev/fd0-is the name of the floppy disk where the archive file is stored./ home/user1/HGB-is the archived directory.
Extract archive files:
tar -xvf backup.tar
This command will extract the backup.tar file.
List files in archive:
tar -tvf backup.tar
The above command displays the files and directories archived in the backup.tar file.
gzip command
Reducing file size has two obvious benefits: it reduces storage space and reduces transfer time when transferring files over the network. Gzip is a command that is often used in linux systems to compress and decompress files, both convenient and easy to use.
Syntax: gzip [option] Compressed (decompressed) filename
Meaning of each option:
-c Writes the output to standard output and retains the original file.
-d Extract compressed files.
-l For each compressed file, display the following fields:
Size of compressed file
Size of uncompressed file
compression ratio
Name of uncompressed file
-r Recursively searches the specified directory and compresses or decompresses all files in it.
- tTest to check if the compressed file is complete.
-v For each compressed and decompressed file, displays the file name and compression ratio.
-num Adjusts the speed of compression with the specified number num,-1 or-fast for the fastest compression method (low compression ratio),-9 or-best for the slowest compression method (high compression ratio). The system default is 6.
Suppose a directory/home contains the files mm.txt, sort.txt, xx.com.
Example 1: Compress each file in/home into a.gz file.
$ cd /home
$ gzip *
$ ls
m.txt.gz sort.txt.gz xx.com.gz
Example 2: Extract each compressed file from Example 1 and list the details.
$ gzip -dv *
mm.txt.gz 43.1%-–replaced with mm.txt
sort.txt.gz 43.1%-–replaced with sort.txt
xx.com.gz 43.1%-–replaced with xx.com
$ ls
mm.txt sort.txt xx.com
Example 3: Display the information of each compressed file in Example 1 in detail without decompression.
$ gzip -l *
compressed uncompr. ratio uncompressed_name
277 445 43.1% mm.txt
278 445 43.1% sort.txt
277 445 43.1% xx.com
$ ls
mm.txt.gz sort.txt.gz xx.com.gz
Example 4: Compressing a tar backup file, such as usr.tar, with the extension.tar.gz
$ gzip usr.tar
$ ls
usr.tar.gz
unzip command unzip file under linux
Linux comes with the unzip command can extract windows zip format compressed files.
unzip command
Syntax: unzip [options] zip file name.zip
The meaning of each option is:
-x File list unpacks files, but does not include the specified file file.
-v View the compressed file directory without extracting it.
-t Tests files for corruption, but does not extract them.
-d directory Unzip compressed files to specified directory.
-z Displays only comments for compressed files.
-n does not overwrite existing files.
-o Overwrites existing files and does not require user confirmation.
-j Unzip all files into the same directory without reconstructing the directory structure of the document.
Example 1: Unzip the compressed file text.zip in the current directory.
$ unzip text.zip
Example 2: Extract the compressed file text.zip in the specified directory/tmp. If the same file already exists, ask the unzip command not to overwrite the original file.
$ unzip -n text.zip -d /tmp
Example 3: View the compressed file directory, but do not extract it.
$ unzip -v text.zip
At this point, on the "Linux backup and compression command use instructions" on the end of the study, I hope to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.