Linux – How to get only names from find command without path

linuxshell

I am trying to get only the names from the search result using find, but it always includes the directories too. How can I print only the names (or assign to a variable) using find

find trunk/messages/ -name "*.po" -printf '%f\n'

a similar command to assign this to a variable e.g. "resource" to use it later on.

EDIT: And if possible only the name excluding the extension.

Best Answer

Use find trunk/messages/ -name "*.po" -exec basename {} .po \;

Example and explanations:

Create some test files:

$ touch test1.po  
$ touch test2.po  
$ find . -name "*.po" -print
./test1.po  
./test2.po

Ok, files get found, including path.

For each result execute basename, and strip the .po part of the name

$ find . -name "*.po" -exec basename \{} .po \;  
test1  
test2
Related Question