How to only get file name with Linux 'find'?

marverix picture marverix · Mar 28, 2011 · Viewed 290.9k times · Source

I'm using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get ./dir1/dir2/file.txt and I want to get file.txt

Answer

SiegeX picture SiegeX · Mar 28, 2011

In GNU find you can use -printf parameter for that, e.g.:

find /dir1 -type f -printf "%f\n"