Header Ads


How to Determine File Encoding in Mac OS by Command Line

How to Determine File Encoding in Mac OS by Command Line


You can determine a files encoding and character set through the command line in Mac OS (and linux) by using the file command, which helps to retrieve general and specific information about a file type. This probably wont be a relevant tip to many users, but if youre required to be working with a specific character set for something or need to know what a file type, encoding, or character set of an inputted item is by way of the command line, then this will do the trick.

The file command works in Mac OS and Mac oS X as well as linux and many other unix variations, making this trick helpful for scripts and other similar purposes too. The basic syntax is as follows: (In case it wasnt obvious, thats a capital i as the flag as in -I, not a lowercase L) Hitting return with a proper file name as the input will reveal a character set like UTF-8, us-ascii, binary, 8bit, etc. For example, lets say were checking the character set and file encoding of a file named text.txt then the syntax would look as so: With text/plain being the file type and unknown-8bit being the character set file encoding. You can also issue the file command on literally any other file, be it images, archives, executables, or anything else you want to point the command at.

This can be nice if youre automating something to detect a file type to then run an appropriate command, perhaps after a and the archive type needs to be determined before a proper command can be executed. There are many other uses for checking character set, file encoding, and file type through the command line with the file command, and the -I flag is just one of a wide variety of options available. Check out the for file to learn more if interested, and dont forget to check out our many other command line tips (or ). Do you know of another or better way to check file encoding and character set via the command line in Mac OS? Let us know in the comments!


No comments

Powered by Blogger.