如何仅使用 Linux 'find' 获取文件名? [英] How to only get file name with Linux 'find'?

查看:40
本文介绍了如何仅使用 Linux 'find' 获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对目录中的所有文件使用 find,所以我得到了一个路径列表.但是,我只需要文件名.即我得到 ./dir1/dir2/file.txt 并且我想得到 file.txt

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

推荐答案

在 GNU find 中你可以使用 -printf 参数,例如:

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

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

这篇关于如何仅使用 Linux 'find' 获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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