DEV Community

Burdette Lamar
Burdette Lamar

Posted on

Create a Text File from Linux Command Line

Here are some ways I can create a text file from the Linux command line.

cat

Command cat with no source file specified reads from stdin. So I can type this (ending with Ctrl-D):

$ cat > t.txt
Foo
Bar
Baz

echo

Command echo has option -e, which enables interpretation of backslash escapes. So I can type this:

$ echo -e "Foo\nBar\nBaz\n" > t.txt

touch

And finally, if I don't need content in the file, I can just type:

touch t.txt

Top comments (1)

Collapse
 
qcgm1978 profile image
Youth

There're three kinds of commands to create file I know now.