CLI – file

serveimage

CLI – If you encounter a file and are not sure what type of file it is (often because the extension is missing), the the file command is what you are looking for.

This command allows you to lets you see the type of file you’re dealing with. The description of file in the macOS man page is:

file tests each argument in an attempt to classify it.  There are three sets of tests, performed in this order: filesystem tests, magic tests, and language tests.  The first test that succeeds causes the file type to be printed.

The type printed will usually contain one of the words text (the file contains only printing characters and a few common control characters and is probably safe to read on an ASCII terminal), executable (the file contains the result of compiling a program), or data meaning anything else (data is usually “binary” or non-printable).  

To learn a lot more about how to use file, take a look at “Linux file Command Tutorial for Beginners (5 Examples)“. Yes, this is a Linux article, but the file command as implemented on macOS is fundamentally the same. Check the macOS man page for file for all of the available options.


See my other CLI and macOS articles


 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.