All Modules / Module 7 / Lesson 3 of 4

Saving command output to files

4 minute read

Save Output to a File

Sometimes you don't want to copy output — you want to save it to a file. Terminal has special symbols for this.

The > Symbol: Create or Overwrite

The > symbol sends output to a file instead of showing it on screen:

1

Save a directory listing to a file:

ls -la > filelist.txt
2

Check the contents:

cat filelist.txt

Careful! Using > will overwrite the file if it already exists. No warning, no undo.

The >> Symbol: Append

If you want to add to a file instead of replacing it, use double arrows:

1

Add the date to your file:

date >> filelist.txt
2

Check — it's at the end now:

cat filelist.txt

Real Uses

echo "note" >> notes.txt

Quick note-taking from Terminal

history > commands.txt

Save your command history for reference

Key Takeaway

> saves output to a file (overwrites). >> appends to a file. Both are essential for logging and saving data.