I have 8 files in the linux operating system and i want to know which one of them is only-human readable file .

-file00  -file01  -file02  -file03  -file04  -file05  -file06  -file07  -file08  -file09

how can i do this ?


If you're looking for files that match the text/plain MIME Type, then you could use file --mime-type, which will have a "best guess" at what the file is... pair that with grep and you might get a reasonable result.

# put the name of each file into the `files` variable
files=( * )

file --mime-type -- "${files[@]}" \
  | grep -E ': +text/plain$'

Note that file doesn't actually scan the entire file to make this "best guess" assessment, so you may get some false positives. Additionally, I'm not sure how it will deal with Unicode...

If you're after something else, then please revise your question with more detail on what you're after.

  • 1
    Note the names in question begin with -f. Use ./* or --. – Kamil Maciorowski Apr 1 '20 at 20:06
  • 1
    @attie file properly identifies UTF8-encoded files (UTF-8 Unicode text) – xenoid Apr 1 '20 at 20:21
  • @KamilMaciorowski thanks... I had actually assumed that was an artefact of incorrect formatting, oops. – Attie Apr 1 '20 at 21:06
  • 1
    @attie file assigns the UTF-8 file the same text/plain MIME type as a pure ASCII file. – xenoid Apr 1 '20 at 21:11
  • @xenoid great, thanks! I was wondering if there was an ; encoding=utf-8 or anything appended – Attie Apr 1 '20 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.