Online Linux Terminal Logo
OnlineLinuxTerminal
归档与压缩CLI Manual

$tar

创建、查看和解压 .tar 及 .tar.gz 压缩归档文件。

命令语法POSIX Standard
tar [OPTIONS] [ARCHIVE-FILE] [FILE...]
Linux 社区2.4k 在线

与真实 Linux 用户交流,学习常用命令并免费获取精美速查表 PDF。

在交互式终端沙盒中实时运行

无需安装的客户端实时仿真环境。

在全屏终端工作区中打开 ↗
bash — terminal

概述与工作原理

tar 是 Linux 下最常用的归档打包与解压工具,支持 gzip、bzip2 等多种压缩算法。

常用参数与选项说明

Flag / OptionDescription
-c, --createCreate a new tar archive.
-x, --extractExtract files from an existing archive.
-z, --gzipCompress or decompress archive using gzip algorithm.
-v, --verboseVerbosely list files processed.
-f, --file [ARCHIVE]Use archive file specified.
-t, --listList the contents of an archive without extracting it.

实际生产案例与代码范例

#1Compress a folder into a .tar.gz archive
tar -czvf backup.tar.gz /home/user/projects

Creates a compressed archive named backup.tar.gz containing all files in projects.

#2Extract a .tar.gz archive
tar -xzvf backup.tar.gz -C /tmp

Extracts all contents of backup.tar.gz into the /tmp directory.