Example 01: VI Editor
In the Linux family, the VI editor is perhaps the most common and basic text editor. Here are some of the major reasons why it is such a popular editor:
- It’s included in practically every Linux/UNIX distribution.
- It is compatible with a wide range of systems and versions.
- It is simple to use.
As a result, many Linux users adore it and employ it to do their editing tasks. If you specify an already-existing file in the current directory, the VI editor will open it for editing. You can also make a new file if necessary by using the same method. As you can see in the image below, when we type this command, the VI editor opens the bash file, which is located in the project1 directory of git.
The screen below displays the contents of an existing file. Symbols (~) represent empty lines in a new or open file that can be edited.
Example 2: Vim Editor
Vim is a text editor that allows us to create and modify text and other files. VIM is a more advanced and extended version of the VI editor. In vim, there are two modes: the command mode andthe insert mode. The user can navigate around the file, delete content, and so on using the command mode. The user will input text in the insert mode. If you don’t have VIM installed on your Linux machine, use the command “sudo apt-get install vim” to do so. VIM can be installed in a short amount of time. Without first installing VIM Editor, the vim command will not be recognized by the Linux terminal as shown below.
After installing it, to open an existing file or create a new one, use the vim command followed by the whole directory path as shown below.
You can also try using the name of a file within vim instruction after moving within the directory that contains the specific file to be opened.
When we just typed the vim command, as shown above, the terminal navigated us to the file shown in the screenshot. The screen indicates that the file is empty; save and close the file after inputting the appropriate input data of your choice.
–
Example 3: Gnu Nano Editor
In this example, you will learn how to install and use the Nano editor in Linux. For Linux and Unix-like operating systems, Nano is a well-known text editor among users. Nano is a powerful editor that allows you to create, open, and edit a wide variety of files. To begin, use the nano –version command to determine whether nano is installed on your machine on the Linux operating system. If this operation returns a GNU nano version, it means NANO is already installed on your Linux system; otherwise, it must be installed.
If it’s not already installed, try running the below-presented command on a Debian, Linux, UNIX, or Ubuntu computer to install the Nano text editor. Then sit back and wait for the installation to complete.
r
When we press the enter key, the Nano editor opens the text file in editing mode, as shown in the shell screen below. Simply press the Ctrl + X keys together to close the file after editing. You may open files with the extensions .txt, .sh, .php, and .html. Just remember that if you want to access a specific file in Nano editor, you must either be in the same directory where it is located or type the entire directory path. The syntax is given below:
Nano will generate a new file if you input a file name that does not exist in the directory. Alternatively, if you run the nano command without supplying a file name, the Nano text editor will generate an empty file with no name and prompt you for one when you depart the editor. When you run the nano instruction, a new window will appear, allowing you to update the file in a variety of ways. The user interface for the Nano text editor is shown above. Simply use the arrow keys on your computer to move the cursor around the text.
Example 4: Cat Instruction
If you’ve ever dealt with Linux, you’ve almost certainly come across the cat command. Concatenate is abbreviated as a cat. This command shows the contents of one or more files without requiring the file to be opened for modification. You need to add the file name after the “cat” keyword in the particular directory to open a file. You can see the data within the newfile.txt has been displayed in our shell.
The “-n” option allows you to give the cat command instructions.
Conclusion:
This is all about the use of different text editors and commands to open any type of file in the Kali Linux system. We have discussed some examples to open any type of file in Linux’s vi editor, vim editor, and Gnu Nano editor. Also, we have discussed the use of “cat” instruction to display data on the shell screen.