Finding Out File Types with file

Finding Out File Types with file

If you come from a Windows or Macintosh background, you're probably used to accessing files and being able to see what type of files they areHTML files, GIFs, documents, or whatever. In Unix, though, you often can't tell the file type just by listing files or displaying directory contents. That's where file comes in handy, as shown in Code Listing 7.7.

To identify file types with file:

  • file /usr/bin/pico

    At the shell prompt, type file, followed by the path (if necessary) and filename. You'll see output similar to that in Code Listing 7.7.


  • Not all files have the "magic" information associated with them that makes file work, but most do. Where they don't, you get a best-guess response, like the second response in Code Listing 7.7. Unfortunately, you can't tell by looking if it's definitive information or a guess, but if it's terse (as in the second response), take it with a grain of salt.

Code Listing 7.7. The file command provides useful information about what kind of data is in specific files.

[ejr@hobbes ejr]$ file /usr/bin/pico /usr/bin/pico: ELF 32-bit LSB executable,    Intel 80386, version 1, dynamically ld [ejr@hobbes ejr]$ file temp.htm temp.htm: ASCII text [ejr@hobbes ejr]$ 

Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: