What if the file already exists?

QuestionsQuestions8 SkillsProBasic Files OperationsOct, 29 2025
087

If the file file2.txt already exists when you run the command:

echo "Hello, Linux" > file2.txt

The existing content of file2.txt will be overwritten with the new text "Hello, Linux".

If you want to append the text instead of overwriting, you can use the >> operator:

echo "Hello, Linux" >> file2.txt

This will add "Hello, Linux" to the end of the existing file without deleting its current content.

0 Comments

no data
Be the first to share your comment!