How to edit a text file in my terminal
LinuxTerminalText FilesLinux Problem Overview
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?
vi helloWorld.txt
Linux Solutions
Solution 1 - Linux
Try this command:
sudo gedit helloWorld.txt
it, will open up a text editor to edit your file.
OR
sudo nano helloWorld.txt
Here, you can edit your file in the terminal window.
Solution 2 - Linux
Open the file again using vi. and then press " i " or press insert key ,
For save and quit
Enter Esc
and write the following command
:wq
without save and quit
:q!
Solution 3 - Linux
Open the file again using vi. and then press the insert button to begin editing it.
Solution 4 - Linux
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.
Solution 5 - Linux
You can open the file again using vi helloworld.txt
and then use cat /path/your_file
to view it.
Solution 6 - Linux
you doesn't have root access type this
sudo su
If you want to use nano editor to create file in same directory where you headed
nano filename.format
eg:- nano attendaence.txt
-
Ctrl+o
-
Enter
-
Ctrl+x
If you want to use nano editor to create file in other directory where you headed
-
nano location/filename.txt
eg1:- nano home/ec2-user/public_html/attendence.php
eg2:- nano /home/ec2-user/public_html/attendence.php
2. Ctrl+o
-
`Enter`
-
`Ctrl+x`
Create file without editor in same directory
touch filename.format
eg:- touch helloworld.html
Create file without editor in another directory
touch location/filename.format
eg:- touch var/www/index.html