13
3
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.
@Hennes What is the purpose of backslash before the opening curly brace in the last
find
? – Utku – 2017-10-31T02:10:17.763Great thanks :). Can I strip only the PO extension from dirs?
I mean: dir1/po1.po and dir2/po2.po can they be got like dir1/po1 and dir2/po2? – wakeup – 2013-03-02T14:47:07.937
@user1754665
find . -name '*.po' -exec bash -c 'echo ${0%.po}' {} \;
– slhck – 2013-03-02T14:50:17.493@slhck thanks. lastly I need to get the filename without extension and the last folder where it is in: e.g: dir1/subdir1/subsubdir1/po1.po and dir2/subdir2/subsubdir2/po2.po should be set to a variable like: subsubdir1/po1 subsubdir2/po2, respectively. – wakeup – 2013-03-02T14:58:10.960
@user1754665 Hmm, maybe
find . -name '*.po' -type f -exec sh -c 'echo $(basename $(dirname $0))/$(basename $0)' {} \;
– slhck – 2013-03-02T15:29:03.723