Another way to create a text file

You can create a multiline text file without using any text editor. This is done like this:

# cat > ~/test.txt <<EOF

~/test.txt is the file we want to create. Now you can type the contents line by line. When you are finished, type EOF:

>EOF

Another way to create a text file by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2005 - Some Rights Reserved

George Notaras avatar

About George Notaras

George Notaras is the editor of the G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.

4 responses on “Another way to create a text file

  1. Yannick Permalink →

    I use:
    cat > test.txt
    next I type the contents line by line and hit CTRL+C when I finished typing..

    Seems to do the same thing but a bit easier :)

  2. George Notaras Post authorPermalink →

    Hi, Yannick. I just now noticed your comment. Was busy doing some things on the site…
    Thanks for this tip. Works just fine. An absolutely quicker way than the one I wrote about. :-)

  3. agorf Permalink →

    Ctrl+D is more appropriate since it stands for EOF (End Of File).

  4. George Notaras Post authorPermalink →

    Indeed, Ctrl-D is more appropriate and, apparently, the correct alternative choice to typing “EOF”.