I need to create a list of files in a directory and all of its subdirectories. I've used
find . -type f
to get the list of files, but I only need the file name, not the path that leads to it.
So instead of returning this:
./temp2/temp3/file3.txt
./temp2/file2.txt
./file.txt
I need to return
file3.txt
file2.txt
file.txt
find . -type f -exec basename {} \;
or better yet:
find . -type f -printf "%f\n"
You can use printf option in gnu find:
find . -type f -printf "%f\n"
For non-gnu find use -execdir and printf:
find . -type f -execdir printf "%s\n" {} +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With