How to edit a text file in my terminal

LinuxTerminalText Files

Linux 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

  1. nano filename.format

eg:- nano attendaence.txt

  1. Ctrl+o

  2. Enter
    
  3. Ctrl+x
    

If you want to use nano editor to create file in other directory where you headed

  1. 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

  1. `Enter`
    
  2. `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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMad_ Questionnaire View Question on Stackoverflow
Solution 1 - LinuxGaurav DaveView Answer on Stackoverflow
Solution 2 - LinuxNadeem QasmiView Answer on Stackoverflow
Solution 3 - LinuxArpit AggarwalView Answer on Stackoverflow
Solution 4 - LinuxmanuelvigarciaView Answer on Stackoverflow
Solution 5 - LinuxSaransh JainView Answer on Stackoverflow
Solution 6 - LinuxRonny DsouzaView Answer on Stackoverflow