归档与压缩CLI Manual
$tar
创建、查看和解压 .tar 及 .tar.gz 压缩归档文件。
命令语法POSIX Standard
tar [OPTIONS] [ARCHIVE-FILE] [FILE...]在交互式终端沙盒中实时运行
无需安装的客户端实时仿真环境。
bash — terminal
AST Sandbox (Free)
概述与工作原理
tar 是 Linux 下最常用的归档打包与解压工具,支持 gzip、bzip2 等多种压缩算法。
常用参数与选项说明
| Flag / Option | Description |
|---|---|
| -c, --create | Create a new tar archive. |
| -x, --extract | Extract files from an existing archive. |
| -z, --gzip | Compress or decompress archive using gzip algorithm. |
| -v, --verbose | Verbosely list files processed. |
| -f, --file [ARCHIVE] | Use archive file specified. |
| -t, --list | List the contents of an archive without extracting it. |
实际生产案例与代码范例
#1Compress a folder into a .tar.gz archive
tar -czvf backup.tar.gz /home/user/projectsCreates a compressed archive named backup.tar.gz containing all files in projects.
#2Extract a .tar.gz archive
tar -xzvf backup.tar.gz -C /tmpExtracts all contents of backup.tar.gz into the /tmp directory.