- How can I edit a file if there is no vi, vim, joe, etc?
- 9 Answers 9
- How to Edit File in Linux
- How To Edit File in Linux Through Nano Editor
- How To Edit File in Linux Through Vim Editor
- Conclusion
- About the author
- Syeda Wardah Batool
- How to Edit a File in Linux? [SOLVED]
- Edit Files in GUI using Gedit
- Edit Files in CLI
- Method-1: Using VIM
- Method-2: Using nano
- Alternatives
- What is NEXT
- Summary
- References
- How to edit a text file in my terminal
- 6 Answers 6
How can I edit a file if there is no vi, vim, joe, etc?
Is there a way to edit a file if there are no vi, vim, joe, mcedit? In another words is there a way to edit a file using just the shell commands?
Make a copy of the file you want to edit. Then do cat file , followed by cat >file and arrange the parts with cut+paste and/or typing, finish with ctrl-d .
This also happened to me, in docker.. It is very minimalistic. Now how the heck do i do something like that. The VM is ephemeral, i cannot ssh nor ftp, i have to use redirection and hacks like sed to change some files. It was a great challenge. See how reliant we are on editors 😛
If this is a container or accessed via some other host you can use echo <
9 Answers 9
In that instance, I’d try transferring files out and editing them on another computer, then transfer them back. If you have ssh, you should have scp (I hope), so you should be able to push files in and out. If not, you can also look for ftp to transfer files in and out.
If not, then I think your best option is to try and make use of cat, grep, sed, echo, and I/O redirection (especially append with >> ). And lots of temporary files.
Though if you have access to perl (or something similar), you can run it with no arguments and it will let you input a script source from standard input. Once you press ctrl+d, it can then run the script. You could use that method to create a file. It would be more powerful than hacking something on the command line as I mentioned before.
How to Edit File in Linux
If you’re new to the Linux operating system and want to learn some basic points, you’re in the right place. This tutorial is mentioning one of the general beginnings points you should know about.
How to edit a file while using the Linux system is the question that arrives in every beginner’s mind. When executing programs on a system, sometimes we need to modify them in a timely manner. You can perform such tasks through two of the most used editors’ i-e, nano editor, and vim editor.
How To Edit File in Linux Through Nano Editor
Nano editor is a straightforward built-in editor in Linux distributions used to edit files. We don’t need to learn much before using this, it’s simple. All the basic operations with the symbols are mentioned at the bottom of the editor. You can make use of them with the “Control (ctrl)” key. There is no pre-requisite of it or no command to operate this.
To open nano editor, first check its version using command in terminal:
(If it is not installed in your system; type the following command to get it “$ sudo apt install nano”)
Simple type “nano” with the file name that needs to be edited in the editor. For example, there is a file in my system name “testing.txt”, to open it, type:
To edit it, move the cursor where you want to add required text and start typing.
After modification press “ctrl+o” keys to save it:
File modification has been saved successfully. Now, press “ctrl+x” keys to exit the nano editor.
To verify the modification, open the terminal and run cat command with the file name:
How To Edit File in Linux Through Vim Editor
The vim or vi editor is most likely a built-in Linux editor that comes up with multiple modes. Most of the tools contain one mode to edit documents. But when you start working with vim editor, you will get several things like insert, command, line mode and many more.
Before getting started with vim editor, you should know some basic symbols to switch mode:
- “i” for insert mode
- “w” to save file
- “Esc” for normal mode
- “:q” to quit editor without saving
- “:wq” to save updated document and quit editor
To check which version is installed in your system, type in terminal:
Now, type vim with the file name to open it, for example to open “test.txt” file, type:
If there is no “test.txt” file in the system backup, then this command will create a new file of this name.
Edit File: Now to edit the file, press “i”, it will activate insert mode and allow you to add anything in the file.
Save File: Use the following “:wq” operation to save an updated file and quit the vi editor.
Conclusion
Editing a file or document is the most common thing while using any system. Similarly, in the Linux operating system, you might need editing all the time. Linux distributions come with the multiple built-in editing tools i-e, vim, and nano. This article has briefly explained how to edit files using vim editor and nano editor.
About the author
Syeda Wardah Batool
I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.
How to Edit a File in Linux? [SOLVED]
In Linux operating systems, everything is a file. There are daily routine tasks within the system such as turning new features on or off or editing files. An editor is needed for these tasks, regardless of GUI or CLI.
In this article, we will explain how to edit files in Linux operating systems.
Linux users have many alternatives for editing files. Let’s talk about a few applications for both GUI and CLI. At the end you will find the list of alternative apps for you.
Edit Files in GUI using Gedit
The first application we will describe is Gedit . Gedit is a text editor for the GNOME desktop. If you are using your Linux system with Gnome Desktop, your default text editor may already be Gedit. If you are using a different desktop, you may need to install it.
To install on Debian-based systems(Ubuntu, Mint, Pardus, etc), run the following command in terminal:
For installation on Redhat-based OS(Fedora, CentOS, AlmaLinux, Rocky Linux, etc):
$ sudo dnf install gedit.x86_64 -y
There are many plugins for Gedit. You can install the plugin you need from the package repository.
$ sudo dnf search gedit-plugin- Last metadata expiration check: 0:01:40 ago on Sun 12 Feb 2023 10:04:43 +03. ========================= Name Matched: gedit-plugin- ========================== gedit-plugin-bookmarks.x86_64 : gedit bookmarks plugin gedit-plugin-bracketcompletion.x86_64 : gedit bracketcompletion plugin gedit-plugin-charmap.x86_64 : gedit charmap plugin gedit-plugin-codecomment.x86_64 : gedit codecomment plugin gedit-plugin-colorpicker.x86_64 : gedit colorpicker plugin gedit-plugin-colorschemer.x86_64 : gedit colorschemer plugin gedit-plugin-commander.x86_64 : gedit commander plugin gedit-plugin-drawspaces.x86_64 : gedit drawspaces plugin gedit-plugin-editorconfig.x86_64 : EditorConfig plugin for Gedit gedit-plugin-findinfiles.x86_64 : gedit findinfiles plugin gedit-plugin-git.x86_64 : gedit git plugin gedit-plugin-joinlines.x86_64 : gedit joinlines plugin gedit-plugin-multiedit.x86_64 : gedit multiedit plugin gedit-plugin-sessionsaver.x86_64 : gedit sessionsaver plugin gedit-plugin-smartspaces.x86_64 : gedit smartspaces plugin gedit-plugin-synctex.x86_64 : gedit synctex plugin gedit-plugin-terminal.x86_64 : gedit terminal plugin gedit-plugin-textsize.x86_64 : gedit textsize plugin gedit-plugin-translate.x86_64 : gedit translate plugin gedit-plugin-wordcompletion.x86_64 : gedit wordcompletion plugin
After installing you can invoke Gedit in the Applications menu. Or you can open the file by clicking on a file (if it is not the default editor, right click and open with «Open With Other Application» > Gedit).
After this stage, you can start editing your files with pleasure.
Another application you can use to edit text in Linux is Mousepad. Mousepad is a simple text editor for Xfce desktop environment.
To install on Debian-based systems(Ubuntu, Mint, Pardus, etc), run the following command in terminal:
foc@ubuntu22desktop:~$ sudo apt install mousepad -y
For installation on Redhat-based OS(Fedora, CentOS, AlmaLinux, Rocky Linux, etc)
foc@fedora:~$ sudo dnf install mousepad.x86_64 -y
If mousepad is already your default text editor, double-clicking the mouse opens the file with the mousepad. If Mousepad is not the default editor, right-click and select «Open with Other Application» → Mousepad.
Mousepad is a very stable and useful text editor.
Edit Files in CLI
Method-1: Using VIM
Every Linux distribution has a text editor. Built for the end user, Linux OS comes with many text editors installed, while server systems have fewer. But vim/vi is available in almost all Linux distributions.
If for some reason it is not installed, to install it on Debian based systems:
foc@ubuntu22desktop:~$ sudo apt install vim -y
To install on Redhat based systems:
foc@fedora:~$ sudo dnf install vim -y
Type the filename you want to edit after the vim command in the terminal. If the file does not exist before, it will create a new file and display this information on the screen with the word «New».
You can edit the file by pressing the Insert key on the keyboard.
Then press ESC to cancel editing. If you want to save :wq , to exit without saving :q! write the expressions.
Let’s show you a few vim shortcuts:
dd - Delete entire current line q/ - search history in command buffer i - Enter insert mode to the left of the cursor a - Enter insert mode to the right of the cursor
- CTRL+u — Move up by half a page
- CTRL+d — Move down by half a page
- CTRL+b — Move up by a page
- CTRL+f — Move down by a page
Vi/vim is more than just a text editor. Some users use vim as an application development environment. So it has so many features. Check for more shortcut information.
Method-2: Using nano
Nano, on the other hand, is a simpler and plainer text editor. For installation(On Debian based OS):
foc@ubuntu22desktop:~$ sudo apt install nano -y
foc@fedora:~$ sudo dns install nano -y
The file to be edited is typed after the nano command in the terminal. If it doesn’t exist, it is created, if there is, you can start editing.
Here are some nano shortcuts:
Ctrl + X : Exit Ctrl + W: Search Ctrl + K : Cut line Ctrl + U: Paste line
Alternatives
Here are the application alternatives for both GUI and CLI:
Alternatives editor for GUI
- Xed
- Kate/Kwrite
- Sublime Text Editor
- Geany
- Leaf Pad
- Bluefish
- Atom
Alternatives editor for CLI
What is NEXT
Summary
We have shared text editors for both GUI and CLI. Habits are important when choosing a text editor. You can start using one of the text editors that we have shared and explained.
References
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
How to edit a text file in my terminal
I’m using Linux mint and using the vi command to create text files, now that I created a text file and saved it. How do I get back into to edit the text file again?
6 Answers 6
it, will open up a text editor to edit your file.
Here, you can edit your file in the terminal window.
Open the file again using vi. and then press » i » or press insert key ,
and write the following command
Open the file again using vi. and then press the insert button to begin editing it.
could also run ‘vimtutor’ to learn how to use vi/vim. This of course assumes you have vim (vi’s big brother) if you don’t run ‘sudo apt-get install vim’
If you are still inside the vi editor, you might be in a different mode from the one you want. Hit ESC a couple of times (until it rings or flashes) and then «i» to enter INSERT mode or «a» to enter APPEND mode (they are the same, just start before or after current character).
If you are back at the command prompt, make sure you can locate the file, then navigate to that directory and perform the mentioned «vi helloWorld.txt». Once you are in the editor, you’ll need to check the vi reference to know how to perform the editions you want (you may want to google «vi reference» or «vi cheat sheet»).
Once the edition is done, hit ESC again, then type :wq to save your work or :q! to quit without saving.
For quick reference, here you have a text-based cheat sheet.