Have Find print just the filenames, not full paths

Steve picture Steve · Feb 8, 2012 · Viewed 47.5k times · Source

I'm using the find command in a ksh script, and I'm trying to retrieve just the filenames, rather than the full path. As in, I want it to return text.exe, not //severname/dir1/dir2/text.exe.

How would I go about getting that? To clarify, i know the directory the files are in, i am just grabbing the ones created befoee a ceetain date, so the pathname doesnt matter.

Answer

glenn jackman picture glenn jackman · Feb 9, 2012

If you're using GNU find, then

find path -printf "%f\n"

will just print the file name and exclude the path.