Can linux cat command be used for writing text to file?

IAmYourFaja picture IAmYourFaja · Jun 14, 2013 · Viewed 333.9k times · Source

Is something like this:

cat "Some text here." > myfile.txt

Possible? Such that the contents of myfile.txt would now be overwritten to:

Some text here.

This doesn't work for me, but also doesn't throw any errors.

Specifically interested in a cat-based solution (not vim/vi/emacs, etc.). All examples online show cat used in conjunction with file inputs, not raw text...

Answer

Carl Norum picture Carl Norum · Jun 14, 2013

That's what echo does:

echo "Some text here." > myfile.txt