basename on every file in
find, that is a massive waste of resources, starting a shell for every file found.
find (assuming the GNU version, although other
find versions may also support this) has a directive
-printf that takes a format string which tells it how to output information about the file, including size, ownership, permissions, etc.; not just its name.
One of those formats is
%f which is the filename with any leading directories removed, i.e. exactly what you are using
basename for. So you can use
find -type f -printf '%f\n'
You need to add the newline
\n so that each filename is on each own line.
An additional detail that works in your favour is that you can add a limit on the number of characters to be printed in such a way. If you want at most 3 characters of the filename to be printed, use:
find -type f -printf '%.3f\n'
Now just add
sort to the mix:
find -type f -printf '%.3f\n' | sort
and you have your solution.
EDIT: as it appears that the files need to be sorted, and then the first 3 characters of their contents need to be output, the command becomes:
find -type f -printf '%f\t%p\n' | sort | cut -f2 | xargs head -n 1 | cut -c1-3
This uses the format string to first show just the base filename, followed by a tab, followed by the complete path. This can be used to easily sort the filenames.
cut -f2 extracts just the part after the tab.
xargs head -n 1 gets the first line of each file.
cut -c1-3 shows the first three characters of each line.
head -n 1 part is needed in the pipeline, or else
cut will show the first 3 characters of every line of each file.