Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Ollama Related Commands

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

2. Available commands

3. Flags

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:


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:


9. API (when serve is running)

REST endpoint http://localhost:11434/api:

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.