关于 hf-cli
用于通过 Hugging Face Hub 命令行工具 `hf` 管理 Hub 内容和账户访问的技能。它取代已弃用的 `huggingface-cli`,并涵盖仓库、数据集、存储桶等操作。
主要功能
- 01上传和下载 Hub 文件
- 02管理身份验证令牌
- 03同步本地文件与存储桶
- 04检查和维护本地缓存
- 05管理数据集与讨论
适用场景
- 01将 Hub 仓库下载到本地目录
- 02向模型或数据集仓库上传文件
- 03将本地数据与存储桶同步
- 04切换 Hugging Face 账户令牌
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ huggingface/ skills --skill hf-cli安装后在 Claude Code 中输入/hf-cli确认已加载。
详细介绍
安装:curl -LsSf https://hf.co/cli/install.sh | bash -s。
Hugging Face Hub CLI 工具 hf 已可用。重要提示:hf 命令取代了已弃用的 huggingface-cli 命令。
使用 hf --help 查看可用功能。请注意,所有身份验证命令现在都位于 hf auth 下,例如 hf auth whoami。
使用 huggingface_hub v2.2.0 生成。运行 hf skills add --force 以重新生成。
命令
hf cp SRC— 在本地路径、仓库和存储桶之间复制文件。[--format [auto|human|agent|json|quiet]]hf download REPO_ID— 从 Hub 下载文件。[--type [model|dataset|space|kernel] --revision TEXT --include TEXT --exclude TEXT --cache-dir TEXT --local-dir TEXT --force-download --dry-run --max-workers INTEGER --format [auto|human|agent|json|quiet]]hf env— 输出环境信息。[--format [auto|human|agent|json|quiet]]hf sync— 在本地目录与存储桶之间同步文件。[--delete --ignore-times --ignore-sizes --plan TEXT --apply TEXT --dry-run --include TEXT --exclude TEXT --filter-from TEXT --existing --ignore-existing --verbose --format [auto|human|agent|json|quiet]]hf update— 将hfCLI 更新到最新版本。[--format [auto|human|agent|json|quiet]]hf upload REPO_ID— 将文件或文件夹上传到 Hub。[--type [model|dataset|space|kernel] --revision TEXT --private --include TEXT --exclude TEXT --delete TEXT --commit-message TEXT --commit-description TEXT --create-pr --every FLOAT --format [auto|human|agent|json|quiet]]hf version— 输出 hf 版本信息。[--format [auto|human|agent|json|quiet]]
hf auth — 管理身份验证(登录、登出等)。
hf auth list— 列出所有已存储的访问令牌。[--format [auto|human|agent|json|quiet]]hf auth login— 通过浏览器登录,或使用来自 huggingface.co/settings/tokens 的令牌登录。[--add-to-git-credential --force --format [auto|human|agent|json|quiet]]hf auth logout— 登出指定令牌。[--token-name TEXT --format [auto|human|agent|json|quiet]]hf auth switch— 在访问令牌之间切换。[--token-name TEXT --add-to-git-credential --format [auto|human|agent|json|quiet]]hf auth token— 将当前访问令牌输出到标准输出。[--format [auto|human|agent|json|quiet]]hf auth whoami— 查看当前登录的 huggingface.co 账户。[--format [auto|human|agent|json|quiet]]
hf buckets — 与存储桶交互的命令。
hf buckets cp SRC— 在本地路径、仓库和存储桶之间复制文件。[--format [auto|human|agent|json|quiet]]hf buckets create BUCKET_ID— 创建新的存储桶。[--private --region [us|eu] --exist-ok --format [auto|human|agent|json|quiet]]hf buckets delete BUCKET_ID— 删除存储桶。[--yes --missing-ok --format [auto|human|agent|json|quiet]]hf buckets info BUCKET_ID— 获取存储桶信息。[--format [auto|human|agent|json|quiet]]hf buckets list— 列出存储桶或存储桶中的文件。[--human-readable --tree --recursive --search TEXT --format [auto|human|agent|json|quiet]]hf buckets move FROM_ID TO_ID— 将存储桶移动(重命名)到新的名称或命名空间。[--format [auto|human|agent|json|quiet]]hf buckets remove ARGUMENT— 从存储桶中移除文件。[--recursive --yes --dry-run --include TEXT --exclude TEXT --format [auto|human|agent|json|quiet]]hf buckets settings BUCKET_ID— 更新存储桶设置(可见性)。[--private --public --format [auto|human|agent|json|quiet]]hf buckets sync— 在本地目录与存储桶之间同步文件。[--delete --ignore-times --ignore-sizes --plan TEXT --apply TEXT --dry-run --include TEXT --exclude TEXT --filter-from TEXT --existing --ignore-existing --verbose --format [auto|human|agent|json|quiet]]
hf cache — 管理本地缓存目录。
hf cache list— 列出缓存的仓库或修订版本。[--cache-dir TEXT --revisions --filter TEXT --sort [accessed|accessed:asc|accessed:desc|modified|modified:asc|modified:desc|name|name:asc|name:desc|size|size:asc|size:desc] --limit INTEGER --show-warnings --format [auto|human|agent|json|quiet]]hf cache prune— 从缓存中移除已脱离的修订版本和未完成的下载。[--cache-dir TEXT --yes --dry-run --format [auto|human|agent|json|quiet]]hf cache rm TARGETS— 移除缓存的仓库、修订版本或文件。[--cache-dir TEXT --yes --dry-run --format [auto|human|agent|json|quiet]]hf cache verify REPO_ID— 验证缓存或本地目录中单个仓库修订版本的校验和。[--type [model|dataset|space|kernel] --revision TEXT --cache-dir TEXT --local-dir TEXT --fail-on-missing-files --fail-on-extra-files --format [auto|human|agent|json|quiet]]
hf collections — 与 Hub 上的集合交互。
hf collections add-item COLLECTION_SLUG ITEM_ID ITEM_TYPE— 向集合添加条目。[--note TEXT --exists-ok --format [auto|human|agent|json|quiet]]hf collections create TITLE— 在 Hub 上创建新集合。[--namespace TEXT --description TEXT --private --exists-ok --format [auto|human|agent|json|quiet]]hf collections delete COLLECTION_SLUG— 从 Hub 删除集合。[--missing-ok --format [auto|human|agent|json|quiet]]hf collections delete-item COLLECTION_SLUG ITEM_OBJECT_ID— 从集合中删除条目。[--missing-ok --format [auto|human|agent|json|quiet]]hf collections info COLLECTION_SLUG— 获取 Hub 上集合的信息。[--format [auto|human|agent|json|quiet]]hf collections list— 列出 Hub 上的集合。[--owner TEXT --item TEXT --sort [lastModified|trending|upvotes] --limit INTEGER --format [auto|human|agent|json|quiet]]hf collections update COLLECTION_SLUG— 更新 Hub 上集合的元数据。[--title TEXT --description TEXT --position INTEGER --private --theme TEXT --format [auto|human|agent|json|quiet]]hf collections update-item COLLECTION_SLUG ITEM_OBJECT_ID— 更新集合中的条目。[--note TEXT --position INTEGER --format [auto|human|agent|json|quiet]]
hf datasets — 与 Hub 上的数据集交互。
hf datasets card DATASET_ID— 获取 Hub 上数据集的数据集卡片(README)。[--metadata --text --format [auto|human|agent|json|quiet]]hf datasets info DATASET_ID— 获取 Hub 上数据集的信息。[--revision TEXT --expand TEXT --format [auto|human|agent|json|quiet]]hf datasets leaderboard DATASET_ID— 列出数据集排行榜中的模型分数。此命令有助于查找适用于某项任务的最佳模型,或根据基准测试分数比较模型。使用 'hf datasets ls --filter benchmark:official' 列出可用的排行榜。[--limit INTEGER --format [auto|human|agent|json|quiet]]hf datasets list— 列出 Hub 上的数据集,或列出数据集仓库中的文件。[--search TEXT --author TEXT --filter TEXT --sort [created_at|downloads|last_modified|likes|trending_score] --limit INTEGER --expand TEXT --human-readable --tree --recursive --revision TEXT --format [auto|human|agent|json|quiet]]hf datasets parquet DATASET_ID— 列出数据集可用的 parquet 文件 URL。[--subset TEXT --split TEXT --format [auto|human|agent|json|quiet]]hf datasets sql SQL— 使用 DuckDB 对数据集 parquet URL 执行原始 SQL 查询。[--format [auto|human|agent|json|quiet]]
hf discussions — 管理 Hub 上的讨论和拉取请求。
hf discussions close REPO_ID NUM— 关闭讨论或拉取请求。[--comment TEXT --yes --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions comment REPO_ID NUM— 对讨论或拉取请求发表评论。[--body TEXT --body-file PATH --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions create REPO_ID --title TEXT— 在仓库中创建新讨论或拉取请求。[--body TEXT --body-file PATH --pull-request --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions diff REPO_ID NUM— 显示拉取请求的差异。[--type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions edit REPO_ID NUM COMMENT_ID— 编辑讨论或拉取请求中的现有评论。[--body TEXT --body-file PATH --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions info REPO_ID NUM— 获取讨论或拉取请求的信息。[--type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions list REPO_ID— 列出仓库中的讨论和拉取请求。[--status [open|closed|merged|draft|all] --kind [all|discussion|pull_request] --author TEXT --limit INTEGER --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions merge REPO_ID NUM— 合并拉取请求。[--comment TEXT --yes --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions rename REPO_ID NUM NEW_TITLE— 重命名讨论或拉取请求。[--type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf discussions reopen REPO_ID NUM— 重新打开已关闭的讨论或拉取请求。[--comment TEXT --yes --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]
hf endpoints — 管理 Hugging Face 推理端点。
hf endpoints catalog deploy— 从模型目录部署推理端点。[--repo TEXT --recipe TEXT --name TEXT --accelerator [cpu|gpu|neuron] --gguf-file TEXT --namespace TEXT --format [auto|human|agent|json|quiet]]hf endpoints catalog list— 列出模型目录中可用的模型。[--accelerator [cpu|gpu|neuron] --engine [llamacpp|sglang|tei|vllm] --license TEXT --task TEXT --search TEXT --limit INTEGER --format [auto|human|agent|json|quiet]]hf endpoints delete NAME— 永久删除推理端点。[--namespace TEXT --yes --format [auto|human|agent|json|quiet]]hf endpoints deploy NAME --repo TEXT --framework TEXT --accelerator TEXT --instance-size TEXT --instance-type TEXT --region TEXT --vendor TEXT— 从 Hub 仓库部署推理端点。[--namespace TEXT --task TEXT --min-replica INTEGER --max-replica INTEGER --scale-to-zero-timeout INTEGER --scaling-metric [pendingRequests|hardwareUsage] --scaling-threshold FLOAT --revision TEXT --custom-image TEXT --engine [custom|hf-serve|llamacpp|sglang|tei|tgi|tgi-neuron|vllm|vllm-neuron] --health-route TEXT --port INTEGER --container-registry-username TEXT --container-registry-password TEXT --tensor-parallel-size INTEGER --data-parallel-size INTEGER --container-command TEXT --container-args TEXT --env TEXT --env-file TEXT --secrets TEXT --secrets-file TEXT --type [public|authenticated|private] --format [auto|human|agent|json|quiet]]hf endpoints describe NAME— 获取现有端点的信息。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf endpoints hardware— 列出可用于部署推理端点的硬件。[--namespace TEXT --vendor TEXT --region TEXT --accelerator TEXT --instance-type TEXT --all --format [auto|human|agent|json|quiet]]hf endpoints list— 列出指定命名空间的所有推理端点。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf endpoints pause NAME— 暂停推理端点。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf endpoints resume NAME— 恢复推理端点。[--namespace TEXT --fail-if-already-running --format [auto|human|agent|json|quiet]]hf endpoints scale-to-zero NAME— 将推理端点缩容至零。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf endpoints update NAME— 更新现有端点。[--namespace TEXT --repo TEXT --accelerator TEXT --instance-size TEXT --instance-type TEXT --framework TEXT --revision TEXT --task TEXT --custom-image TEXT --engine [custom|hf-serve|llamacpp|sglang|tei|tgi|tgi-neuron|vllm|vllm-neuron] --health-route TEXT --port INTEGER --tensor-parallel-size INTEGER --data-parallel-size INTEGER --container-command TEXT --container-args TEXT --min-replica INTEGER --max-replica INTEGER --scale-to-zero-timeout INTEGER --scaling-metric [pendingRequests|hardwareUsage] --scaling-threshold FLOAT --format [auto|human|agent|json|quiet]]
hf extensions — 管理 hf CLI 扩展。
hf extensions exec NAME— 执行已安装的扩展。hf extensions install REPO_ID— 从公开的 GitHub 仓库安装扩展。[--force --format [auto|human|agent|json|quiet]]hf extensions list— 列出已安装的扩展命令。[--format [auto|human|agent|json|quiet]]hf extensions remove NAME— 移除已安装的扩展。[--format [auto|human|agent|json|quiet]]hf extensions search— 搜索 GitHub 上可用的扩展(带有 'hf-extension' 主题标签)。[--format [auto|human|agent|json|quiet]]hf extensions update— 将已安装的扩展更新至最新版本。[--format [auto|human|agent|json|quiet]]
hf jobs — 在 Hub 上运行和管理作业。
hf jobs cancel JOB_ID— 取消 Job[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs expose JOB_ID— 替换运行中 Job 的公开端口。[--public INTEGER --clear --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs hardware— 列出 Job 可用的硬件选项[--format [auto|human|agent|json|quiet]]hf jobs inspect JOB_IDS— 显示一个或多个 Job 的详细信息[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs labels JOB_ID— 更新 Job 的标签。传入 --label 会替换所有现有标签;仅传入 --name 则保留现有标签。[--name TEXT --label TEXT --clear --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs list— 列出 Job。[--all --status [COMPLETED|CANCELED|ERROR|DELETED|SCHEDULING|RUNNING] --label TEXT --name TEXT --limit INTEGER --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs logs JOB_ID— 获取 Job 的日志。[--follow --tail INTEGER --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs rerun JOB_ID— 使用现有 Job 的配置运行新的 Job。[--detach --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs run IMAGE COMMAND— 运行 Job。[--env TEXT --secrets TEXT --name TEXT --label TEXT --volume TEXT --env-file TEXT --secrets-file TEXT --flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|rtx-pro-6000|rtx-pro-6000x2|rtx-pro-6000x4|rtx-pro-6000x8] --timeout TEXT --attempts INTEGER RANGE --detach --dry-run --expose INTEGER --expose-public INTEGER --ssh --network-group TEXT --network-alias TEXT --resource-group-id TEXT --namespace TEXT --format [agent|auto|human|json|quiet] --json --quiet]hf jobs scheduled delete SCHEDULED_JOB_ID— 删除计划 Job。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled inspect SCHEDULED_JOB_IDS— 显示一个或多个计划 Job 的详细信息[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled labels SCHEDULED_JOB_ID— 更新计划 Job 的标签。传入 --label 会替换所有现有标签;仅传入 --name 则保留现有标签。[--name TEXT --label TEXT --clear --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled list— 列出计划 Job。[--all --status [active|suspended] --label TEXT --name TEXT --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled reschedule SCHEDULED_JOB_ID SCHEDULE— 更改计划 Job 的运行时间。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled resume SCHEDULED_JOB_ID— 恢复(取消暂停)计划 Job。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled run SCHEDULE IMAGE COMMAND— 计划运行 Job。[--suspend --concurrency --env TEXT --secrets TEXT --name TEXT --label TEXT --volume TEXT --env-file TEXT --secrets-file TEXT --flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|rtx-pro-6000|rtx-pro-6000x2|rtx-pro-6000x4|rtx-pro-6000x8] --timeout TEXT --attempts INTEGER RANGE --dry-run --expose INTEGER --expose-public INTEGER --resource-group-id TEXT --namespace TEXT --format [agent|auto|human|json|quiet] --json --quiet]hf jobs scheduled suspend SCHEDULED_JOB_ID— 暂停计划 Job。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled trigger SCHEDULED_JOB_ID— 立即触发计划 Job 运行(不会更改计划)。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs scheduled uv run SCHEDULE SCRIPT— 在 HF 基础设施上运行 UV 脚本(本地文件或 URL)[--suspend --concurrency --image TEXT --flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|rtx-pro-6000|rtx-pro-6000x2|rtx-pro-6000x4|rtx-pro-6000x8] --env TEXT --secrets TEXT --name TEXT --label TEXT --volume TEXT --env-file TEXT --secrets-file TEXT --timeout TEXT --attempts INTEGER RANGE --dry-run --expose INTEGER --expose-public INTEGER --resource-group-id TEXT --namespace TEXT --with TEXT --python TEXT --format [agent|auto|human|json|quiet] --json --quiet]hf jobs ssh JOB_ID— 通过 SSH 连接到运行中的 Job。[--identity-file PATH --dry-run --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs stats— 获取 Job 的资源使用统计数据和指标。[--follow --namespace TEXT --format [auto|human|agent|json|quiet]]hf jobs uv run SCRIPT— 在 HF 基础设施上运行 UV 脚本(本地文件或 URL)[--image TEXT --flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|rtx-pro-6000|rtx-pro-6000x2|rtx-pro-6000x4|rtx-pro-6000x8] --env TEXT --secrets TEXT --name TEXT --label TEXT --volume TEXT --env-file TEXT --secrets-file TEXT --timeout TEXT --attempts INTEGER RANGE --detach --dry-run --expose INTEGER --expose-public INTEGER --ssh --network-group TEXT --network-alias TEXT --resource-group-id TEXT --namespace TEXT --with TEXT --python TEXT --format [agent|auto|human|json|quiet] --json --quiet]hf jobs wait JOB_IDS— 等待一个或多个 Job 达到终止状态。[--timeout TEXT --namespace TEXT --format [auto|human|agent|json|quiet]]
hf models — 与 Hub 上的模型交互。
hf models card MODEL_ID— 获取 Hub 上模型的模型卡(README)。[--metadata --text --format [auto|human|agent|json|quiet]]hf models info MODEL_ID— 获取 Hub 上模型的信息。[--revision TEXT --expand TEXT --format [auto|human|agent|json|quiet]]hf models list— 列出 Hub 上的模型,或模型仓库中的文件。[--search TEXT --author TEXT --filter TEXT --pipeline-tag TEXT --gated --apps TEXT --num-parameters TEXT --inference-provider [baseten|cerebras|cohere|deepinfra|fal-ai|featherless-ai|fireworks-ai|groq|hf-inference|novita|nscale|openai|ovhcloud|publicai|replicate|scaleway|together|wavespeed|zai-org] --warm --sort [created_at|downloads|last_modified|likes|trending_score] --limit INTEGER --expand TEXT --human-readable --tree --recursive --revision TEXT --format [auto|human|agent|json|quiet]]
hf papers — 与 Hub 上的论文交互。
hf papers info PAPER_ID— 获取 Hub 上论文的信息。[--format [auto|human|agent|json|quiet]]hf papers list— 列出 Hub 上的每日论文。[--date TEXT --week TEXT --month TEXT --submitter TEXT --sort [publishedAt|trending] --limit INTEGER --format [auto|human|agent|json|quiet]]hf papers read PAPER_ID— 以 Markdown 格式阅读论文。[--format [auto|human|agent|json|quiet]]hf papers search QUERY— 搜索 Hub 上的论文。[--limit INTEGER --format [auto|human|agent|json|quiet]]
hf repos — 管理 Hub 上的仓库。
hf repos branch create REPO_ID BRANCH— 在 Hub 上为仓库创建新分支。[--revision TEXT --type [model|dataset|space|kernel] --exist-ok --format [auto|human|agent|json|quiet]]hf repos branch delete REPO_ID BRANCH— 从 Hub 上的仓库删除分支。[--type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf repos cp SRC— 在本地路径、仓库和存储桶之间复制文件。[--format [auto|human|agent|json|quiet]]hf repos create REPO_ID— 在 Hub 上创建新仓库。[--type [model|dataset|space|kernel] --sdk TEXT --template TEXT --private --public --protected --exist-ok --resource-group-id TEXT --region [us|eu] --flavor [cpu-basic|cpu-upgrade|zero-a10g|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8] --sleep-time INTEGER --secrets TEXT --secrets-file TEXT --env TEXT --env-file TEXT --volume TEXT --format [auto|human|agent|json|quiet]]hf repos delete REPO_ID— 从 Hub 删除仓库。此操作无法撤销。[--type [model|dataset|space|kernel] --missing-ok --yes --format [auto|human|agent|json|quiet]]hf repos delete-files REPO_ID PATTERNS— 从 Hub 上的仓库删除文件。[--type [model|dataset|space|kernel] --revision TEXT --commit-message TEXT --commit-description TEXT --create-pr --format [auto|human|agent|json|quiet]]hf repos duplicate FROM_ID— 复制 Hub 上的仓库(模型、数据集或 Space)。[--type [model|dataset|space|kernel] --private --public --protected --exist-ok --resource-group-id TEXT --flavor [cpu-basic|cpu-upgrade|zero-a10g|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8] --sleep-time INTEGER --secrets TEXT --secrets-file TEXT --env TEXT --env-file TEXT --volume TEXT --format [auto|human|agent|json|quiet]]hf repos list— 列出所有仓库(模型、数据集、空间、存储桶)及存储信息。[--namespace TEXT --type [model|dataset|space|bucket] --search TEXT --limit INTEGER --explore --format [auto|human|agent|json|quiet]]hf repos move FROM_ID TO_ID— 将仓库从一个命名空间移至另一个命名空间。[--type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf repos settings REPO_ID— 更新仓库设置。[--gated [auto|manual|false] --private --public --protected --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf repos tag create REPO_ID TAG— 为仓库创建标签。[--message TEXT --revision TEXT --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf repos tag delete REPO_ID TAG— 删除仓库标签。[--yes --type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]hf repos tag list REPO_ID— 列出仓库的标签。[--type [model|dataset|space|kernel] --format [auto|human|agent|json|quiet]]
hf sandbox — 在 Hugging Face Jobs 上运行和管理实验性沙箱。
hf sandbox cp SRC DST— 在本地计算机和沙箱之间复制文件(类似 Docker)。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf sandbox create— 创建沙箱:默认使用专用 VM,也可通过--pool使用低成本共享 VM。[--pool TEXT --flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|rtx-pro-6000|rtx-pro-6000x2|rtx-pro-6000x4|rtx-pro-6000x8] --idle-timeout TEXT --env TEXT --secrets TEXT --label TEXT --env-file TEXT --secrets-file TEXT --volume TEXT --namespace TEXT --forward-hf-token --format [auto|human|agent|json|quiet]]hf sandbox exec SANDBOX_ID COMMAND— 在沙箱中运行命令并流式输出结果。退出码与命令的退出码相同。[--workdir TEXT --env TEXT --env-file TEXT --timeout FLOAT --namespace TEXT]hf sandbox kill— 终止一个沙箱、整个共享主机,或所有对象(--all)。[--all --yes --namespace TEXT --format [auto|human|agent|json|quiet]]hf sandbox pool create— 预热一个池:立即启动一台主机 VM,并为其添加标签,以便之后通过池 ID 查找。[--flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|rtx-pro-6000|rtx-pro-6000x2|rtx-pro-6000x4|rtx-pro-6000x8] --per-host INTEGER RANGE --max-hosts INTEGER RANGE --idle-timeout TEXT --namespace TEXT --format [auto|human|agent|json|quiet]]hf sandbox pool delete POOL_ID— 终止池中的所有主机 VM(因此也会终止其中的所有沙箱)。[--yes --namespace TEXT --format [auto|human|agent|json|quiet]]hf sandbox pool ls— 列出正在运行的沙箱池(按其主机 VM 分组)。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf sandbox process kill SANDBOX_ID PID— 停止在沙箱中运行的后台进程。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf sandbox process ls SANDBOX_ID— 列出在沙箱中运行的后台进程(使用hf sandbox spawn启动)。[--namespace TEXT --format [auto|human|agent|json|quiet]]hf sandbox spawn SANDBOX_ID COMMAND— 在后台启动长时间运行的命令并返回其 PID(不等待)。[--workdir TEXT --env TEXT --env-file TEXT --namespace TEXT]
hf skills — 管理 AI 助手的技能。
hf skills add— 为 AI 助手安装 Hugging Face 技能。[--global --dest PATH --force --format [auto|human|agent|json|quiet]]hf skills list— 列出 Hugging Face 市场中可用的技能。[--format [auto|human|agent|json|quiet]]hf skills preview— 将生成的hf-cliSKILL.md 输出到标准输出。[--format [auto|human|agent|json|quiet]]hf skills update— 更新已安装的 Hugging Face 市场技能。[--global --dest PATH --format [auto|human|agent|json|quiet]]
hf spaces — 与 Hub 上的空间交互。
hf spaces card SPACE_ID— 获取 Hub 上某个空间的空间卡片(README)。[--metadata --text --format [auto|human|agent|json|quiet]]hf spaces dev-mode SPACE_ID— 启用或禁用某个空间的开发模式。[--stop --format [auto|human|agent|json|quiet]]hf spaces hardware— 列出空间可用的硬件选项。[--format [auto|human|agent|json|quiet]]hf spaces hot-reload SPACE_ID— 热重载空间中的任意 Python 文件,无需完整重建并重启。[--local-file PATH --skip-checks --skip-summary --format [auto|human|agent|json|quiet]]hf spaces info SPACE_ID— 获取 Hub 上某个空间的信息。[--revision TEXT --expand TEXT --format [auto|human|agent|json|quiet]]hf spaces list— 列出 Hub 上的空间,或空间仓库中的文件。[--search TEXT --author TEXT --filter TEXT --sort [created_at|last_modified|likes|trending_score] --limit INTEGER --expand TEXT --human-readable --tree --recursive --revision TEXT --format [auto|human|agent|json|quiet]]hf spaces logs SPACE_ID— 获取某个空间的运行或构建日志。[--build --follow --tail INTEGER --format [auto|human|agent|json|quiet]]hf spaces pause SPACE_ID— 暂停某个空间。[--format [auto|human|agent|json|quiet]]hf spaces restart SPACE_ID— 重启某个空间。[--factory-reboot --format [auto|human|agent|json|quiet]]hf spaces search QUERY— 使用语义搜索在 Hub 上搜索空间。[--filter TEXT --sdk TEXT --include-non-running --description --limit INTEGER --format [auto|human|agent|json|quiet]]hf spaces secrets add SPACE_ID— 添加或更新某个空间的密钥。[--secrets TEXT --secrets-file TEXT --format [auto|human|agent|json|quiet]]hf spaces secrets delete SPACE_ID KEY— 删除某个空间中的密钥。[--yes --format [auto|human|agent|json|quiet]]hf spaces secrets list SPACE_ID— 列出某个空间的密钥。密钥值仅可写入,不会返回。[--format [auto|human|agent|json|quiet]]hf spaces settings SPACE_ID— 更新某个空间的设置。[--sleep-time INTEGER --hardware [cpu-basic|cpu-upgrade|zero-a10g|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8] --format [auto|human|agent|json|quiet]]hf spaces ssh SPACE_ID— SSH 连接到某个空间的开发模式容器。[--identity-file PATH --dry-run --auto --format [auto|human|agent|json|quiet]]hf spaces templates— 列出可用的空间模板。[--format [auto|human|agent|json|quiet]]hf spaces variables add SPACE_ID— 添加或更新某个空间的环境变量。[--env TEXT --env-file TEXT --format [auto|human|agent|json|quiet]]hf spaces variables delete SPACE_ID KEY— 删除某个空间中的环境变量。[--yes --format [auto|human|agent|json|quiet]]hf spaces variables list SPACE_ID— 列出某个空间的环境变量。[--format [auto|human|agent|json|quiet]]hf spaces volumes delete SPACE_ID— 删除某个空间的所有卷。[--yes --format [auto|human|agent|json|quiet]]hf spaces volumes list SPACE_ID— 列出挂载到某个空间的卷。[--format [auto|human|agent|json|quiet]]hf spaces volumes set SPACE_ID— 设置(替换)某个空间的卷。[--volume TEXT --format [auto|human|agent|json|quiet]]hf spaces wait SPACE_ID— 等待某个空间完成构建或启动。[--timeout TEXT --format [auto|human|agent|json|quiet]]hf spaces zero-gpu quota— 显示你的 ZeroGPU 配额(剩余 GPU 时间和重置日期)。[--format [auto|human|agent|json|quiet]]
hf webhooks — 管理 Hub 上的 Webhook。
hf webhooks create --watch TEXT— 创建新的 Webhook。[--url TEXT --job-id TEXT --domain [repo|discussions] --secret TEXT --secrets TEXT --secrets-file TEXT --format [auto|human|agent|json|quiet]]hf webhooks delete WEBHOOK_ID— 永久删除 Webhook。[--yes --format [auto|human|agent|json|quiet]]hf webhooks disable WEBHOOK_ID— 停用已启用的 Webhook。[--format [auto|human|agent|json|quiet]]hf webhooks enable WEBHOOK_ID— 启用已停用的 Webhook。[--format [auto|human|agent|json|quiet]]hf webhooks info WEBHOOK_ID— 显示单个 Webhook 的完整详情。[--format [auto|human|agent|json|quiet]]hf webhooks list— 列出当前用户的所有 Webhook。[--format [auto|human|agent|json|quiet]]hf webhooks update WEBHOOK_ID— 更新现有 Webhook。仅更改已提供的选项。[--url TEXT --job-id TEXT --watch TEXT --domain [repo|discussions] --secret TEXT --secrets TEXT --secrets-file TEXT --format [auto|human|agent|json|quiet]]
常用选项
--format— 输出格式:--format json(或--json)或--format table(默认)。-q / --quiet— 静默输出(每行一个 ID)。等同于'--format quiet'。--revision— Git 修订 ID,可以是分支名称、标签或提交哈希。--token— 使用用户访问令牌。建议设置HF_TOKEN环境变量,而不是传入--token。--type— 仓库类型(model、dataset、space 或 kernel)。
将仓库挂载为本地文件系统
若要将 Hub 仓库或存储桶挂载为本地文件系统——无需下载、复制或等待——请使用 hf-mount。文件会按需获取。GitHub:https://github.com/huggingface/hf-mount
安装:brew install hf-mount,或从 https://github.com/huggingface/hf-mount/releases 下载二进制文件。
部分命令示例:
hf-mount start repo openai-community/gpt2 /tmp/gpt2— 挂载仓库(只读)hf-mount start --hf-token $HF_TOKEN bucket myuser/my-bucket /tmp/data— 挂载存储桶(读写)hf-mount status/hf-mount stop /tmp/data— 列出挂载项或卸载
提示
- 使用
hf <command> --help查看完整选项、说明、用法和实际示例 - 使用
HF_TOKEN环境变量(推荐)或--token进行身份验证 - 使用
hf update更新 CLI(会根据检测到的安装方式使用正确的命令)
评论
支持 Markdown