# fc

修改历史命令并执行

## 补充说明

**fc命令** 自动掉用vi编辑器修改已有历史命令，当保存时立即执行修改后的命令，也可以用来显示历史命令。fc命令编辑历史命令时，会自动调用vi编辑器。fc保存文件后，会自动执行所编辑过的命令。

### 语法

```
fc [-e 编辑器名] [-lnr] [起始] [终结]
fc -s [模式=替换串] [命令]
```

### 选项

```
-l：显示历史命令；
-n：显示历史命令时，不显示编号；
-r：反序显示历史命令。
```

### 参数

* 起始指令编号：指定要编辑的起始指令编号；
* 结尾指令编号：指定要编辑的结尾指令编号。

### 实例

使用该指令显示最近使用的10条历史命令，输入如下命令：

```
[root@localhost ~]# fc -l -10     #显示10条历史命令
1039     type -a grep
1040     export
1041     history 10
1042     ulimit -a
1043     shopt
1044     help ls
1045     help env
1046     help short
1047     help shopt
1048     showkey -a
```

第一列信息是历史命令的编号，第二列信息是历史命令的具体格式。若用户需要编辑第1040条历史命令时，则输入如下命令：

```
fc 1040                    #编辑第1040条历史命令
```

命令执行成功后，将自动调用vi编辑器编辑指定的命令，编辑完成后保存，会自动执行修改后的命令。当用户在vi编辑器中修改指令并保存后，被修改的命令会被自动调用并执行。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hezhiqiang.gitbook.io/linux/ming-ling/fc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
