friendica (DFRN) - Link to source

Look the short AI answer here is at this prompt

What does the file command do on Linux, and how can it identify file types without relying on extensions?

Short answer:
The file command analyzes file content using magic numbers and heuristics to determine type, bypassing extensions. It supports MIME types, compressed files (-z), and symlinks (-L).

mine does this or I do it..



answer is ungoing because I did not precised the context of what I want, rather the whole.


@tante this is the few %

in reply to Plan-A

@Plan-A

Magic numbers are used by most OSes even MS/Windows. They are typically the first two to four bytes, in some instances more. Every graphics format has their own magic number. Also the bash shebang #! is a magic number. Elf binaries have a magic number as well a MS/Windows PE files and other executable formats on MS/Windows. When it come to plain text files such as json and source files file uses heuristics as their are no magic numbers to count on.

Unlike MS/Windows file extensions are meaningless in regards to the filesystems used on Unix derivatives such as Linux. Though file can make assumptions based on a file extension. This does not mean you should use them in places where they do not belong.

A basic rule for file extensions, greatly ignored from those coming from MS/Windows, is that if the file will be consumed by another app or service then we give it a file extension so its MIME type can be used. An example would be files that are served by your httpd daemon. We DO NOT use file extensions on any program that is intended to be invoked from the CLI ever. There are some issues. Such as when Microsoft had the standards for .NET drawn up they required the .exe extension for executables. Most .NET applications developed on 'nix systems are not run at the CLI so this is not an issue. When they are we create a symbolic link to the .exe file so that users do not have to use the .exe extension when invoking the command.

This is an ongoing issue as many developers turning to 'nix from a Windows environment do not seem capable of understanding that file extension are not typically used in many cases on 'nix. That is why we have a file in the first place. It is sad that even those at a professional level often do not get this simple concept.

We can also use the symbolic link technique when we are writing python programs that are meant to be invoked at the command line though our tool chain likes file extensions. We do typically use file extensions on source code for compiled programs as they are not directly invoked and are consumed by the compiler. You will note that there are many python and perl scripts used on a 'nix system and none of them have a file extension. If a python, perl or other script has a shebang line and you set the executable bit then it should not have a file extension. If it is run by an interpreter and does not have a shebang line and does not have the execution bit turned on it is fine to have a file extension.

This entry was edited (19 hours ago)
⇧