首页 > 系统相关 >linux 中find命令查找到文件仅显示文件名、路径名、完整路径

linux 中find命令查找到文件仅显示文件名、路径名、完整路径

时间:2023-05-30 16:58:13浏览次数:42  
标签:test1 test3 test2 PC1 路径名 linux txt root 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

 

标签:test1,test3,test2,PC1,路径名,linux,txt,root,find
From: https://www.cnblogs.com/liujiaxin2018/p/17443697.html

相关文章

  • linux while、until、break、continue
    目录一、总结二、实验演示          一、总结forwhileuntilfor主要用于已知循环次数while条件满足才执行循环,不满足就退出循环,在绝大多数情况,while和for可以通用,while更好用死循环unti条件不满足才能循环,满足条件退出,一般不用循环控制语句:continue:......
  • windows web服务器代码移植到linux所采的坑
    windowsweb服务器代码移植到linux所采的坑一、导入问题不能直接将编译后的class文件放入linux服务器中,虽说java是跨平台性好,但是windows下的class文件是不能在linux下直接运行的.二、编译问题1.编码问题在linux端编译代码时,最先遇到的就是编码问题,默认是按ACSII码编译的,不行......
  • Linux 07 while case 计划任务
    `命令`==$(命令),两种语句格式效果相同,都执行其中的命令,只返回执行结果。while循环语句#!/bin/bash#haha.shPRICE=$(expr$RANDOM%1000)TIMES=0whiletruedo read-p"Enter:"HAHA letTIMES++ if[$HAHA-eq$PRICE] then echo"congratulations!$TIMES......
  • linux之软链接
     实现以上效果需要前提1.server不要存在,先删除掉2.创建软连接ln-s绝对路径 单词   (在当前目录下执行)看命令rm-rfserver;ln-s/a/b/c/d/classes/server  (在当前目录下运行)......
  • nacos服务下线操作时报错:The Raft Group [naming_instance_metadata] did not find th
    【问题描述】caused:errCode:500,errMsg:dometadataoperationfailed;caused:com.alibaba.nacos.consistency.exception.ConsistencyException:TheRaftGroup[naming_instance_metadata]didnotfindtheLeadernode;caused:TheRaftGroup[naming_instance_metad......
  • Linux(Ubuntu)下设置开机自启shell脚本执行Java程序jar包
    Linux(Ubuntu)下设置开机自启shell脚本执行Java程序jar包 原创软件测试日常记录2023-01-1907:19:29博主文章分类:ubuntu©著作权文章标签ubuntujarlinuxJAVAjava文章分类运维阅读数122 经常需要在Linux服务器上设置开机启动jar包,首先编写一个启动jar包的脚本,这里以/......
  • linux Centos7 部署 nodejs服务
    nodejs服务要有nodejs环境。所以要先安装nodejs不会安装的可以看  Centos7安装npm学习 安装pm2cnpminstallpm2-g,查看pm2是否安装成功pm2-v,如果报错,升级node版本进入node项目目录,安装项目依赖 cnpminstall创建pm2任务 [root@localhostserver]#pm2sta......
  • Linux系统中常见的远程管理协议!
    只要提到远程管理,一般都是指远程管理服务器,而远程管理实际上就是计算机之间通过网络进行数据传输的过程,与浏览器需要HTTP协议浏览网页一个道理,那么Linux系统中常见的远程管理协议都有哪些呢?以下是详细的内容:1、RFBRFB(RemoteFrameBufferProtocol)是一种用于远程......
  • Linux下批量重命名技巧(批量重命名linux)
    Linux下批量重命名技巧(批量重命名linux)Linux批量重命名技巧在Linux系统中是非常有用的,它允许用户一次更改多个文件名称。它可以提供用户更快捷、更有效地处理文件。Linux中提供了一些命令来帮助用户快速实现批量重命名。1.mv命令mv命令是一个用来重命令的常用命令。它......
  • linux - 配置自启动服务
    一般来说,按照下面方式配置即可在下面文件添加需要的指令vi/etc/rc.local 保存继续下面的指令授权chmod+x/etc/rc.local启动服务【用于检查是否正常】systemctl startrc-local.service查看状态【用于检查是否正常】systemctlstatusrc-local.service开启自启动服务......