2024年5月10日发(作者:)
`find` 是 Linux 中一个非常强大的命令,用于在指定目录下
查找文件或目录。它的基本语法如下:
```
find [path] [expression]
```
其中,`path` 表示要查找的目录路径,可以是相对路径或绝
对路径;`expression` 表示查找的条件,可以是文件名、文件
类型、文件大小、修改时间等等。
下面是一些常用的 `find` 命令用法:
1. 查找指定文件名的文件:
```
find /path/to/dir -name filename
```
2. 查找指定文件类型的文件:
```
find /path/to/dir -type f -name "*.txt"
```
3. 查找指定目录下的所有文件:
```
find /path/to/dir -type f
```
4. 查找指定目录下的所有目录:
```
find /path/to/dir -type d
```
5. 查找指定目录下的所有空文件夹:
```
find /path/to/dir -type d -empty
```
6. 查找指定目录下的所有大于指定大小的文件:
```
find /path/to/dir -type f -size +10M
```
7. 查找指定目录下的所有小于指定大小的文件:
```
find /path/to/dir -type f -size -10M
```
8. 查找指定目录下的所有最近修改时间在指定时间之前的
文件:
```
find /path/to/dir -type f -mtime +7
```
9. 查找指定目录下的所有最近修改时间在指定时间之后的
文件:
```
find /path/to/dir -type f -mtime -7
```
以上是 `find` 命令的一些常用用法,还有很多其他的用法,
可以通过 `man find` 命令查看 `find` 命令的帮助文档来了
解更多。


发布评论