← 返回命令列表

Linux command

compress 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Compress

compress path/to/file1 path/to/file2

Example

compress -f path/to/file

Example

compress -b 12 path/to/file

Example

compress -c path/to/file

Decompress

compress -d path/to/file.Z

Example

compress -v path/to/file

Keep

compress -k path/to/file

说明

compress is the classic Unix compression utility that implements the LZW (Lempel-Ziv-Welch) algorithm, producing files with the distinctive .Z extension. It was the standard compression tool on Unix systems before being largely superseded by gzip in the early 1990s. The algorithm uses adaptive dictionary-based compression, starting with 9-bit codes and expanding up to 16 bits as needed. When compressing files, compress preserves important file metadata including ownership, permissions (modes), and timestamps. It operates safely by default, refusing to compress symbolic links and files with multiple hard links unless the -f force flag is used. Compressed files replace the originals unless the -c stdout option or -k keep option is specified. The compression ratio varies by file type, with text files typically achieving 50-60% size reduction. Binary files may compress less effectively. While compress is considered obsolete for most purposes today, it remains available for compatibility with legacy .Z archives and systems that still use this format. Modern alternatives like gzip and bzip2 provide better compression ratios and are more widely supported.

参数

-f
Force compression, overwriting existing files and compressing files with hard links
-k
Keep (do not delete) input files
-v
Verbose mode; display compression percentage for each file
-c
Write output to stdout without modifying any files
-V
Print version and patchlevel information
-r
Operate recursively through directories
-b BITS
Set maximum bits per code (9-16, default 16)
--
Stop parsing options; treat remaining arguments as filenames

FAQ

What is the compress command used for?

compress is the classic Unix compression utility that implements the LZW (Lempel-Ziv-Welch) algorithm, producing files with the distinctive .Z extension. It was the standard compression tool on Unix systems before being largely superseded by gzip in the early 1990s. The algorithm uses adaptive dictionary-based compression, starting with 9-bit codes and expanding up to 16 bits as needed. When compressing files, compress preserves important file metadata including ownership, permissions (modes), and timestamps. It operates safely by default, refusing to compress symbolic links and files with multiple hard links unless the -f force flag is used. Compressed files replace the originals unless the -c stdout option or -k keep option is specified. The compression ratio varies by file type, with text files typically achieving 50-60% size reduction. Binary files may compress less effectively. While compress is considered obsolete for most purposes today, it remains available for compatibility with legacy .Z archives and systems that still use this format. Modern alternatives like gzip and bzip2 provide better compression ratios and are more widely supported.

How do I run a basic compress example?

Run `compress path/to/file1 path/to/file2` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -f do in compress?

Force compression, overwriting existing files and compressing files with hard links