How to open and edit files in Linux

You can open/edit file in Linux using vi editor
Syntax:

  • vi [options] <file name or path to file> then press ‘i’ to open in insert[edit] mode

Examples:

  • vi file1
  • vi /tmp/file2
open/edit/close file in linux
To close opened file, follow below commands of vi editor:
  • To save file, type:
    • :wq<Enter Key>
  • To save file forcefully, type:
    • :wq!<Enter Key>
  • To close file without saving, type:
    • :q<Enter Key>
  • To close file forcefully, type:
    • :q!<Enter Key>
open/edit/close file in linux

Note: If you are in insert mode and want to close file, then press Esc key first.

You may want to see
How to sort contents of a file

The sort command is used to sort the contents of a file. You can sort the data in a text Read more

How to use sed command in Linux

sed, short for "stream editor", allows you to filter and transform text. A stream editor is used to perform basic Read more

How to use crontab in Linux

Cron is the system process that will automatically perform tasks for you according to a set schedule. The schedule is Read more

How to extract archive file in Linux

To extract archive file in Linux, you can use the tar command, used for extracting content from the archive files. "tar" Read more

Leave a Reply

Your email address will not be published. Required fields are marked *