A collection of utility scripts for managing Ollama models on Linux systems. These tools help simplify common administration tasks for your Ollama server.
Ollama is a framework that allows you to run large language models locally. These utilities help you manage your Ollama installation more efficiently.
All scripts source ollama_common.sh, which holds the API client, the model
dependency map, formatting helpers and the proxy authentication logic. Keep it
next to the scripts; they refuse to run without it.
Every script uses the same exit codes:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Usage error |
| 2 | Missing dependency, or no proxy key when one is needed |
| 3 | Server unreachable, or refusing privileged operations |
| 4 | Completed, but one or more models failed |
Pulls the latest version of every installed model. Models that exist only
locally (for example those created by ollama_set_ctx.sh) are rebuilt on top of
their base model, with their PARAMETER overrides preserved.
A base model is only accepted on conclusive evidence:
details.parent_modelfrom the API, when it names another installed model. This field is frequently absent, self-referential, or a filesystem path from the machine that originally built the model, so it is always validated.- The
FROMweights-blob digest, when exactly one other installed model shares it.
When neither is conclusive the model is skipped with an explanation rather
than rebuilt on a guess. Earlier versions matched on architecture, parameter
count and quantization, which are not unique: that could rebuild qwen3.5:35b
on top of qwen3.6:35b. A model is also never rebuilt on top of its own
derivative.
Features:
--dry-runreports the base model each local-only model would use, changing nothing. Run this first.-p, --pattern <regex>limits the run to matching models-y, --yesskips the confirmation prompt- Closing summary of updated, rebuilt, skipped and failed models; exit 4 if any failed
- A failed pull is never taken as proof that a model is local-only. The server is asked directly whether privileged operations are permitted, because the CLI reports an authorization failure and a genuinely missing model in indistinguishable terms.
Sets the num_ctx parameter of your models. Ollama defaults to a small context
regardless of what a model was trained for; this raises it, optionally capped.
Features:
- Interactive per-model confirmation
[y/N/all], or-yfor unattended runs - Cap with
-m <size>, or set exactly with-s <size> - Sizes accept plain numbers,
k/M, and decimals with a unit:8192,8k,1.5k(= 1536),1M. A decimal with no unit (1.5) or a comma (1,5k) is rejected rather than guessed at. - Refuses a context larger than the model's native length unless
-fis given, since Ollama will not extend a model beyond its trained context - Batch mode skips models that are themselves derived from another installed
model, because deriving from a derivative stacks overrides.
--include-derivedopts in. - Refuses to create a model whose generated name equals its own source, which would rebuild it on top of itself
- Verifies the applied
num_ctxby reading it back from the server
-smeans--set-ctxhere, but--sortinollama_ls_details.sh. The flags are kept as they are for compatibility.
Backs up the Modelfile of every installed model into a timestamped directory
(ollama_modelfile_backups_YYYYMMDD_HHMMSS/), written next to the script rather
than into the current working directory.
Two files are written per model:
| File | Purpose |
|---|---|
<name>.Modelfile |
The server's raw dump, kept verbatim as a record. Not restorable: its FROM line points at a blob path on the server, such as FROM /root/.ollama/models/blobs/sha256-..., which no other machine can resolve. |
<name>.restore.Modelfile |
The same overrides with FROM rewritten to name a real model. This is the file to restore from. |
MANIFEST.txt records the server, the timestamp, and the base model resolved
for each entry. Each dump is verified to be non-empty, and an existing
non-empty target directory is never overwritten without --force.
./ollama_backup.sh
# Restore a model:
ollama create <model_name> -f ollama_modelfile_backups_YYYYMMDD_HHMMSS/<name>.restore.ModelfileDisplays a detailed table of your models: architecture, parameters, quantization, disk size, maximum and in-use context, VRAM and processor placement. Static metadata comes from a single API request, so listing is fast.
Columns:
| Column | Meaning |
|---|---|
| NAME | Model name |
| ID | Ollama's identifier (first 12 characters of the manifest digest) |
| ARCH | Architecture, for example qwen3, gemma3 |
| PARAMS | Parameter count, for example 7.6B, 307.58M |
| QUANT | Quantization, for example Q4_K_M, Q8_0, F16 |
| DISK | On-disk size |
| CTX(MAX) | The model's maximum context length |
| CTX(USED) | Context actually allocated when loaded |
| VRAM | VRAM in use when loaded |
| PROCESSOR | Placement, for example 100% GPU, 38%/62% CPU/GPU |
| AGE | How old the displayed measurement is |
CTX(USED), VRAM and PROCESSOR require the model to be loaded, so they are colour-coded by origin, with a key printed below the table:
| Colour | Origin |
|---|---|
| Green | Measured by this run |
| Yellow | Already loaded on the server, so reported without touching it |
| Dim | Restored from cache; AGE says how old |
| Red | Could not be measured |
Yellow is not a warning. It marks numbers that belong to whoever loaded the model, so the context and VRAM reflect their settings rather than this run's.
Features:
- Regex filtering on the model name
- Sort by column:
--sort NAME|ARCH|PARAMS|QUANT|DISK|CTX|VRAM|PROCESSOR, unit-aware so307.58Msorts below4.3B;--reverseto invert. With no--sortthe order matchesollama ls, newest first. - Per-server caching, so measurements from one host are never shown for another
- Interactive in-place table with progress animation, which falls back to plain output automatically when the table does not fit the window or output is redirected
--quickskips loading but still reports cached and already-resident values
USAGE:
./ollama_ls_details.sh [OPTIONS] [PATTERN]
OPTIONS:
-p, --pattern <regex> Filter models by extended regular expression.
-s, --sort <COLUMN> Sort by column: NAME, ARCH, PARAMS, QUANT, DISK, CTX,
VRAM, PROCESSOR. Default order is newest first.
--reverse Reverse the sort order.
--quick Skip loading models. Cached and already-resident
values are still shown.
--timeout <seconds> Maximum time to wait for one model to load (300).
--no-progress Disable the interactive display and animations.
--no-cache Ignore the cache and do not write to it.
--prune-cache Remove entries for models no longer installed, exit.
--clear-cache Delete the cache for this server, then exit.
-h, --help Display this help menu and exit.
ARGUMENTS:
[PATTERN] (Optional) Same as --pattern.VRAM, CTX(USED) and PROCESSOR are properties of a loaded model, so obtaining
them means loading it, and the numbers reflect the state of the whole server,
including whatever other users are doing. Loading is done with an empty prompt
through /api/generate, or through /api/embed for embedding models, which
have no completion capability and reject /api/generate. Either way no tokens
are generated.
The script is built to be a considerate neighbour:
- A model that is already resident is observed, never reloaded or evicted.
- Models this run loads are released on interrupt; models it did not load are left alone.
- On a busy GPU a model may land partly on the CPU, so PROCESSOR and VRAM can legitimately differ between runs. The AGE column tells you how stale a cached number is.
- Models may appear or disappear between runs as other users add or remove them.
- Linux, and a Bash shell (5.x)
- Ollama installed and configured
curlandjq, used for all API accesstput(fromncurses-bin) for the interactive display; without a terminal the scripts fall back to plain output automatically
-
Clone this repository (replace
YOUR_USERNAMEwith your GitHub username or fork path):git clone https://github.com/YOUR_USERNAME/ollama-admin-tools.git cd ollama-admin-tools -
Make the scripts executable:
chmod +x *.sh
By default, these tools connect to your local Ollama instance. To manage a remote Ollama server:
export OLLAMA_HOST="http://your-remote-server:11434"OLLAMA_HOST is accepted as host, host:port, or scheme://host:port; port
11434 is assumed when none is given.
Some deployments put Ollama behind a proxy that leaves reads open but protects
mutating operations such as pull, create and delete, granting a temporary IP
whitelist instead of using per-request tokens. auth.sh requests that
whitelist; because it lasts several hours, running it once per working day is
enough.
./auth.sh # request the whitelist
./auth.sh --status # report whether privileged operations are permittedThe key is never stored in the script. It is read from the first of:
$OLLAMA_PROXY_KEY${XDG_CONFIG_HOME:-$HOME/.config}/ollama-admin-tools/proxy_key.ollama_proxy_keynext to the scripts
Create the file and restrict it; both filenames are in .gitignore:
printf '%s\n' 'YOUR_KEY' > .ollama_proxy_key
chmod 600 .ollama_proxy_keyTo rotate the key, edit that file. Nothing else needs to change.
The key is sent to the server on curl's standard input, never as a
command-line argument, because the process list is readable by every user on a
shared machine. ollama_update_all.sh and ollama_set_ctx.sh authenticate once
at startup when a key is configured; the read-only tools never do.
Preview first — this shows the base model each local-only model would be rebuilt from, without changing anything:
./ollama_update_all.sh --dry-runThen run it:
./ollama_update_all.sh
./ollama_update_all.sh -y -p '^gemma3' # unattended, gemma3 models only# Display help information:
./ollama_set_ctx.sh --help
# Single Model Operations:
./ollama_set_ctx.sh llama3.3:latest # Update using native context
./ollama_set_ctx.sh -y llama3.3:latest # Update without confirmation prompt
./ollama_set_ctx.sh -f llama3.3:latest # Force update even if context already set
./ollama_set_ctx.sh -s 4096 llama3.3:latest # Set specific context size (4096)
./ollama_set_ctx.sh -s 32k llama3.3:latest # Set specific context size (32k)
./ollama_set_ctx.sh -m 8192 llama3.3:latest # Cap context at 8192
./ollama_set_ctx.sh -m 8k llama3.3:latest # Cap context at 8K (equivalent to 8192)
# New Model Operations:
./ollama_set_ctx.sh -a llama3.3:latest # Auto-named model with native context (e.g., 'llama3.3:128k_num_ctx')
./ollama_set_ctx.sh -a -m 16k llama3.3:latest # Auto-named model with capped context (e.g., 'llama3.3:16k_num_ctx')
./ollama_set_ctx.sh -a -s 4096 llama3.3:latest # Auto-named model with specific context (e.g., 'llama3.3:4k_num_ctx')
./ollama_set_ctx.sh -o llama3.3:full_context llama3.3:latest # Custom-named model with native context
./ollama_set_ctx.sh -o llama3.3:large -m 32k llama3.3:latest # Custom-named model with capped context
./ollama_set_ctx.sh -o llama3.3:4k -s 4096 llama3.3:latest # Custom-named model with specific context
# Batch Operations (All Installed Models):
./ollama_set_ctx.sh # Interactive update of all models (native context)
./ollama_set_ctx.sh -y # Non-interactive update of all models (native context)
./ollama_set_ctx.sh -y -f # Force update all models, no confirmations
./ollama_set_ctx.sh -y -m 8k # Update all models, cap at 8K
./ollama_set_ctx.sh -y -s 4096 # Update all models to exactly 4096 context
./ollama_set_ctx.sh -a # Create auto-named copies of all models with their native max context
./ollama_set_ctx.sh -a -m 16k # Create auto-named copies capped at 16K
# Combined Options:
./ollama_set_ctx.sh -y -f -m 32k llama3.3:latest # Force update with no confirmation, cap at 32K
./ollama_set_ctx.sh -y -f -a -m 16k llama3.3:latest # Create auto-named model, force, no confirmation, cap at 16KIf you have a system with limited RAM but want to use the maximum practical context size:
# Set all models to use at most 8k context but keeping their original names.
./ollama_set_ctx.sh -y -m 8kOr create copies with new auto named models:
# Create new models to use at most 8k context with auto generated names.
./ollama_set_ctx.sh -y -m 8k -aUnattended updates need care. The original example chained ollama_update_all.sh
into ollama_set_ctx.sh -y -m 32k -a, which creates a new auto-named model for
every installed model on every run, and does so without anyone watching.
Start by logging a dry run, so you can see what a real run would do:
0 2 * * 0 cd /path/to/ollama_admin_tools && ./ollama_update_all.sh --dry-run >> update_log.txt 2>&1Once the output looks right, narrow the scope with a pattern and keep the two operations separate:
0 2 * * 0 cd /path/to/ollama_admin_tools && ./ollama_update_all.sh -y -p '^(gemma3|qwen3)' >> update_log.txt 2>&1Notes for scheduled runs:
- Pass
-y. Without a terminal to prompt at, the scripts exit with an error rather than silently doing nothing or silently proceeding. crongets a minimal environment, so setOLLAMA_HOSTin the crontab if you target a remote server.- Behind a proxy, add
./auth.sh &&in front, since the whitelist will have expired overnight. - Check the exit code: 4 means some models failed while others succeeded.
Contributions are welcome! Feel free to submit pull requests or create issues for bugs and feature requests.
MIT License