find’s printf action

Categories: Uncategorized

If you use find, it outputs full paths, which may not always be desirable. Turns out find has a -printf action with which you can do  niceties such as outputting plain filenames (as if you’d used basename on them, but this means one less command on your pipeline):

find data/{audio,documents,images,video,websites}/ -type f -printf "%f\n"

The -printf command has a lot of formatting variables and possibilites! give it a try, look at the man page for more information.