Linux: Find all the text files in a directory

I need to find all the text files in a given directory for potential clean up. There is not a super easy way to find only text files, but I came up with a hacky solution:

# Using `fd` (new hotness)
fd . /tmp/ --exec file {} + | grep -P ":.*text" | cut -d: -f1

# Using old school `find` (old and busted)
find /tmp/ -exec file {} + | grep -P ":.*text" | cut -d: -f1

These rely on the file command to determine what the filetype is.

Leave A Reply
All content licensed under the Creative Commons License