# 1.常用命令

## 基础部分

### 切换目录 cd

* 格式:`cd` 目标目录
* 返回上一级: `cd` ../或 `cd` ..

### 列出当前目录的子目录与文件 ls

* 列出当前目录所有内容: `ls`&#x20;
* 详细列出当前子目录与文件:`ls` -l
* 列出的数据按照时间排序显示(降序)):`ls` -lt
* 按时间升序展示:`ls` -ltr
* 列出指定子目录:`ls` ./dir &#x20;
* 详细列出指定子目录:`ls` -l ./dir

### 查看当前目录 pwd

* 显示当前目录的绝对路径: `pwd`&#x20;

### 查看目标文件绝对路径 readlink

* readlink -f targetFilename

### 查看小文件内容 cat

* 查看小文件:`cat` 123.txt

### 查看大文件内容 more

* 查看大文件: `more` 345.txt

### 按行数查看文件(从前向后) head

* 默认查看前10行:`head` filename
* 查看前n行:`head` n filename

### 按行数查看文件(从后向前) tail

* 默认查看后10行:`tail` filename
* 查看后n 行:`tail` n filename
* 监视动态文件变更内容:`tail` -f log.txt

### 文件创建 touch

* 创建一个新的空文件:`touch` empty.txt
* 同时创建多个文件: `touch` 1.txt 2.txt
* 更新文件时间戳：`touch` -t 201811111420.55 1.txt

### 文件夹创建 mkdir

* 创建一级文件夹：`mkdir` test
* 创建多级文件夹：`mkdir` -p test1/test2/test3

### 文件夹删除　rmdir

* 删除空文件夹：`rmdir`　emptyDir&#x20;

### 文件删除 rm

* 删除目标文件：`rm` 123.txt
* 强制删除文件：`rm` -rf 123.txt
* 强制删除目录：`rm` -rf dir

### 文件拷贝　cp

* 拷贝文件到其他目录：`cp` 1.txt other
* 拷贝文件并改名称：`cp` 1.txt other/2.txt
* 拷贝一份完全一致的文件(包括旧文件的属性)：`cp` -a other/2.txt

### 文件移动 mv

* 移动文件：`mv` newDirectory
* 重命名文件:`mv` a.txt b.txt

### 对比文件差异　diff

* 对比文件差异: `diff` 1.txt 2.txt

### 切换主机　sh

* 切换主机：`ssh` ip
  * exit　退出

### 查看当前用户　id

### 查看系统信息

* 查看系统信息：`uname`
* 查看系统详细信息：`uname`　-a

### 网络检测　ping

* 检查网络是否通畅：`ping` ip

### 标注输出 echo

* `echo` "hello world"&#x20;

### 命令文档查看　man

* 查看制定命令文档：`man` command
  * `man` ls
  * 按 q 退出


---

# 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://sugar-at.gitbook.io/blog-article/linux/part1.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.
