On Unix-like operating systems, the ex command is a text editor, and the line-editor mode of vi. It is the basis of vim, a popular text editor around the world. ex was written by Bill Joy in 1976, based on an earlier program written by Charles Haley.

Description

“ex” stands for extended, because it was originally an extension of the simple line editor ed. Similarly, “vi” stands for visual, because vi is the “visual” (full-screen) editing mode, which was eventually added to ex.

  • Description
  • Syntax
  • Examples
  • Related commands
  • Linux commands help

The commands ex and vi point to the same program, started in different modes. You can start ex by running vi -e, or you can start vi by running ex -v. Additionally, from within ex, you can start vi with the visual command (or vi for short). From inside vi, you can start ex with the command Q.

If you are familiar with vi, you can think of the ex command prompt as being the same as vi’s command prompt after you type a colon (":"). For instance, the ex command “w” writes your changes to disk, as “:w” writes changes to disk in vi.

For more in-depth information about using a line editor, see our documentation of ed, which contains extensive examples and a tutorial.

Syntax

ex [ -| -s ] [ -l ] [ -L ] [ -R ] [ -r [ file ] ] [ -t tag ] [ -v ] [ -V ] [ -x ] [ -wn ] [ -C ] [ +command | -c command ] file

Options

Examples

ex myfile.txt

Edits the file myfile.txt.

ed — A simple text editor.edit — A text editor.grep — Filter text which matches a regular expression.sed — A utility for filtering and transforming text.sort — Sort the lines in a text file.vi — Text editor based on the visual mode of ex.vim — An advanced version of vi.