linux 操作系统下ed命令介绍和使用案例
ed
命令介绍
ed
是一个基于命令行的文本编辑器,广泛用于 Unix 和 Linux 系统。它是最早的文本编辑器之一,主要用于处理文本文件。与现代图形界面编辑器不同,ed
不会在屏幕上显示文本,而是直接在命令行中操作文本行。这使得它在脚本和批处理任务中非常高效
基本用法
启动 ed
要启动 ed
,您可以在终端中输入以下命令:
bash
ed [filename]
- 如果指定了文件名,
ed
会加载该文件的内容到缓冲区。 - 如果没有指定文件名,将启动一个空的编辑会话。
命令介绍
root@rke2-24:/data# which ed
/usr/bin/ed
root@rke2-24:/data# ed --help
GNU ed is a line-oriented text editor. It is used to create, display,
modify and otherwise manipulate text files, both interactively and via
shell scripts. A restricted version of ed, red, can only edit files in
the current directory and cannot execute shell commands. Ed is the
'standard' text editor in the sense that it is the original editor for
Unix, and thus widely available. For most purposes, however, it is
superseded by full-screen editors such as GNU Emacs or GNU Moe.
Usage: ed [options] [file]
Options:
-h, --help display this help and exit
-V, --version output version information and exit
-E, --extended-regexp use extended regular expressions
-G, --traditional run in compatibility mode
-l, --loose-exit-status exit with 0 status even if a command fails
-p, --prompt=STRING use STRING as an interactive prompt
-r, --restricted run in restricted mode
-s, --quiet, --silent suppress diagnostics, byte counts and '!' prompt
-v, --verbose be verbose; equivalent to the 'H' command
--strip-trailing-cr strip carriage returns at end of text lines
Start edit by reading in 'file' if given.
If 'file' begins with a '!', read output of shell command.
Exit status: 0 for a normal exit, 1 for environmental problems (file
not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or
invalid input file, 3 for an internal consistency error (e.g., bug) which
caused ed to panic.
Report bugs to [email protected]
Ed home page: http://www.gnu.org/software/ed/ed.html
General help using GNU software: http://www.gnu.org/gethelp
root@rke2-24:/data# ed
使用案例
root@rke2-24:/data# ed meng.txt
meng.txt: No such file or directory
a
b
c
.
w
4
q
$ ed meng.txt # 打开或创建 meng.txt
a # 进入添加模式
b # 输入文本 b
c # 输入文本 c
. # 结束添加模式
w # 保存更改到 meng.txt
q # 退出 ed 编辑器
标签:txt,操作系统,--,ed,exit,file,linux,meng
From: https://blog.csdn.net/lisanmengmeng/article/details/143380586