HuggingFace CLI Cheatsheet
The HuggingFace CLI is the command-line tool for interacting with the HuggingFace Hub. Use it to download/upload models and datasets, manage cache, create/delete repositories, and handle authentication. Supports resume downloads and file filtering for large model downloads.
Quick Start
``bash
# Login
huggingface-cli login --token hf_xxxxxxxx
# Download a model huggingface-cli download meta-llama/Llama-3.1-8B --local-dir ./models
# Download only GGUF files huggingface-cli download bartowski/Llama-3.2-3B-Instruct-GGUF --include '*.gguf'
# Check current user huggingface-cli whoami
# View cache usage
huggingface-cli scan-cache
`
Authentication
Login with huggingface-cli login --token . Tokens are managed at huggingface.co/settings/tokens. For CI/CD, use export HF_TOKEN=hf_xxx. Models requiring access approval (like Llama) need a token with accepted terms.
Download
The download command is the most used feature. Key flags: --local-dir (output path), --include (file filter), --exclude (skip files), --repo-type (model/dataset/space), --revision (branch/tag), --resume-download (resume interrupted), --cache-dir (custom cache).
Upload
Use upload to push files. First create a repo with repo create, then upload files. Supports --repo-type for dataset repos. For large files (>5MB), LFS is handled automatically.
Cache Management
scan-cache shows cached repos and versions. delete-cache interactively removes unused versions. Set HF_HOME to change the cache location. The default cache at ~/.cache/huggingface/hub can grow very large (100GB+ for multiple models).
Environment Variables
HF_TOKEN for authentication, HF_ENDPOINT for mirror endpoints (China: https://hf-mirror.com), HF_HOME for cache directory, HF_HUB_ENABLE_HF_TRANSFER=1 for faster downloads with hf_transfer`.
Startup & Modes(14)
| Command | Level | ||
|---|---|---|---|
huggingface-cli --helpShow huggingface-cli help | Basic | huggingface-cli --help | |
huggingface-cli loginLog in to HuggingFace account | Basic | huggingface-cli login --token hf_xxx | |
huggingface-cli logoutLog out | Basic | huggingface-cli logout | |
huggingface-cli whoamiCheck current logged-in user | Basic | huggingface-cli whoami | |
huggingface-cli scan-cacheScan HuggingFace cache | Intermediate | huggingface-cli scan-cache | |
huggingface-cli delete-cacheDelete specific version from cache | Intermediate | huggingface-cli delete-cache | |
huggingface-cli envShow HuggingFace environment info | Basic | huggingface-cli env | |
huggingface-cli repo createCreate a new repository | Intermediate | huggingface-cli repo create my-new-model --type model | |
huggingface-cli repo deleteDelete a repository | Expert | huggingface-cli repo delete my-user/old-model | |
huggingface-cli lfs-enable-largefilesEnable large file support (LFS) | Intermediate | huggingface-cli lfs-enable-largefiles ./repo | |
huggingface-cli tagTag a repository version | Intermediate | huggingface-cli tag my-user/my-model v1.0 | |
huggingface-cli listList user's models/datasets | Basic | huggingface-cli list | |
export HF_TOKENSet HuggingFace token environment variable | Basic | export HF_TOKEN=hf_xxxxxxxxxxxx | |
export HF_ENDPOINTSet HF mirror endpoint (for China users) | Basic | export HF_ENDPOINT=https://hf-mirror.com |
ai-model(10)
| Command | Level | ||
|---|---|---|---|
huggingface-cli downloadDownload model or dataset (core feature) | Basic | huggingface-cli download meta-llama/Llama-3.1-8B --local-dir ./models/llama | |
huggingface-cli download --local-dirSpecify local download directory | Basic | huggingface-cli download meta-llama/Llama-3.1-8B --local-dir ./models | |
huggingface-cli download --repo-typeSpecify repo type (model/dataset/space) | Intermediate | huggingface-cli download databricks/databricks-dolly-15k --repo-type dataset | |
huggingface-cli download --revisionDownload specific version/branch | Intermediate | huggingface-cli download meta-llama/Llama-3.1-8B --revision main | |
huggingface-cli download --includeOnly download files matching pattern | Intermediate | huggingface-cli download meta-llama/Llama-3.1-8B --include '*.gguf' | |
huggingface-cli download --excludeExclude files matching pattern | Intermediate | huggingface-cli download meta-llama/Llama-3.1-8B --exclude '*.safetensors' | |
huggingface-cli download --cache-dirSpecify cache directory | Intermediate | huggingface-cli download meta-llama/Llama-3.1-8B --cache-dir /data/hf-cache | |
huggingface-cli uploadUpload file to HuggingFace | Intermediate | huggingface-cli upload my-user/my-model ./model.gguf | |
huggingface-cli upload --repo-typeUpload to specific repo type | Intermediate | huggingface-cli upload my-user/my-dataset ./data --repo-type dataset | |
huggingface-cli download --resume-downloadResume interrupted download | Intermediate | huggingface-cli download meta-llama/Llama-3.1-8B --resume-download |