How to append instead of overwrite?

QuestionsQuestions8 SkillsProData Stream RedirectionOct, 21 2025
0191

To append content to a file instead of overwriting it in Linux, you can use the >> operator with the cat command. Here’s how you can do it:

Command:

cat >> file

Steps:

  1. Append Mode: When you run cat >> file, it opens the specified file (file) in append mode. If the file does not exist, it will be created.

  2. Input Content: You can start typing the content you want to append to the file.

  3. End Input: To finish entering content and save it to the file, press Ctrl + D (EOF - End Of File) on a new line.

Example:

cat >> myfile.txt
This is an additional line.
# Press Ctrl + D to save and exit

After executing the above commands, if myfile.txt previously contained:

This is the first line.
This is the second line.

It will now contain:

This is the first line.
This is the second line.
This is an additional line.

Using >> ensures that the existing content of the file remains intact while adding new content at the end.

0 Comments

no data
Be the first to share your comment!