# 判断文件是否为空

我们知道在脚本中用 `-z` 可以判断字符串是否为空，那么对于文件来说，该怎么判断是否为空呢？

bash也提供了一个 `-s` 来判断文件是否为空，注意，当文件中 **有内容** 时候为 **真**

```bash
[ -s file.name ] || echo "file is empty"
```

## 参考

* [How to check if a file is empty in Bash?](https://stackoverflow.com/questions/9964823/how-to-check-if-a-file-is-empty-in-bash)


---

# 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/check_file_empty.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.
