在 Ubuntu 里“文件搜索”一般分几种场景,下面按最常用 → 进阶给你讲清楚。
适合:普通用户、桌面使用
find(最常用、最强大)find /路径 -name "文件名"
例子:
find ~ -name "test.txt"
find /home -name "*.py"
忽略大小写:
find . -iname "readme*"
按类型:
find . -type f # 文件
find . -type d # 目录
locate(最快,但需更新索引)sudo apt install mlocate
sudo updatedb
locate nginx.conf
优点:快
缺点:不是实时
grep(搜文件内容)grep -r "关键词" /路径
例子:
grep -rn "main" ./src
fzf(交互式搜索)sudo apt install fzf
fd(更人性化的 find)sudo apt install fd-find
fd "config"
| 需求 | 推荐命令 |
|---|---|
| 按文件名 | find / locate |
| 按内容 | grep |
| 快速模糊 | fzf / fd |
| 桌面用户 | 文件管理器 |
如果你愿意,可以告诉我:
我可以直接给你一条最合适你的命令。