When you are browsing your files in the OS X Finder, you will have a number of options for telling you what the file is. For starters, most files have an icon that represents the program that will open it, and then you can click the file and press Command-i to get information on it. When managing file in the OS X Terminal, if you are relatively new to the Terminal you may think the only identification for a file is its name (ie, a “.txt” suffix for a text file); however, there are several tools you can use to see quite a bit of information about a file.
When viewing information about files in the Finder, most of the information is from metadata that is just organized on a pretty interface, but this information is also available in the command line.
ls -l /path/to/file ls -lU /path/to/file
If you are wondering what kind of file you are dealing with, you can use the “file” command, which is quite informative with its basic usage to tell you information such as the file being a text, html, or xml document, or for images tell you details such as resolution and bit depth:
The options so far only outline non-metadata attributes for a file, but you can also see a lot of information that OS X and other programs store in the file’s metadata by running the following command to list metadata attributes for the file:
The details output by this command will be a list of metadata keys and their values. These will include details like file size, name, content type, image size and resolution, among many others. Note that metadata is intended for quick access to file information; however, it is maintained my services separate from the file and could be incorrect. For instance, there is nothing that prevents file size metadata from being different from a file’s size on disk. For the most part, system services keep this information up to date, but changes that do not invoke these services could require them to run in order to keep the metadata up to date.
A last metadata-handling routine is viewing and managing the extended attributes for files, which are metadata entries that set system functionality options as opposed to more content-based information. For the most part you will likely not need to interact with these beyond simply listing them, and perhaps deleting them from a file. To list them, you can run either of the following two commands:
ls -l@ /path/to/file xattr -l /path/to/file
Finally, as with any file the ability to read its content will also tell you information about the file. If in using the above options you have determined the file contains text (ie, its format is XML, HTML, CSV, TXT, or similar), then you can at least preview its contents in the Terminal by opening it in a Terminal-based text editor or concatenating its contents to the Terminal output, done with the following two commands:
nano /path/to/file cat /path/to/file