linux操作系统下的compress命令介绍和使用案例

韵味老鸟 2024-09-13 16:29:04
linux 操作系统下的compress命令介绍和使用案例

compress命令是Linux系统中用于文件压缩的一个工具,主要使用Lempel-Ziv-Welch (LZW)算法进行数据压缩。压缩后,文件的扩展名将变为“.Z”。虽然compress命令在历史上有其重要性,但在现代Linux系统中,它已经被更高效的压缩工具如gzip和bzip2所取代

使用方法基本语法bash compress [选项] [文件名]

安装部署:

root@meng:~# which compress

root@meng:~# compress

Command 'compress' not found, but can be installed with:

apt install ncompress

root@meng:~# apt install ncompress

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

The following NEW packages will be installed:

ncompress

0 upgraded, 1 newly installed, 0 to remove and 224 not upgraded.

Need to get 22.0 kB of archives.

After this operation, 58.4 kB of additional disk space will be used.

Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 ncompress amd64 4.2.4.6-5 [22.0 kB]

Fetched 22.0 kB in 1s (23.0 kB/s)

Selecting previously unselected package ncompress.

(Reading database ... 75125 files and directories currently installed.)

Preparing to unpack .../ncompress_4.2.4.6-5_amd64.deb ...

Unpacking ncompress (4.2.4.6-5) ...

Setting up ncompress (4.2.4.6-5) ...

Processing triggers for man-db (2.10.2-1) ...

Scanning processes...

Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

root@meng:~# compress --help

Unknown flag: '-'; Usage: compress [-dfhvcVr] [-b maxbits] [--] [file ...]

-d If given, decompression is done instead.

-c Write output on stdout, don't remove original.

-b Parameter limits the max number of bits/code.

-f Forces output file to be generated, even if one already.

exists, and even if no space is saved by compressing.

If -f is not used, the user will be prompted if stdin is.

a tty, otherwise, the output file will not be overwritten.

-h This help output.

-v Write compression statistics.

-V Output version and compile options.

-r Recursive. If a filename is a directory, descend

into it and compress everything in it.

命令案例:

root@meng:~# more m1.txt

hello men

g

hello meng

g

Hello World

This is a test

HelloWorld

Hello World

This is a test

root@meng:~# compress -v m1.txt

m1.txt: -- replaced with m1.txt.Z Compression: 21.10%

root@meng:~# ls

f1.txt.bz2 f2.txt.bz2 m1.txt.Z m2.txt meng.txt meng.txt.bz2 rec00001f1.txt s1.txt s2.txt snap tmp

root@meng:~# uncompress -v m1.txt.Z

m1.txt.Z: 21.1% -- replaced with m1.txt

root@meng:~# ls

f1.txt.bz2 f2.txt.bz2 m1.txt m2.txt meng.txt meng.txt.bz2 rec00001f1.txt s1.txt s2.txt snap tmp

root@meng:~#

0 阅读:5

韵味老鸟

简介:感谢大家的关注