Archiving and Compression of Linux Files

target content
file archive command
Create tar package - decompress - query tar package content



1. The benefits of file archiving command tar
archiving:  Easy to use, query, and
read Easy to manage (delete files in batches)

Why compress
? Direct transmission will consume a lot of traffic bandwidth, resulting in slow access to the company’s intranet.
Compression before transmission -- Decompression after transfer The benefits of

file compression
Save hard disk resources and
speed up file transfer Commands

used
: tar function: package and compress files; tar files are a collection of several files and (or) directories in a folder inside. Best tool for creating backups and archives

[root@xuegod72 ~]# tar --help
[root@xuegod72 ~]# tar -cf archive.tar foo bar #Package foo bar files into .tar
[root@xuegod72 ~] # tar -tvf archive.tar #List all files in tar
[root@xuegod72 ~]# tar -xf archive.tar #Ahead or release files in tar

Packaging
syntax: tar [parameter] name of the package target file/directory
Parameters:
 -c create create a file
 -x decompress and restore the file
 -v display the detailed process of execution
 -f specify the backup file
 -t list the contents of the backup file
 -P (uppercase) does not remove the root sign before the file name when using an absolute path,
 -C (uppercase) specifies the decompression location
 -z compresses via gzip
 -j decompresses via

bzip2 When specifying the name of the file, the suffix should be added according to the type of compression you want

[root@xuegod72 mnt]# tar -cvf grub2.tar /boot/grub2/
--archive [root@xuegod72 mnt]# tar -tvf grub2. tar|more --View files in archive
[root@xuegod72 mnt]# tar -cvfP grub2.tar /boot/grub2/ --Archive root directory (dangerous, may overwrite root directory after decompression)
[root@xuegod72 mnt]# tar -xvf grub2.tar -C /usr/src/ --extract and release -C specified location


In LINUX, how do you distinguish the type and suffix of the file,
such as the sh script aa

file command, check the file type
linux for the file extension It is not as strict as the requirements of windows, so in the process of using linux, we often encounter some files that have no extension at all. How should we judge whether a file without an extension is a file or a directory?
Function: Determine the file type
Syntax : file file name

[root@xuegod72 mnt]# file grub2.tar
[root@xuegod72 mnt]# file /etc/init.d/nginx

file file type


file
size vs. file size:
[root@xuegod72 mnt]# du -sh /boot/grub2/
[root@xuegod72 mnt]# ll - h /boot/grub2/


2. Linux file
compression tool: gzip bzip2 zip tar
3.1 Compression format
Common compression format: gz, bz2, xz, zip, Z
format (file name format): .tar.gz or .tgz
syntax Format: tar zcvf newfile.tar.gz SOURCE

tar.gz format
[root@xuegod72 mnt]# tar zcf grub2.tar.gz /boot/grub2 #Packaging and compression
[root@xuegod72 mnt]# tar zxf grub2.tar.gz # Unzip

tar.bz2 format
[root@xuegod72 mnt]# tar jcf grub2.tar.gz /boot/grub2 #Package and compress
[root@xuegod72 mnt]# tar jxf grub2.tar.gz #Unzip

rar format
[root@xuegod72 mnt]# rar a grub2.rar /boot/grub2 #Packaging and compression
[root@xuegod72 mnt]# rar x grub2.tar.gz #Decompression

zip format
[root@xuegod72 mnt]# zip -r grub2.zip /boot/grub2 #Package and compress
[root@xuegod72 mnt]# unzip grub2.tar.gz -d /tmp #Unzip

gzip format
[root@xuegod72 mnt]# gzip grub2.tar #Package and compress
[root@xuegod72 mnt]# gzip -d grub2.tar.gz #Decompress

bzip2 format
[root@xuegod72 mnt]# bzip2 -k grub2.tar #Package and compress
[root@xuegod72 mnt]# bzip2 -d grub2.tar.bz2 #Decompress

xz format
[root@xuegod72 mnt]# xz -zk grub2.tar #Packaging and compression
[root@xuegod72 mnt]# unxz -dk grub2.tar.xz #Decompression

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326375548&siteId=291194637