closeup photo of street go and stop signage displaying stop
Photo by Kai Pilger / Unsplash

When you download a program on a typical Windows based computer and attempt to run it you would expect to simply double click the icon and have the software run or install or do whatever it is meant to do right?
That program would also likely have something called a file extension, a concept that you might not have heard of before but have certainly encountered unknowingly. A typical file extension for a Windows application would be something like .exe or for an installer maybe something like .msi, looking at these extensions you are likely familiar with them now that I have explained what they are. Essentially every file on a Windows computer has an extension to help Windows and you, the user, figure out what type of file it is and what do with it. Files without extensions result in Windows throwing a prompt for you to pick the application that should handle them.

This shows how reliant Windows is on file extensions.

black binders on steel rack
Photo by Samuel Zeller / Unsplash

UNIX is not.

UNIX uses some data at the start of a file called a 'Header' to decide what kind of file it's dealing with. Be that a jpeg image or a text file, UNIX and Unix-Like systems such as Linux or BSD make use of the header in place of the file extension in many cases. This isn't to say that the extension is ignored completely as certain applications can still make use of it to display a pretty icon or to denote a version of a similar file.

So this explains briefly how both Windows and UNIX handle the existence or lack of file extensions.
But what happens in the special case of executable files?

Executable files are usually programs or scripts that are expected to be interpreted or run by the system in some way.
On a Windows system if you attempt to run a file that has the typical .exe extension and the file is indeed a program, then Windows will run it, more often than not completely blindly. It is this very blind running nature that has caused Windows so much strife in the past with malware, regardless of the attempts to curb this behaviour with mechanisms like UAC (User account control).

UNIX on the other hand treats every file with a degree of suspicion and refuses to execute anything that isn't explicitly marked as executable. Even if UNIX had an 'executable' file extension it wouldn't run that file blindly without your permission to do so. UNIX does this by adding a special permission to all files known as the executable bit, it is either 1 or 0 for on or off respectively. A file with a 0 executable bit cannot be executed under any circumstances. You can even test this out by creating a text file with this contents:

#!/bin/sh

echo "Hello World"

exit

Then try and run that text file with ./{filename}

Your shell will throw a permission error or, in the case of a graphical interface, simply open the file in a text editor, because that's all this is right now, a block of text. It isn't interpreted in any way other than as text on a page.

Now add the executable permission with:

chmod +x {filename}
or
chmod 755

And rerun the file.
This time, the text "Hello World" will print to the terminal and then exit.

Essentially you have told the system that this file is now an executable text file and to run it through whatever shell you have, in this case /bin/sh as listed at the top of the file.

This executable permissions model works extremely well for preventing system wide destructive changes due in part to the fact that no user other than the super user (root) can make the above changes to a system file or to a file that could damage the system.
There is one exception to this however, the program "sudo", more on that next time.