在 Linux 中查找特定文件,常用的方法有以下几种,按使用频率从高到低介绍:
find 命令(最常用、最强大)根据文件名、类型、大小、时间等条件查找。
find /path -name "filename"
示例:在 /home 下查找名为 test.txt 的文件
find /home -name "test.txt"
find /home -iname "test.txt"
find /home -name "*.log"
find /home -type f # 普通文件
find /home -type d # 目录
find /home -size +100M # 大于100M
find /home -size -10k # 小于10k
locate 命令(最快,但非实时)基于数据库查找,速度快。
locate filename
⚠️ 如果找不到新文件,先更新数据库:
sudo updatedb
grep(查找文件内容,不是文件名)如果你想找包含某内容的文件:
grep -r "关键词" /path
which / whereis(找命令文件)which python
whereis python
.conf 文件:find / -name "*.conf" 2>/dev/null
find /home -mtime -7
如果你能说明:
我可以给你更精确的命令。