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 %
Plan-A
in reply to Plan-A • — (0.0.0.0) •Judge about this ya'll.
Plan-A
in reply to Plan-A • •Unus Nemo
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 filesfileuses 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
filecan 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
.exeextension 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.exefile so that users do not have to use the.exeextension 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
filein 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.
Plan-A likes this.
Plan-A
in reply to Unus Nemo • •But thanks for the information 🙂
Unus Nemo likes this.
Plan-A
in reply to Unus Nemo • — (0.0.0.0) •About NixOS you want.
Unus Nemo likes this.
Unus Nemo
in reply to Plan-A • •@Plan-A
When I say 'nix I am not talking about NixOS I am talking about all Unix derivatives including MacOS, BSD distros, Gnu/Linux distros, Hurd/Linux and any other Unix Derivatives. Yes, NixOS happens to be one of those derivatives, though it is not what I am specifically talking about.
Plan-A likes this.
Plan-A
in reply to Unus Nemo • •Unus Nemo likes this.
Unus Nemo
in reply to Plan-A • •@Plan-A
The term 'nix meaning Unix Like, is a lot older than NixOS 😉
Plan-A likes this.