📜  vi 编辑器和 cat 命令的区别

📅  最后修改于: 2021-09-10 03:12:27             🧑  作者: Mango

vi 编辑器和 cat 命令都用于在文件中输入内容。

1. vi 编辑器:
vi 编辑器代表可视化编辑器,它是 UNIX 操作系统中的一种智能编辑工具,用于读取、创建文件、编辑它们等。它是 UNIX 中的默认编辑工具。

打开特定文件的命令:

vi filename

它具有三种模式:

  1. 命令模式: vi 编辑器始终在此模式下打开。这是接受所有命令的地方。
  2. 插入/输入模式:文件以输入模式打开,文件内容在此处写入或编辑。
  3. 执行模式:执行模式由命令模式中的’:’命令调用。然后命令被读入命令模式。

下图解释了从另一个模式访问每种模式的方式。

从彼此访问每种模式的方法

2. cat 命令:
cat 命令代表连接。它还用于创建新文件、读取和更新现有文件。它们还用于将多个文件连接在一起或将一个文件的内容复制到另一个文件中。

cat 命令示例:

  • 创建和添加一些内容到文件中。
    cat > newfile
    This is a new file that is not empty.
  • 读取或显示现有文件的内容。
    cat newfile
  • 将两个文件合并为一个新文件。
    cat file1 file2 >> file3

    还有很多其他命令使用 cat。但是,它们的使用都有一定的限制。

vi 编辑器和 cat 命令的区别:

S.NO. vi editor cat command
1. vi editor opens an editor tool to work. It works on the dollar prompt itself.
2. vi editor works in three modes – command, insertion, execution mode. There is no concept of modes in the cat command.
3. Using a vi editor, the contents of the file can be edited throughout the file. Using a cat command, the contents of a file cannot be edited. Only more lines could be added or the content of the file can be completely replaced.
4. There are several commands (i, I, o, O, a, A, r, R, s, S) to get to the insertion mode which decides the location of the cursor in the file. This helps in editing the file from wherever the user wants. There are no commands to decide the location of the cursor inside the file. It always gives the option to edit from the location of last insertion.
5. Copying the contents a file is done manually using the yy command. First the contents of a file are copied and then inserted in the new one. Copying the contents a file is very handy. It can be done with one simple instruction using the command :
cat file1 > file2
6. Contents of multiple files cannot be copied at a time. Contents of multiple files can be copied at a time.
7. A file can be merged but only with the one being currently edited. Merging multiple files is easy and can be done through a single command.
8. In case the system crashes, vi editor let’s one save versions of the file. There is no scope for saving files that can be edited later.