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
精彩评论