>_ IzzyLab

Topic breakdown

Almost every command prints its result to the screen. The shell can redirect that output to a file:

  • > writes to a file; if the file existed, its old contents are lost;
  • >> appends to the end of a file; if there's no file, it's created.

echo simply prints its arguments, which makes it handy for writing lines to files. If the text has spaces or punctuation, put it in quotes so the shell passes it along as one piece:

echo 'first line' > /tmp/list.txt
echo 'second line' >> /tmp/list.txt
cat /tmp/list.txt     # both lines are there

What's checked

  1. /root/hello.txt holds the line "Hello, Linux"
  2. The first two lines of todo.txt are untouched
  3. A new third line at the end of todo.txt

What it looks like