How can I tell if a file is a binary file or a text file without opening it?
There's no way to verify what kind of contents a file has without some program opening it and actually reading the contents.
If you're asking how to tell whether the file is binary or text without opening it in a text editor, that's certainly possible, at least for most files. Linux includes the
file program for just this purpose; at the command line, run
(where of course you replace
name_of_file with the actual name of the file you're testing). The
file program will print out an informed guess at the type of the file, based on its contents, and it's usually pretty good at guessing.
Of course, there will always be some corner cases where even
file can't tell. If a file is UTF-8 encoded text that includes a lot of high-numbered Unicode characters, for example, it'd probably look like a binary file and you'd get gibberish if you open it in a text editor that isn't Unicode-aware. Although even in that case, I think
file might be able to identify it correctly... the point is, sometimes it's hard/impossible to tell at all, so you can never be 100% sure that you've identified the contents type correctly.
I guess the bigger question would be, why are you trying to distinguish binary files from text files?
This is impossible. All you can do is use tools like
file to make a best guess.