How can I detect if a file is a compiled object ( .o .a (library)) or executable, without the file extension?
I want to do this so that I can then issue the standard what command to see what .c / .h files were used to build the binary.
Presumably there would be some kind of header at the beginning of the file or some other pattern to look for (?)
Had a look around here and elsewhere a little already but the answers tend to be about MIME types and web development / handling of such files:
If you're in Unix/Linux, the file
command is useful for determining file type of files without relying on a file extension.
It looks at things like "is this a special device rather than a normal file", then looks for "magic numbers" which identify certain file format, etc.