# 软链接和文件名

shell脚本中获取软链接的方法是 `readlink`

```bash
path="/usr/lib/libxslt.so.1"
readlink -f "$path"
```

则输出为完整的文件路径

```
/usr/lib/libxslt.so.1.1.17
```

如果我们的脚本需要在滤掉目录，只保留文件名，则使用`basename`（对软连接也可使用）

```bash
basename "$path"
```

输出结果就是

```
libxslt.so.1
```

## 参考

* [How to resolve symbolic links in a shell script](https://stackoverflow.com/questions/7665/how-to-resolve-symbolic-links-in-a-shell-script)


---

# 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://huataihuang.gitbook.io/cloud-atlas-draft/develop/shell/bash/softlink_and_filename.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.
