How to redirect echo output?

0164

You can redirect the output of the echo command using the > and >> operators in the terminal.

  1. Using > to create or overwrite a file:

    This operator redirects the output to a file. If the file already exists, it will be overwritten.

    echo 'hello labex' > redirect.txt
    

    This command creates a file named redirect.txt with the content "hello labex".

  2. Using >> to append to a file:

    This operator appends the output to the end of an existing file without overwriting it.

    echo 'labex.io' >> redirect.txt
    

    This command adds "labex.io" to the end of the redirect.txt file.

You can then view the contents of the file using the cat command:

cat redirect.txt

This will display both lines you added to the file.

0 Comments

no data
Be the first to share your comment!