MCPInstall

tar-compression

归档与压缩

Installs
85
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/chaterm/terminal-skills --skill tar-compression
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads tar-compression automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

归档与压缩

概述

tar/gzip/xz 归档压缩、分卷备份技能。

tar 基础

创建归档

# 创建 tar 归档
tar -cvf archive.tar /path/to/dir

# 创建并 gzip 压缩
tar -czvf archive.tar.gz /path/to/dir

# 创建并 bzip2 压缩
tar -cjvf archive.tar.bz2 /path/to/dir

# 创建并 xz 压缩
tar -cJvf archive.tar.xz /path/to/dir

# 多个目录/文件
tar -czvf archive.tar.gz dir1 dir2 file1.txt

解压归档

# 解压 tar
tar -xvf archive.tar

# 解压 gzip
tar -xzvf archive.tar.gz

# 解压 bzip2
tar -xjvf archive.tar.bz2

# 解压 xz
tar -xJvf archive.tar.xz

# 解压到指定目录
tar -xzvf archive.tar.gz -C /target/dir

查看内容

# 列出内容
tar -tvf archive.tar
tar -tzvf archive.tar.gz

# 搜索文件
tar -tzvf archive.tar.gz | grep "filename"

常用选项

# 排除文件/目录
tar -czvf archive.tar.gz --exclude='*.log' --exclude='cache' /path

# 从文件读取排除列表
tar -czvf archive.tar.gz --exclude-from=exclude.txt /path

# 保留权限
tar -czvf archive.tar.gz --preserve-permissions /path

# 增量备份
tar -czvf archive.tar.gz --newer='2024-01-01' /path

压缩工具

gzip

# 压缩
gzip file.txt              # 生成 file.txt.gz,删除原文件
gzip -k file.txt           # 保留原文件
gzip -9 file.txt           # 最高压缩率

# 解压
gunzip file.txt.gz
gzip -d file.txt.gz

# 查看压缩文件
zcat file.txt.gz
zless file.txt.gz
zgrep "pattern" file.txt.gz

bzip2

# 压缩
bzip2 file.txt
bzip2 -k file.txt          # 保留原文件
bzip2 -9 file.txt          # 最高压缩率

# 解压
bunzip2 file.txt.bz2
bzip2 -d file.txt.bz2

# 查看
bzcat file.txt.bz2

xz

# 压缩
xz file.txt
xz -k file.txt             # 保留原文件
xz -9 file.txt             # 最高压缩率
xz -T 4 file.txt           # 多线程

# 解压
unxz file.txt.xz
xz -d file.txt.xz

# 查看
xzcat file.txt.xz

zstd

# 压缩
zstd file.txt
zstd -19 file.txt          # 最高压缩率
zstd -T0 file.txt          # 自动多线程

# 解压
unzstd file.txt.zst
zstd -d file.txt.zst

分卷备份

split 分割

# 按大小分割
split -b 100M archive.tar.gz archive.tar.gz.part_

# 按行分割
split -l 10000 largefile.txt part_

# 合并
cat archive.tar.gz.part_* > archive.tar.gz

tar 分卷

# 创建分卷
tar -czvf - /path/to/dir | split -b 100M - backup.tar.gz.part_

# 解压分卷
cat backup.tar.gz.part_* | tar -xzvf -

常见场景

场景 1:网站备份

#!/bin/bash
DATE=$(date +%Y%m%d)
BACKUP_DIR="/backup"
WEB_DIR="/var/www/html"

# 创建备份
tar -czvf ${BACKUP_DIR}/web_${DATE}.tar.gz \
    --exclude='*.log' \
    --exclude='cache/*' \
    ${WEB_DIR}

# 保留最近 7 天
find ${BACKUP_DIR} -name "web_*.tar.gz" -mtime +7 -delete

场景 2:数据库备份压缩

# MySQL
mysqldump -u root -p database | gzip > db_backup.sql.gz

# 解压恢复
gunzip < db_backup.sql.gz | mysql -u root -p database

# PostgreSQL
pg_dump database | xz > db_backup.sql.xz

场景 3:增量备份

#!/bin/bash
SNAPSHOT="/backup/snapshot.snar"
BACKUP_DIR="/backup"
SOURCE="/data"

# 完整备份(首次)
tar -czvf ${BACKUP_DIR}/full.tar.gz -g ${SNAPSHOT} ${SOURCE}

# 增量备份
tar -czvf ${BACKUP_DIR}/incr_$(date +%Y%m%d).tar.gz -g ${SNAPSHOT} ${SOURCE}

场景 4:远程备份

# 本地压缩后传输
tar -czvf - /path/to/dir | ssh user@remote "cat > /backup/archive.tar.gz"

# 远程压缩
ssh user@remote "tar -czvf - /path/to/dir" > local_backup.tar.gz

压缩对比

格式压缩率速度内存适用场景
gzip中快低日常备份
bzip2高慢中归档存储
xz最高最慢高长期存储
zstd高快中现代备份

故障排查

问题排查方法
解压失败检查文件完整性、格式
空间不足使用管道、分卷
权限丢失使用 --preserve-permissions
文件损坏使用 gzip -t 测试
# 测试压缩文件
gzip -t file.gz
bzip2 -t file.bz2
xz -t file.xz

# 修复损坏的 gzip
gzrecover file.gz

# 查看压缩信息
gzip -l file.gz

FAQ

What does the tar-compression skill do?

归档与压缩

How do I install tar-compression?

Run npx skills add https://github.com/chaterm/terminal-skills --skill tar-compression in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/tar-compression/ (personal) or .claude/skills/tar-compression/ (project).

Which AI agents can use tar-compression?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is tar-compression safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains tar-compression?

It is published by chaterm in chaterm/terminal-skills. It has 85 recorded installs.

More from chaterm/terminal-skills

View all →

cron

chaterm/terminal-skills

定时任务管理

1.3K installs

system-admin

chaterm/terminal-skills

Linux system administration and monitoring

DevOps & Cloud561 installs

systemd

chaterm/terminal-skills

Systemd 服务管理

254 installs

network-tools

chaterm/terminal-skills

Linux network tools and diagnostics

DevOps & Cloud218 installs

vpn

chaterm/terminal-skills

VPN 配置与管理

193 installs

ssh

chaterm/terminal-skills

SSH 管理与安全

147 installs

Popular other skills

View category →

hyperframes-cli

heygen-com/hyperframes

The HyperFrames CLI by job - scaffold, check, look at frames, edit the timeline, preview, render locally or in the cloud, publish, project history - plus reading its JSON and recovering from build or render failures.

1.3M installs

triage

mattpocock/skills

Move issues and external PRs through a state machine of triage roles, categorise, verify, grill if needed, and write agent-ready briefs.

1M installs

ask-matt

mattpocock/skills

Ask which skill or flow fits your situation. A router over the skills in this repo.

778.4K installs

to-questionnaire

mattpocock/skills

Turn a decision you can't fully answer into a questionnaire for someone else to fill in.

508.9K installs

wait-what

mattpocock/skills

Stop. That last message did not land: re-pitch it.

459.7K installs

loop-me

mattpocock/skills

Grill me about specs for the workflows I want to build, within this workspace.

447.9K installs