# cat: 连接

`cat`输出文件内容，到标准输出或另一个文件里面。

### **实例1：查看单个文件**

```bash
cat filename
```

这会打印文件所有的内容到屏幕上。

### **实例2：查看多个文件**

```bash
cat file1 file2
```

将打印多个文件。

### **实例3：输出行号**

```bash
cat -n filename
```

不但打印出文件内容，还会在每行前面打印行号。

### **实例4：新建一个文件**

```bash
cat > newfile
```

这样会新建一个文件，这个时候输入的内容就会写入文件，然后Ctrl+c退出。

### **实例5：复制文件**

```bash
cat src-filename > dest-filename
```

这会把`src-filename`复制到新的`dest-filename`中。

### **实例6：压缩空行**

```bash
cat -s filename
```

如果文件中有空行，会对其进行压缩（连续多个空行只输出一行）。

### **实例7：添加内容**

```bash
cat src-filename >> desc-filename
```

这会把`src-filename`的内容添加到`desc-filename`文件的末尾。

### **实例8：文件拼接**

根据7可以实现多个文件的拼接：

```bash
cat file1 file2 file3 ... filen >> file
```


---

# 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://valineliu.gitbook.io/deuterium-wiki/linux/cmd/cat-lian-jie.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.
