Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

File compression and archiving

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Data compression is a technology to reduce the amount of data without losing data information.

Compress

Compress is an ancient compression tool with a .Z suffix for compressed files.

-d: decompress-c: output the result to standard output without deleting the original file-v: display details

Use the example

[root@centos7 / testdir] # compress passwd # Compression [root@centos7 / testdir] # lspasswd.Z [root@centos7 / testdir] # compress-d passwd # decompress gzip

The gzip compressed file has the suffix .gz, and if you compress the tar backup file, the extension is .tar.gz

Gzip, gunzip, zcat-compress or expand files

-d: decompress, equivalent to unzip-c: output the result of compression or decompression to the standard output-#: 1-9, specify the compression ratio zcat: view the contents of the text file without showing the decompression

Gunzip is used to decompress

Zcat is used to view

Use the example

[root@centos7 / testdir] # gzip passwd [root@centos7 / testdir] # lspasswd.gz passwd.Z [root@centos7 / testdir] # [root@centos7 / testdir] # zcat passwd.gz > passwd [root@centos7 / testdir] # lspasswd.gz passwd passwd.Z [root@centos7 / testdir] # bzip2

Bzip2 compressed files have a .bz2 extension

-k: keep, keep the original file-d: decompress-#: 1-9, compression ratio. Default is 6bzcat: view file contents without showing decompression.

Bunzip is used to decompress

Bzcat is used to view unzipped

Use the example

[root@centos7 / testdir] # bzip2 passwd [root@centos7 / testdir] # lspasswd.gz passwd.bz2 passwd.Z [root@centos7 / testdir] # bzcat passwd.bz2 > passwd [root@centos7 / testdir] # lspasswd.gz passwd passwd.bz2 passwd.Z [root@centos7 / testdir] # xz

The xz compressed file has a .xz extension

-k: keep, keep the original file-d: decompress-#: 1-9, compression ratio. Default is 6xzcat: view file contents without showing decompression.

Unxz is used to decompress

Xzcat is used to view

Use the example

[root@centos7 / testdir] # xz passwd [root@centos7 / testdir] # lspasswd.bz2 passwd.gz passwd.xz passwd.Z [root@centos7 / testdir] # [root@centos7 / testdir] # xzcat passwd.xz > passwd [root@centos7 / testdir] # lspasswd passwd.bz2 passwd.gz passwd.xz passwd.Z [root@centos7 / testdir] # zip

Package the compressed file, and after being compressed by zip, it will generate a separate .zip file without deleting the original file.

Zip-package and compress (archive) files

-r: recursive processing that processes all files in the specified directory with subdirectories-Q: does not show the execution process

Unzip is used to decompress

Zcat is used to view

Use the example

[root@centos7 / testdir] # zip-Q passwd. / passwd [root@centos7 / testdir] # lspasswd passwd.bz2 passwd.gz passwd.xz passwd.Z passwd.zip [root@centos7 / testdir] #

Take a look at the general compression:

[root@centos7 / testdir] # lltotal 192 RW Murray. 1 root root 164065 Aug 19 09:06 message.zip-rw-r--r--. 1 root root 4129 Aug 19 08:46 passwd-rw-r--r--. 1 root root 1526 Aug 19 08:30 passwd.bz2-rw-r--r--. 1 root root 1539 Aug 19 08:39 passwd.gz-rw-r--r--. 1 root root 1540 Aug 19 08:45 passwd.xz-rw-r--r--. 1 root root 2151 Aug 19 08:16 passwd.Z-rw-r--r--. 1 root root 1676 Aug 19 09:02 passwd.zip [root@centos7 / testdir] # zcat

The zcat command views the compressed file, but does not extract it.

[root@bash ~] # zcat b.zipcircle http://yolynn.blog.51cto.com/tar binbash # write your 51cto blog URL in url, save the exit, run the script, and modify the zipper blog as needed.

The tar command creates an archive (backup file) of a file or directory, and the tar command packages many files into a single file, which can be archived and compressed in combination with compression tools.

Use syntax:

Tar [OPTION...] [FILE]... EXAMPLES tar-cf archive.tar foo bar # Create archive.tar from files foo and bar. Tar-tvf archive.tar # List all files in archive.tar verbosely. Tar-xf archive.tar # Extract all files from archive.tar.

Common parameters:

-c:-- creat, create a new backup file-C dir: extract-f:-- file=ARCHIVE in a specific directory, specify the backup file-x:-- extract,-- get, restore the file-t:-- list from the backup file, and list the contents of the backup file-v:-- verbose

Summary of tar usage:

(1) create an archive

Tar-c-f/PATH/TO/SOMEFILE.tar FILE...tar cf/PATH/TO/SOMEFILE.tar FILE...

(2) View the list of files in the archive file

Tar-t-f / PATH/TO/SOMEFILE.tar (3) expand and archive tar-x-f / PATH/TO/SOMEFILE.tartar-x-f / PATH/TO/SOMEFILE.tar-C / PATH/

(4) implement with compression tool: archive and compress

-j: bzip2,-z: gzip,-J: xz

Package it into a tar package:

Tar-cvf passwd.tar passwd packaged only, uncompressed tar-zcvf passwd.tar.gz passwd packaged and gzip compressed tar-jcvf passwd.tar.bz2 passwd packaged and bzip2 compressed tar-Jcvf passwd.tar.xz passwd packaged and xz compressed

Use the example

[root@centos7 / testdir] # tar-cf passwd.tar passwd [root@centos7 / testdir] # lspasswd passwd.tar [root@centos7 / testdir] # tar-zcf passwd.tar.gz passwd [root@centos7 / testdir] # lspasswd passwd.tar passwd.tar.gz [root@centos7 / testdir] # tar-jcf passwd.tar.bz2 passwd [root@centos7 / testdir] # lspasswd passwd.tar passwd.tar.bz2 passwd.tar.gz [root@centos7 / testdir] # tar-Jcf passwd.tar.xz passwd [root@ Centos7 / testdir] # lspasswd passwd.tar passwd.tar.bz2 passwd.tar.gz passwd.tar.xz [root@centos7 / testdir] # [root@centos7 / testdir] # tar-tvf passwd.tar # query-rw-r--r-- root/root 10240 2016-08-19 09:27 passwd [root@centos7 / testdir] # tar-tvf passwd.tar.gz-rw-r--r-- root/root 10240 2016-08-19 09:27 passwd [root@centos7 / Testdir] # [root@centos7 / testdir] # tar xf passwd.tar # decompress [root@centos7 / testdir] # lspasswd passwd.tar passwd.tar.bz2 passwd.tar.gz passwd.tar.xz [root@centos7 / testdir] # tar xf passwd.tar.gz [root@centos7 / testdir] # lspasswd passwd.tar passwd.tar.bz2 passwd.tar.gz passwd.tar.xz [root@centos7 / testdir] # [root@centos7 / testdir] # lltotal Murray. 1 root root 10240 Aug 19 09:27 passwd-rw-r--r--. 1 root root 20480 Aug 19 10:52 passwd.tar-rw-r--r--. 1 root root 116 Aug 19 10:53 passwd.tar.bz2-rw-r--r--. 1 root root 120 Aug 19 10:52 passwd.tar.gz-rw-r--r--. 1 root root 180 Aug 19 10:53 passwd.tar.xzcpio

The cpio command is a tool that packages and restores files through redirection. it can extract files that end in .cpio or .tar; in other words, cpio can copy files into or from an archive package.

Use syntax:

Cpio-copy files to and from archivescpio [options] > file name or device name cpio [options]

< 文件名或者设备名EXAMPLES% ls | cpio -ov >

Directory.cpio # must execute ls in the current working directory, followed by an error of% find. -print-depth | cpio-ov > tree.cpio% cpio-iv

< directory.cpio% cpio -idv < tree.cpio% find . -depth -print0 | cpio --null -pvd new-dir 常用参数: -o: --create,Run in copy-out mode,将文件拷贝打包成文件或者将文件输出到设备上-i: --extract,Run in copy-in mode,解包,将打包文件解压或将设备上的备份还原到系统-t: 预览,查看文件内容或者输出到设备上的文件内容-v: 显示打包过程中的文件名称。-d: 解包生成目录,在cpio还原时,自动的建立目录-c: 一种较新的存储方式 使用示例 [root@centos7 /]#find ./etc |cpio -o >

Etc.cpio # backup / etc directory wKiom1e3MfKArn2SAABJ8zL76mY046.png [root@centos7 / testdir] # find / etc/issue | cpio-o > issue.cpio1 block [root@centos7 / testdir] # lsissue.cpio [root@centos7 / testdir] # cpio-tv

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report