New Tool Radar

Local AI

How to Pipe a File into Ollama Run and Ask About It

Pipe a text file into ollama run with a short instruction to summarise it or ask about it, without pasting the file into a chat.

Schematic diagram with three steps: write a practice text file, pipe it into ollama run with an instruction, then read the one-sentence summary saved to a file.

ollama run on its own opens an interactive chat, but with a prompt as the next argument it answers once and exits. You can also pipe text in, and Ollama appends the file to your instruction. That turns a file on your disk into a question you can ask in one line, with no pasting and no chat history to manage. The Ollama commands cheat sheet shows all three forms in one place.

Pipe a file in with a one-line instruction

The cheat sheet’s own examples, run on Ollama 0.40.14 on an Ubuntu 24.04 machine with 4 vCPUs and no GPU, use qwen3.5:4b with --think=false, because Qwen 3.5 thinks by default and the flag keeps the reply to the answer.

Form Command (cheat sheet’s own) What it does
Prompt as an argument ollama run qwen3.5:4b --think=false "What port does PostgreSQL use? One sentence." Answers once and exits; nothing is piped in
Pipe a short line in echo "What is the capital of France? One word." | ollama run qwen3.5:4b --think=false The piped line becomes part of the prompt
Pipe a file in cat /var/log/apt/history.log | ollama run qwen3.5:4b --think=false --nowordwrap "Which packages were installed? One line." The whole file is appended to the instruction

The third line is the one to copy: the file goes in through the pipe, the instruction goes in as the argument, and the two together are the prompt. A research-group wiki shows the same pattern for summarising, with the output redirected to a file: cat $( ls data/*.txt | head -n 10 ) | ollama run command-r7b:latest "Summarize this:" > summary.txt. The wiki warns about the one limit that matters: you have to watch the amount of text being sent relative to the context length of the model, and it notes that the longer context length of llama3.1:8B might make it a better choice there than command-r7b.

Try it: summarise a practice file

Make a small practice file with three short lines, all fictional:

practice-notes.txt

Line Text
1 The lighthouse keeper named Mara checked the lamp at noon.
2 The supply boat arrives on Tuesdays.
3 The lamp oil is stored in the shed by the jetty.

Then pipe it in and save the answer:

cat practice-notes.txt | ollama run llama3.2 "Summarise this in one sentence:" > practice-summary.txt

Check What you should see What it means
File piped in The command runs without asking for the text again The pipe supplied the file as the prompt
Instruction as argument The answer is one sentence, not a chat The argument told the model what to do with the file
Output saved practice-summary.txt holds the summary The answer went to a file instead of the screen

Expected result. We checked the Ollama commands cheat sheet, which shows the pipe form with its own file and instruction and reports that the file example took 2m12s on its test box. We did not run ollama run on this machine, so we have no summary of our own; the practice file above is fictional, and its summary is the expected result, not a real reply.

Limits

The cost scales with what you pipe in: the model reads the whole file as prompt tokens, so the cheat sheet advises piping tail -n 50 of a big file rather than all of it. Add --nowordwrap whenever the output goes to a file or another program, because it keeps a terminal from rewrapping your capture. Spinner codes still go to stderr, so do not merge it with 2>&1 when you capture output. The examples above work with plain text files; the wiki notes that other file types need conversion tools first. The pipe examples and the 2m12s timing in this guide come from a third-party cheat sheet that was checked against Ollama 0.40.14, not from Ollama’s own documentation. We did not test any of this ourselves.

Sources

See all