Linux provides its users with a host of utilities to create and edit text files. In this article, we will use both Command line (CLI) and Graphical (GUI) programs to edit text files in Ubuntu (A distribution of Linux).
Using Command line
- Open the terminal either from the search bar or using the right-click menu.
- You can also press (CTRL + ALT + T) to open the terminal.
- Once you have the terminal opened, go to the directory that contains your text files using cd.
- If you have your text files in the ‘docs’ folder, so use cd to the docs directory.
- We will now use cat to create a new text file using cat. ‘tfile.txt’ is the name of the new text file.
- After pressing enter, a blinking cursor appears. We can now write our text to save it in the file.
- After we finish writing, we can press (CTRL + Z) to save the text file and go back to the terminal.
- We can also use the touch command to create an empty text file.
- This will create an empty text file.
- A new empty file tfile2.txt is created in the directory.
- You can see the contents of the text file using the same cat command.
- Now to edit we can use the vi text editor.
- The vi editor opens with the contents of the text file.
- We can insert a new line by going into insert mode, by pressing the ‘i’.
- This will allow editing the contents of the text file.
- After making our required modifications, we can exit the insert mode by pressing the Escape (Esc) key.
- We can also use the ‘nano’ editor or more professional editors such as vim or emacs.
We can open any text file using ‘nano’ in the following way:
- The following nano editor window will open, in which we can move the cursor and edit the text contents.
- After we are done editing, we can save the modifications by pressing (CTRL + O). Nano will provide the option to change the name of the text file. We can then save it by pressing enter.
- We can exit the nano editor by pressing (CTRL + Z).
Using GUI – Programs
Writing text files is generally easier in a GUI based editor, therefore, Ubuntu comes built-in with ‘gedit’, A GUI based text editor.
We can open a text file in ‘gedit’ from the command line using the following command.
- Press enter, the Gedit window will open with the contents of the file.
- After editing, you can save the file using the save button and close the window.
These are some of the basic and easiest ways to edit a file in Linux. We can also download and use different text editors such as vscode and sublime text to create and edit text files.
How do I edit a file in Linux terminal?
- Press the ESC key for normal mode.
- Press i Key for insert mode.
- Press :q! keys to exit from the editor without saving a file.
- Press :wq! Keys to save the updated file and exit from the editor.
- Press :w test. txt to save the file as test. txt.
How do I edit a file in Unix?
What is the Edit command in Linux?
How do I edit a file in vi?
More Linux resources.
|Go to the last line in a file.
|Go to line X in a file.
|Go to the first line in a file.
How can I edit files without VI?
- Using cat as a text editor. Using cat command to create file cat fileName.
- Using touch command. You can also create the file using touch command.
- using ssh and scp commands.
- Using other Programming Language.
How do I edit a file in PuTTy?
- Log on to the Linux machine as “root” with a SSH client such as PuTTy.
- Back up the configuration file you would like to edit in /var/tmp with the command “cp”. For example: # cp /etc/iscan/intscan.ini /var/tmp.
- Edit the file with vim: Open the file in vim with the command “vim”.
How do I edit and save a file in PuTTY?
How do I edit a file in CMD?
How do you write to a file in Unix?
- echo ‘The only winning move is not to play.’ >
- printf ‘The only winning move is not to play.\n’ > demo.txt.
- printf ‘The only winning move is not to play.\n Source: WarGames movie\n’ > demo-1.txt.
- cat > quotes.txt.
- cat quotes.txt.
How do you write to a file in Linux?
What is File command in Linux?
How do I access a file in Terminal?
How do I find a file in Linux terminal?
How do I view a file in Unix?
- cat command.
- less command.
- more command.
- gnome-open command or xdg-open command (generic version) or kde-open command (kde version) – Linux gnome/kde desktop command to open any file.
- open command – OS X specific command to open any file.
How do I find the path to a file?
Ads by Google