If I understand you correctly (I didn't, see second part of the answer), you want to avoid listing filenames that contain a dot character.
This will do that:
find . -type f ! -name '*.*'
The filename globbing pattern *.*
would match any filename containing at least one dot. The preceding !
negates the sense of the match, which means that the pathnames that gets through to the end will be those of files that have no dots in their names. In really ancient shells, you may want to escape the !
as \!
(or update your Unix installation). The lone !
won't invoke bash
's history expansion facility.
To print only the filename component of the found pathname, with GNU find
:
find . -type f ! -name '*.*' -printf '%f\n'
With standard find
(or GNU find
for that matter):
find . -type f ! -name '*.*' -exec basename {} \;
Before using this in a command substitution in a loop, see "Why is looping over find's output bad practice?".
To list all filenames, and at the same time remove everything after the last dot in the name ("remove the extension"), you may use
find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%s\n" "${pathname%.*}"
done' sh {} +
This would send all found pathnames of all files to a short shell loop. The loop would take each pathname and call basename
on it to extract the filename component of the pathname, and then print the resulting string with everything after the last dot removed.
The parameter expansion ${pathname%.*}
means "remove the shortest string matching .*
(a literal dot followed by arbitrary text) from the end of the value of $pathname
". It would have the effect of removing a filename suffix after the last dot in the filename.
For more info about find ... -exec ... {} +
, see e.g. "Understanding the -exec option of `find`".
find
I’ll provide this aside in a comment. You can do this fluently with modern native bash:shopt -s globstar; files=(**/*); printf '%s\n' "${files[@]%.*}"
— this could have odd behavior if a directory in the path has a.
in it and the files in that path have no.
, but I assume that combination is unlikely. – kojiro Jan 23 '19 at 23:58