How to redirect echo output to a file?

0187

You can redirect the output of the echo command to a file using the > or >> operators. Here's how to do it:

  1. Using > to create or overwrite a file:
echo 'Hello LabEx' > output.txt

This command will create a file named output.txt and write "Hello LabEx" to it. If output.txt already exists, its content will be overwritten.

  1. Using >> to append to a file:
echo 'Welcome to LabEx' >> output.txt

This command will append "Welcome to LabEx" to the end of output.txt without overwriting the existing content.

You can check the contents of the file using the cat command:

cat output.txt

0 Comments

no data
Be the first to share your comment!