The cat command can be used to create a text file if we immediately want to add some text to a new blank file. The syntax of the cat command to create a file is as follows:
$ cat > demo.txt
After pressing Enter, we will return to the prompt and we can directly start inserting text into our file. Once you are done entering text in the file, press Ctrl + D to mark the end of the file and return to the prompt, as shown in the following screenshot:
If you want to use the cat command to create a file from a bash script, we have to use an operator known as a here document. It can be any arbitrary string that can be used to mark the beginning of a file and end when repeated in a new line, as shown in the following screenshot: