ed command in Linux with examples

ed command in Linux is used for launching the ed text editor which is a line-based text editor with a minimal interface which makes it less complex for working on text files i.e creating, editing, displaying and manipulating files. It is the oldest editor built in the Unix. It is succeeded by vi and emacs text editor.

Syntax:

ed [options] [file]

ed command without any option: It will launch the ed editor with an empty buffer for us to write, this is similar to the other visual or command line based editor when invoked without a filename. The simplest way to start the ed text editor is by typing “ed” into the terminal.



Example 1:

Here we have not specified the filename so this will create an empty buffer for us to write.

Example 2: To Enter into insert mode press “a” and when you are done writing stop it by “.” (dot).

Example 3: To view, the last line enter “p” into the ed command prompt.

Example 4: To print all the lines that we inserted in the buffer by using “, p”.

Example 5: To save these lines into a file write “f [filename]”.


Example 6: Type “w” in ed command prompt to write the data into the file and see how many bytes are written.

Example 7: The file now has data and we can exit to the terminal by pressing “Q” at ed command prompt.



My Personal Notes arrow_drop_up

Final Year Student Programming Enthusiast

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.