如何只获得文件名与Linux`发现`? [英] How to only get file name with linux `find`?

查看:132
本文介绍了如何只获得文件名与Linux`发现`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用查找目录中的所有文件,所以我得到一个路径列表。不过,我只需要文件名。即我得到 ./ dir1 / dir2 / file.txt ,我想得到 file.txt

解决方案在GNU find 中,可以使用 -printf <
$ b

  find / dir1 -type f -printf%f \ n 


I'm using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get ./dir1/dir2/file.txt and I want to get file.txt

解决方案

In GNU find you can use -printf parameter for that, e.g.:

find /dir1 -type f -printf "%f\n"

这篇关于如何只获得文件名与Linux`发现`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆