How to quickly create text file in Linux using Command Line [Tip]

linuxterminalIf you are a keyboard lover and love typing, many of things can simply be accomplished using command line interface. For instance, there are some methods that you are required to apply for the creation of the files.

The first method is in which anyone can use for the creating the text file uses the “cat” command. Alternatively,  the cursor will be blinking on the next line, which will allow you to enter the text to the file. Type the text and press Enter key after each line. When you have just completed your work, to exit the file press Ctrl + D and you will be directed to the prompt.

If you are in doubt and want to clarify whether your file has been created or not, the following command will help you. Just type the command at the prompt and press Enter.

The point to note is that the command will begins with ‘L’ in lowercase and the option (-l) is also a lowercase ‘L’.

The format of the command will be.

ls –l smaple.txt

The screen will display a directory listing of the files of your system.

If at some point you want screen to display the content of your files ‘cat’ command will be used. To display the content type the given command with the following format to display the content.

cat sample.txt

After pressing enter you will be directed to the prompt and screen will display you the content of the file.

Right arrow (>) is one of the useful method in order to create a blank text file. Write the right arrow ‘>’ which will be followed by a complete file name. When you have completed the file name press the ‘Enter ’ key.

There can be a situation where you are directed to the prompt with no indication that a file was created. For verification type the command “ls” and the results will show the update about the presence of file

After you typed the “cat” command, which is used to view the content of the file, if it displays nothing this simply means that the created file contain no any text yet.

The command for entering text in the file is “VI’. Along with the name of the file Vi is used to enter the text into the file. The format is demonstrated below.

Vi sample.txt

Command mode is the place where vi opens. If you want to add some text in the file using the text editor then using the keyboard type ‘i’ and press enter. The thing must be kept focus is that small letter ‘i’ is used. After pressing the Enter key, you will enter the text editing mode. Type the text which you want to save. To return back to the command mode while saving your text press the Esc key.

Now to save your file and close the Vi, “wq” is pressed using the keyboard and after that press the Enter key.

Related Posts