matlabfile-formathex-editorsfile-encodingsthunar

Accidentally created a MATLAB file


I was recently playing around with a command-line hex editor called Hx, and decided to create a sample file to play around in. I typed in the bytes 23, 23, 23, 23, and 23. Somehow, my system file manager (Thunar) recognized this as a MATLAB file. I have never used MATLAB. Why did this happen?


Solution

  • Magic Numbers

    Your file system will recognize different files by the first couple bytes or "magic numbers". Most unixy systems will use the file utility to determine file type. For example, if we take your file of \x23\x23\x23\x23\x23 and use file, we get ASCII/text.

    printf "2323232323" | xxd -p -r > temp
    file temp
    temp: ASCII text, with no line terminators
    

    That said, I also see that thunar is interpreting these file bytes as MATLAB:

    enter image description here

    You should also ask this question on our sister site, Unix & Linux if you want to know why thunar is exhibiting this behavior.