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?

How to edit files in Linux
  1. Press the ESC key for normal mode.
  2. Press i Key for insert mode.
  3. Press :q! keys to exit from the editor without saving a file.
  4. Press :wq! Keys to save the updated file and exit from the editor.
  5. Press :w test. txt to save the file as test. txt.

How do I edit a file in Unix?

To open a file in the vi editor to start editing, simply type in ‘vi <filename>’ in the command prompt. To quit vi, type one of the following commands in the command mode and press ‘Enter’. Force exit from vi even though changes haven’t been saved – :q!

What is the Edit command in Linux?

edit FILENAME. edit makes a copy of the file FILENAME which you can then edit. It first tells you how many lines and characters are in the file. If the file does not exist, edit tells you it is a [New File]. The edit command prompt is a colon (:), which is shown after starting the editor.

How do I edit a file in vi?

To enter Insert mode, press i . In Insert mode, you can enter text, use the Enter key to go to a new line, use the arrow keys to navigate text, and use vi as a free-form text editor.

More Linux resources.

Command Purpose
G Go to the last line in a file.
XG Go to line X in a file.
gg Go to the first line in a file.
20 août 2019

How can I edit files without VI?

How to Edit File without vi/vim Editor in Linux?
  1. Using cat as a text editor. Using cat command to create file cat fileName.
  2. Using touch command. You can also create the file using touch command.
  3. using ssh and scp commands.
  4. Using other Programming Language.

How do I edit a file in PuTTy?

To modify the configuration files:
  1. Log on to the Linux machine as “root” with a SSH client such as PuTTy.
  2. 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.
  3. Edit the file with vim: Open the file in vim with the command “vim”.

How do I edit and save a file in PuTTY?

By typing Ctrl+X nano exits and if your file needs change you will be prompted to save the changes in which case to save you should press Y and then enter to save changes in the same file you open. If you are not using any gui and you just want to leave the shell the command is Ctrl+D.

How do I edit a file in CMD?

If you want to edit files in the command prompt, you can get the Windows version of Nano. As a side note, those little ^ signs at the bottom of the window are supposed to represent the Ctrl button. For instance, ^X Exit means that you can exit the program using Ctrl – X .

How do you write to a file in Unix?

Open the Terminal and then type the following command to create a file called demo.txt, enter:
  1. echo ‘The only winning move is not to play.’ >
  2. printf ‘The only winning move is not to play.\n’ > demo.txt.
  3. printf ‘The only winning move is not to play.\n Source: WarGames movie\n’ > demo-1.txt.
  4. cat > quotes.txt.
  5. cat quotes.txt.

How do you write to a file in Linux?

To create a new file, use the cat command followed by the redirection operator ( > ) and the name of the file you want to create. Press Enter , type the text and once you are done, press the CRTL+D to save the file. If a file named file1. txt is present, it will be overwritten.

What is File command in Linux?

file command is used to determine the type of a file. .file type may be of human-readable(e.g. ‘ASCII text’) or MIME type(e.g. ‘text/plain; charset=us-ascii’). This command tests each argument in an attempt to categorize it. The program verifies that if the file is empty, or if it’s some sort of special file.

How do I access a file in Terminal?

Type ls into Terminal and hit Enter. ls stands for “list files” and will list all the files in your current directory. Next type pwd to find our where you are within your computer.

How do I find a file in Linux terminal?

Crack open a terminal window and navigate to a directory containing one or more text files that you want to view. Then run the command less filename , where filename is the name of the file you want to view.

How do I view a file in Unix?

Linux And Unix Command To View File
  1. cat command.
  2. less command.
  3. more command.
  4. gnome-open command or xdg-open command (generic version) or kde-open command (kde version) – Linux gnome/kde desktop command to open any file.
  5. open command – OS X specific command to open any file.

How do I find the path to a file?

To view the full path of an individual file: Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document.