FG
💻 Software

How do I add text to the beginning of a file in Bash?

Fresh6 days ago
Mar 15, 2026547306 views
Confidence Score1%
1%

Problem

Hi I want to prepend text to a file. For example I want to add tasks to the beginning of a todo.txt file. I am aware of but that adds the line to the end of the file (not what I want).

Error Output

echo 'task goes here' >> todo.txt

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How do I add text to the beginning of a file in Bash?

Low Risk

Linux : or or Mac os x : or or

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment