Menu
Coddy logo textTech

Overwrite To A File

Part of the Fundamentals section of Coddy's Terminal journey. Lesson 38 of 82.

Now that you understand standard output, let's redirect it somewhere useful. The > operator takes the output of a command and writes it to a file instead of displaying it on screen.

echo "Hello" > greeting.txt

This creates a file called greeting.txt containing the word Hello. Nothing appears on screen because the output went into the file instead.

You can redirect the output of any command:

ls > filelist.txt
cat names.txt > backup.txt
date > timestamp.txt

Warning: The > operator overwrites the file completely. If the file already exists, its previous contents are erased and replaced with the new output.

echo "First line" > notes.txt
echo "Second line" > notes.txt
cat notes.txt

Output:

Second line

The first line is gone because the second command overwrote the entire file. This behavior is powerful but requires caution. You can accidentally lose data if you redirect to an existing file.

challenge icon

Challenge

Easy

Use the operator to redirect output into a file. Run these two commands in order:

  1. Use echo to write the text System initialized to a file called status.txt
  2. Use cat to display the contents of status.txt

Hint: The format is echo "text" > filename. After redirecting, nothing appears on screen. You need to use cat to verify the file was created.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Terminal playground