Ollama Related Commands
Ollama provides a variety of command-line tools (CLIs) for users to interact with locally running models.
Basic format:
ollama [args]
We can use ollama --help to see which commands are included:
Large language model runner
Usage:
ollama [flags]
ollama [command]
Available Commands:
serve Start ollama
create Create a model from a Modelfile
show Show information for a model
run Run a model
stop Stop a running model
pull Pull a model from a registry
push Push a model to a registry
list List models
ps List running models
cp Copy a model
rm Remove a model
help Help about any command
Flags:
-h, --help help for ollama
-v, --version Show version information
1. Usage
-
ollama [flags]: Run ollama using flags.
-
ollama [command]: Run a specific command of ollama.
2. Available commands
- serve: start the ollama service.
- create: create a model from a Modelfile.
- show: display detailed information about a model.
- run: run a model.
- stop: stop a running model.
- pull: pull a model from a model registry.
- push: push a model to a model registry.
- list: list all models.
- ps: list all running models.
- cp: copy a model.
- rm: delete a model.
- help: get help about any command.
3. Flags
- -h, --help: show ollama's help information.
- -v, --version: show version information.
Complete example:
| Command | Description | Example |
|---|---|---|
ollama run |
Run a model. If it does not exist, it is pulled automatically. | ollama run llama3 |
ollama pull |
Pull a model. Download a model from the library without running it. | ollama pull mistral |
ollama list |
List models. Display all locally downloaded models. | ollama list |
ollama rm |
Delete a model. Remove a local model to free space. | ollama rm llama3 |
ollama cp |
Copy a model. Copy an existing model to a new name (for testing). | ollama cp llama3 my-model |
ollama create |
Create the model. Create a custom model from a Modelfile (advanced). | ollama create my-bot -f ./Modelfile |
ollama show |
Display information. View a model's metadata, parameters, or Modelfile. | ollama show --modelfile llama3 |
ollama ps |
View processes. Display currently running models and VRAM usage. | ollama ps |
ollama push |
Push a model. Upload your custom model to ollama.com. | ollama push my-username/my-model |
ollama serve |
Start the service. Start Ollama's API service (usually runs automatically in the background). | ollama serve |
ollama help |
Help. View help information for any command. | ollama help run |
1. Pulling and deleting models
pull
Pull a remote model locally.
ollama pull
rm / remove
Delete a local model.
ollama rm
list / ls
List all local models.
ollama list
2. Running a model
run
Run a model in interactive mode without exiting.
ollama run
Can include system information and prompt:
ollama run -s "" -p ""
run + script
Read prompt from a file:
ollama run < input.txt
When you type ollama run After entering the chat interface, you are no longer operating the command line but talking with the AI. At this point you can use commands starting with / to control the conversation with shortcut commands:
/byeor/exit:Most important! Exit the chat interface and return to the command line./clear: Clear the current context memory (start a new conversation)./show info: View detailed parameter information of the current model./set parameter seed 123: Set the random seed (advanced, used to reproduce results)./help: View all available shortcuts in chat.
3. Inference interface (one-time execution)
generate
Perform a single inference and output text.
ollama generate -p ""
4. Creating and modifying models
create
Create a local model with a Modelfile.
ollama create -f Modelfile
cp
Copy a model to a new name.
ollama cp
5. Server-related
serve
Start the Ollama local service (default 11434).
ollama serve
run serverless
When ollama run automatically starts the background service; no separate execution needed.
6. Model information
show
View model metadata, parameters, templates.
ollama show
7. Dedicated parameters
Most of these parameters can be used with run/generate:
--num-predict 限制输出 token 数
--temperature 控制随机性
--top-k 采样范围
--top-p 核采样
--seed 固定随机性
--format json Output JSON
--keepalive 会话保持时间
8. Modelfile directives
Used when building a model:
- FROM
: base model - SYSTEM "xxx": set the system prompt
- PARAMETER key=value: set default parameters
- TEMPLATE "xxx": custom Chat template
- LICENSE "xxx": set the License
- ADAPTER
/ WEIGHTS : load LoRA or additional weights
9. API (when serve is running)
REST endpoint http://localhost:11434/api:
/api/generate: text generation/api/chat: chat streaming interface/api/pull: remote pull/api/tags: local model list
Call example (curl):
curl http://localhost:11434/api/generate \
-d '{"model":"qwen2.5","prompt":"hello"}'
10. Advanced
Run with custom parameters:
ollama run --temperature 0.2 --top-p 0.9
Persistent session (preserve context):
Sessions are automatically managed by the model's internal cache, no extra commands needed.