Find can output a space-separated list of results without relying on other commands:
find . -name someFile -type f -printf "%p "
The above will find all files named "someFile" in the current directory or any sub-directories, and then print the results without line breaks.
For example, given this directory tree:
.../dir1/someFile.txt
.../dir1/dir2/someFile.txt
Running find . -name '*.txt' -type f -printf "%p " from dir1 will output:
someFile.txt ./dir2/someFile.txt
The arguments, options, and "actions" (i.e. -printf) passed to the above find command can be modified as follows:
- If you don't give the
-type f option, find will report file system entries of all types named someFile. Further, find's man page lists other parameters that can be given to -type that will cause find to search for directories only, or executable files only, or links only, etc...
- Change
-printf "%p " to -printf "%f " to print file names sans path, or again, see find's man page for other format specifications that find's printf action accepts.
- Change
. to some other directory path to search other directory trees.