In Linux, we can create the file in many ways.
1. Using cat command.
2. Using touch command.
3. Echo command.
4. Using vi or other editors.
1-3 methods of files creation have already been explained in their respective sections. Please click on them to know more about their syntax.
Here, we will describe the 4th approach, i.e, using editors.
“Editor is a tool provided by the operating system to work with files. “
This is similar to our notepad, WordPad, and other tools available for editing files on the machine on windows OS.
Linux operating system is equipped with wide variety of editors to work with documents. They are,
Vi or view editor
Here, we will discuss vi editor options for handling files in Linux.
Vi stands for “Visual Interface” Editor. It is by default provided with Linux flavor operating systems.
By using the vi editor, we can create the files and modify the files.
The syntax for creating the file is
let’s understand its process with below example,
we want to create a file with abclearn1 and update few lines in it.
On the terminal window type,
For any text file in Linux, it is not mandatory to give file extensions.
i.e, abclearn1 and abclearn1.txt both are same.
The Vi editor creates a new file with abclearn1 but it is not yet saved and doesn’t have any content in it.
Below shown an example of the file.
We can start entering the content into the file.
To save this file, we should give
Press Esc button – we can observe that ” --insert--“ option is gone.
Type, “:w” -- for writing the content permanent to memory.
Then, press enter.
The written content is saved.
To come out of this file,
“:q!” -- q is for quitting.
Assume that I have opened a file using vi editor,
We thought file basic operations can be better explained in the form of questions and answers. So, we have framed the same.
These are few which are regularly used on the day to day operations.