English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux ed命令

Linux Command大全

Linux ed命令是文本编辑器,用于文本编辑。

ed是Linux中功能最简单的文本编辑程序,一次仅能编辑一行而非全屏幕方式的操作。

ed命令并不是一个常用的命令,一般使用比较多的是vi 指令。但ed文本编辑器对于编辑大文件或对于在shell脚本程序中进行文本编辑很有用。

语法

ed [-][-Gs][-p<字符串>][--help][--version][文件]

参数

  • -G或--traditional   提供回兼容的功能。

  • -p<字符串>   指定ed在command mode的提示字符。

  • -s,-,--quiet或--silent   不执行开启文件时的检查功能。

  • --help   显示帮助。

  • --version   显示版本信息。

在线示例

以下是一个 Linux ed 完整示例解析:

$ ed              <- Activate ed command 
a                 <- Tell ed to edit a new file 
My name is Titan. <- Enter the first line content 
And I love Perl very much. <- Enter the second line content 
.                 <- Return to the command line state of ed 
i                 <- Tell ed to insert content before the last line 
I am 24-  24, 
.                 <- Return to the command line state of ed 
c                 <- Tell ed to replace the last line of input content 
I am 24 years old. <-  24, 24 years old.”(note: here the last input content is replaced) 
.                 <- Return to the command line state of ed 
w readme.text     <- Rename the file to 'readme.text' and save (note: if editing an existing file, just type 'w' is enough) 
q                 <- Completely exit the ed editor

This is the content of the file:

$ cat readme.text 
My name is Titan. 
I am 24 years old. 
And I love Perl very much.

Linux Command大全