# 6. 文件属性与权限操作

当前目录执行 `ls -lrti`

```
2495523 -rw-r--r--  1 root  root  65 12月 23 15:14 boot.log
```

1. i节点    :文件id     一个文件对应一个i节点   一个i节点可以对应多个文件
2. 文件类型与权限
3. 文件连接到此节点数量(不包括软链接)
4. 文件所有者
5. 文件所有组
6. 容量大小(B)
7. 最后修改时间
8. 文件名

## 链接

### 软连接

类似于win下的程序快捷方式

* 指令:ln -s 目标文件(绝对路径) 目标路径(绝对路径))
* 更改会同步到源文件
* i节点与源文件不同
* 删除源文件后,软连接失效

### 硬链接

* 指令:ln 目标文件(绝对路径) 目标路径(绝对路径))
* 更改会同步到源文件
* i节点与源文件相同
* 删除源文件后硬链接依旧可以使用(相互备份,防止源文件被误删)

## 文件类型判断

* 第一个符号
  * `-` :文件
  * `d` :目录
  * `l` :软链接
  * `b` :块设备
  * `c` :硬件设备
* 2-4字符 所属者权限
  * `r` :读权限  4
  * `w` :写权限  2
  * `x` :执行权限1
* 5-7字符 所属组权限
  * `r` :读权限 &#x20;
  * `w` :写权限 &#x20;
  * `x` :执行权限
* 8-10 字符 其它人的权限

## 修改文件权限命令 `chmod`

### 增加权限

```
chmod u+x,g+w,o test.txt

# 赋予所有权限
chmod 777 test.txt

# 递归赋予权限
chmod -R 777 test.txt
```

### 删除权限

```
chmod u-x,g-w,o test.txt
```

### 修改用户组权限chown

```
chown [user][:[group]] filname
```


---

# 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/attr-power.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.
