Do you want to create a text file using command line?. Yes, you can simply create a text file by using some easy codes as shown in the steps below.
Here, we described two methods to do so. Just have a glance at this article in order to find out how to create a text file using command line in Ubuntu 14.04.
Steps to create a text file using command line interface:
Method 1 of 2: Using cat command
Step 1: First, go to the Unity dash and type ”Terminal’‘. You’ll see a terminal icon, just click on it to open.
Step 2: Under ‘Terminal’, type: “cat > your filename.txt” and then press enter, for eg. “cat > test.txt”. The “cat” command is used to create a file. Here, you can enter your text and after that press “Ctrl + D” to exit and return to the command prompt.
Step 3: Now, type; “ls-l your filename.txt” and press enter, where ‘ls’ command displays the list of files. It displays file creation time and date as well as the file directory.
Step 4: The “cat” command is also used to view the contents of the file. Type: “cat your filename.txt” and press enter, for eg. “cat test.txt”.
Method 2 of 2: Using touch command
Step 1: Under terminal, type: “touch your filename“ and press enter. The touch command creates an empty text file, that is why if you would use the ‘cat’ command then you’ll not get any output. So, in this scenario you must use some text editor to add your text.
Step 2: Type: “vi your filename“ and press enter, here “vi” stands for the text editor.
Step 3: Type your text in the “vi editor” and press “:q” to exit and return to the command prompt.
Step 4: Now, you can use “cat command” to see your text file.