Linux command
ex 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Start ex mode on a file
ex [file.txt]
Execute a substitution command and quit
ex -c "%s/[old]/[new]/g" -c "wq" [file.txt]
Open a file in read-only mode
ex -R [file.txt]
Edit multiple files sequentially
ex [file1.txt] [file2.txt]
说明
ex is a line-oriented text editor. It provides command-line editing without a visual interface, using the same command language that powers vi's colon (:) commands. Commands are entered at a prompt rather than in a full-screen display. ex is particularly valuable for batch editing and scripted file modifications, allowing search/replace and other transformations without interactive use. When combined with -s for silent mode, it can process editing commands from stdin or scripts. The ex and vi editors are the same program started in different modes. Running ex -v starts visual mode (vi), and running vi -e starts line mode (ex).
参数
- -c _COMMAND_
- Execute command after loading the first file.
- -s
- Silent (batch) mode. Suppress all interactive feedback. Useful for scripting.
- -R
- Read-only mode. Prevents writing to the file.
- -r _FILE_
- Recover editing session from a swap file after a crash.
- -n
- Do not use a swap file (vim implementation).
- -t _TAG_
- Edit the file containing the specified tag.
- -V
- Verbose mode. Show commands read from stdin.
- -v
- Start in visual mode (equivalent to running vi).
FAQ
What is the ex command used for?
ex is a line-oriented text editor. It provides command-line editing without a visual interface, using the same command language that powers vi's colon (:) commands. Commands are entered at a prompt rather than in a full-screen display. ex is particularly valuable for batch editing and scripted file modifications, allowing search/replace and other transformations without interactive use. When combined with -s for silent mode, it can process editing commands from stdin or scripts. The ex and vi editors are the same program started in different modes. Running ex -v starts visual mode (vi), and running vi -e starts line mode (ex).
How do I run a basic ex example?
Run `ex [file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c _COMMAND_ do in ex?
Execute command after loading the first file.