You might be knowing opening and editing file in vi/vim editor in Linux system. Do you wonder- how you can edit file without vi or vim editor?
Many times you have to create a file, write the content on your Unix-line or Linux systems. Sometimes you require to write a program and run it. For all this, you need a text editor to read and write in the file.
So let’s see different commands for creating and editing the files even if you don’t have vi or vim editor, one-by-one…
Table of Contents
The vi and vim are two widely used command line editors on the Unix-like systems (including Linux). And many of the users know about vi and vim editor.
Following are the simple commands you can use to create the file and edit it.
vi fileName
There are two modes of opening file in vi editors. One is command mode and other is insert mode. As it’s not the part of this discussion. And it’s a big topic to discuss in full fledge. We will describe it in the upcoming article.
vim fileName
What if you don’t have vi or vim editor installed on your system?
You can use cat or touch command.
Using cat command to create file
cat fileName
Write the content and once it is done press ctrl+D.
It will save the contents to the file.
Note: Every time when you run this command, it will erase all the contents and write newly entered content. So, be careful if you have any important data in your file.
If you want to edit a file using cat, try the following the command
cat - > /path/to/file
You can also create the file using touch command.
touch fileName
If you are working on the Linux server, you can see there are limited packages installed on the server. There may be a restriction of using resources and so installed packages.
If none of the commands work, follow the steps give below.
You can use the simple scp command to copy the file from server to your local system.
scp server:/file/name .
If you have scripting or any other programming language installed on your system, you can use that to create and edit the file. For example…
It is pretty easy to edit the file using vi and vim editor. But sometimes you may need to edit the file without vi and vim editor. Hope these commands will help you to edit file if there is no vi, vim.
Other vi/vim editor’s commands f0r enhancing your Linux experience:
If you have any doubt or if you have any another alternative to edit file without vi/vim editor, feel free to write in a comment below.
If you are working in networking domain, you need lots of such commands to master Linux and networking.
Thanks for such a nice overview of these basics. I would like to read more of such, Thanks!
You are right, Marwal!
Thanks for your kind words.
I will keep adding more of these commands in future. Stay tuned…
Hi
Here my need is, I am connecting remote machine.
In that I should open.dat files and replace with some text for 10+ files at a time
How it possible. Please suggest me.
You can use any scripting language like Python, bash to overwrite the file content.