开发者

Chopping out last field of the output of find?

开发者 https://www.devze.com 2022-12-15 05:50 出处:网络
How can I chop out the text, returned by find, after the last \"/\" ? $ find home/a/misc/ -type f home/a/misc/6

How can I chop out the text, returned by find, after the last "/" ?

$ find home/a/misc/ -type f
home/a/misc/6
home/a/misc/5
home/a/misc/2

I can do it by piping cut -d"/" f4 to the find command but problem is that the folder misc 开发者_开发技巧folder is not always there in folder a. It can be in like /home/a/b/c/d/e/. In that case it will return the element in folder c

Edit: 6, 5 and 2 are files, not directories.

Solved

using -printf %f with the find command did the magic. Thanks to all of you


basename will do the trick:

$ basename foo/bar
bar
$ find . -type f
./bar/quux/file
./foo/bar
./foo/baz
$ find . -type f -exec basename {} \;
file
bar
baz


You can use basename or dirname

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号