artwhisper
← Blog Mastering Hugging Face CLI: A Comprehensive Guide

Mastering Hugging Face CLI: A Comprehensive Guide

Learn how to manage Hugging Face Hub operations directly from the terminal with the `hf` CLI, covering login, downloading models and datasets, uploading files, and more.

Mar 2, 2026

Introduction

The hf CLI is a powerful tool for managing Hugging Face Hub operations directly from the terminal. This guide covers the core commands, authentication, download, upload, repository management, delete files from a repository, cache management, browsing the Hub, jobs (cloud compute), and inference endpoints.

Quick Command Reference

The following table provides a quick reference to the most common hf CLI commands:

Task Command
Login hf auth login
Download model hf download <repo_id>
Download to folder hf download <repo_id> --local-dir ./path
Upload folder hf upload <repo_id> . .
Create repo hf repo create <name>
Create tag hf repo tag create <repo_id> <tag>
Delete files hf repo-files delete <repo_id> <files>
List cache hf cache ls
Remove from cache hf cache rm <repo_or_revision>
List models hf models ls
Get model info hf models info <model_id>
List datasets hf datasets ls
Get dataset info hf datasets info <dataset_id>
List spaces hf spaces ls
Get space info hf spaces info <space_id>
List endpoints hf endpoints ls
Run GPU job hf jobs run --flavor a10g-small <image> <cmd>
Environment info hf env

Core Commands

Authentication

Authentication is the first step to using the hf CLI. The following commands cover authentication:

hf auth login                    # Interactive login
hf auth login --token $HF_TOKEN  # Non-interactive
hf auth whoami                   # Check current user
hf auth list                     # List stored tokens
hf auth switch                   # Switch between tokens
hf auth logout                   # Log out

Download

The download command is used to download models and datasets from the Hugging Face Hub:

hf download <repo_id>                              # Full repo to cache
hf download <repo_id> file.safetensors             # Specific file
hf download <repo_id> --local-dir ./models         # To local directory
hf download <repo_id> --include "*.safetensors"    # Filter by pattern
hf download <repo_id> --repo-type dataset          # Dataset
hf download <repo_id> --revision v1.0              # Specific version

Upload

The upload command is used to upload files and folders to the Hugging Face Hub:

hf upload <repo_id> . .                            # Current dir to root
hf upload <repo_id> ./models /weights              # Folder to path
hf upload <repo_id> model.safetensors              # Single file
hf upload <repo_id> . . --repo-type dataset        # Dataset
hf upload <repo_id> . . --create-pr                # Create PR
hf upload <repo_id> . . --commit-message="msg"     # Custom message

Repository Management

The following commands cover repository management:

hf repo create <name>                              # Create model repo
hf repo create <name> --repo-type dataset          # Create dataset
hf repo create <name> --private                    # Private repo
hf repo create <name> --repo-type space --space_sdk gradio  # Gradio space
hf repo delete <repo_id>                           # Delete repo
hf repo move <from_id> <to_id>                     # Move repo to new namespace
hf repo settings <repo_id> --private true          # Update repo settings
hf repo list --repo-type model                     # List repos
hf repo branch create <repo_id> release-v1         # Create branch
hf repo branch delete <repo_id> release-v1         # Delete branch
hf repo tag create <repo_id> v1.0                  # Create tag
hf repo tag list <repo_id>                         # List tags
hf repo tag delete <repo_id> v1.0                  # Delete tag

Delete Files from Repo

The following command is used to delete files from a repository:

hf repo-files delete <repo_id> folder/             # Delete folder
hf repo-files delete <repo_id> "*.txt"             # Delete with pattern

Cache Management

The following commands cover cache management:

hf cache ls                      # List cached repos
hf cache ls --revisions          # Include individual revisions
hf cache rm model/gpt2           # Remove cached repo
hf cache rm <revision_hash>      # Remove cached revision
hf cache prune                   # Remove detached revisions
hf cache verify gpt2             # Verify checksums from cache

Browse Hub

The following commands are used to browse the Hugging Face Hub:

# Models
hf models ls                                        # List top trending models
hf models ls --search "MiniMax" --author MiniMaxAI  # Search models
hf models ls --filter "text-generation" --limit 20  # Filter by task
hf models info MiniMaxAI/MiniMax-M2.1               # Get model info

# Datasets
hf datasets ls                                      # List top trending datasets
hf datasets ls --search "finepdfs" --sort downloads # Search datasets
hf datasets info HuggingFaceFW/finepdfs             # Get dataset info

# Spaces
hf spaces ls                                        # List top trending spaces
hf spaces ls --filter "3d" --limit 10               # Filter by 3D modeling spaces
hf spaces info enzostvs/deepsite                    # Get space info

Jobs (Cloud Compute)

The following commands are used to run jobs on the Hugging Face infrastructure:

hf jobs run python:3.12 python script.py           # Run on CPU
hf jobs run --flavor a10g-small <image> <cmd>      # Run on GPU
hf jobs run --secrets HF_TOKEN <image> <cmd>       # With HF token
hf jobs ps                                         # List jobs
hf jobs logs <job_id>                              # View logs
hf jobs cancel <job_id>                            # Cancel job

Inference Endpoints

The following commands are used to manage inference endpoints:

hf endpoints ls                                     # List endpoints
hf endpoints deploy my-endpoint \
  --repo openai/gpt-oss-120b \
  --framework vllm \
  --accelerator gpu \
  --instance-size x4 \
  --instance-type nvidia-a10g \
  --region us-east-1 \
  --vendor aws
hf endpoints describe my-endpoint                   # Show endpoint details
hf endpoints pause my-endpoint                      # Pause endpoint
hf endpoints resume my-endpoint                     # Resume endpoint
hf endpoints scale-to-zero my-endpoint              # Scale to zero
hf endpoints delete my-endpoint --yes               # Delete endpoint

Topics:

  • Hugging Face CLI,
  • Hugging Face Hub,
  • Model and Dataset Management,
  • Repository Management,
  • Cache Management,
  • Cloud Compute,
  • Inference Endpoints