linux 中find命令查找到文件仅显示文件名、路径名、完整路径
001、
[root@PC1 test3]# ls test1 test2 [root@PC1 test3]# tree ## 测试数据 . ├── test1 │ └── a.txt └── test2 └── b.txt 2 directories, 2 files [root@PC1 test3]# find ./ -name "*.txt" ## 一般显示模式 ./test1/a.txt ./test2/b.txt
002、仅显示文件名
[root@PC1 test3]# ls test1 test2 [root@PC1 test3]# tree . ├── test1 │ └── a.txt └── test2 └── b.txt 2 directories, 2 files [root@PC1 test3]# find ./ -name "*.txt" ./test1/a.txt ./test2/b.txt [root@PC1 test3]# find ./ -name "*.txt" -exec basename {} \; ## 仅显示文件名 a.txt b.txt [root@PC1 test3]# find ./ -name "*.txt" | xargs -i basename {} a.txt b.txt
003、显示绝对路径
[root@PC1 test3]# ls test1 test2 [root@PC1 test3]# tree . ├── test1 │ └── a.txt └── test2 └── b.txt 2 directories, 2 files [root@PC1 test3]# find ./ -name "*.txt" ./test1/a.txt ./test2/b.txt [root@PC1 test3]# find ./ -name "*.txt" -exec readlink -f {} \; ## 显示绝对路径 /home/test3/test3/test1/a.txt /home/test3/test3/test2/b.txt [root@PC1 test3]# find ./ -name "*.txt" | xargs -i readlink -f {} ## 显示绝对路径 /home/test3/test3/test1/a.txt /home/test3/test3/test2/b.txt
004、进显示路径
[root@PC1 test3]# ls test1 test2 [root@PC1 test3]# tree . ├── test1 │ └── a.txt └── test2 └── b.txt 2 directories, 2 files [root@PC1 test3]# find ./ -name "*.txt" ./test1/a.txt ./test2/b.txt ## 仅显示路径 [root@PC1 test3]# find ./ -name "*.txt" -exec readlink -f {} \; | xargs -i dirname {} /home/test3/test3/test1 /home/test3/test3/test2
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-05-30 redhat9中配置静态IP(nmtui命令)
2022-05-30 redhat8中配置yum仓库
2022-05-30 redhat8基于vmware软件图形界面配置IP
2022-05-30 redhat8中使用nmtui命令图形界面配置网络IP
2022-05-30 redhat8如何配置静态IP
2022-05-30 linux中awk命令实现科学计数法和普通数值的相互转换
2022-05-30 linux中awk命令实现保留指定小数位数