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
复制代码

 

posted @   小鲨鱼2018  阅读(2449)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!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命令实现保留指定小数位数
点击右上角即可分享
微信分享提示