Methods of payment Abuse

Making a file executable in Linux

06.03.2021, 20:51

What makes Linux different from Windows in terms of file execution is that the former system defines executable files as program files not by their extension, but by a special executability flag. Thus each file has three modes of executability: read, execute and write. It is these modes that determine what the system can do with a particular file. When a user downloads various installers from the Internet or creates a script, it is assigned the following modes by default: read and write. In short, the user will not be able to do anything with such a program, because something else needs to be done with it.

What does executability mean?

But first of all, we should deal with such a question as: what is executability and what does it mean in general? Let's start with a program, which is a set of instructions executed by a processor over a set of data in order to get the desired result. For the processor, there is no difference between instructions and data.

Both the former and the latter consist of digits - bytes. That is, a certain combination of digits will signify to the processor the need to perform a particular action. For the processor there is no fundamental difference which process to execute - operating system data or a text file. Both the first and the second will be executed, except that in the case of a text file the need for instructions is actually eliminated.

Executability flags were invented for the system to understand which instructions should be executed and which ones should not be executed. In fact, the content does not change in any way depending on the set executability class - the difference is reduced only to a few lines. With scripts everything works in the same way, but commands are executed not by the processor, but by an interpreter, for example, in bash scripts - by the bash shell itself. Regular programs also have their own loader - it is ld-linux.so.2.

How to make a file executable

The Linux system has a special utility that allows you to manage flags, which is called chmod. To call this utility, you need to invoke the syntax:

$ chmod category action flag file_address

КАК СДЕЛАТЬ ФАЙЛ ИСПОЛНЯЕМЫМ В LINUX

And here the following must be considered:

Flag - one of the available flags - r (read), w (write), x (execute).

Category - can be set for three categories: file owner, data group and all other users. In the command they are indicated by u (user) g (group) o (other) respectively.

Action - can be + (plus), which would mean set the flag or - (minus) remove the flag.

Thus, to make a script executable in Linux, the user needs to execute:

$ chmod u+x file_address

Often this is already enough to make it executable, but if other users need to be authorized to execute these files, more must be added:

$ chmod ugo+x file_address

To see them in the terminal, just use the ls utility:

$ ls -l file_directory

Посмотреть флаги в терминале можно с помощью утилиты ls

Flags are included for all categories. The first rwx are owner flags, the second are group flags, and the third are for all others. If it is not set, a dash will take its place.

It is very easy to remove the executable flag. The same command is used, only with a minus sign:

$ chmod u-x file_address

Next let's consider the issue of setting controllability in GUI.

How to set the executable flag in GUI

For beginners, this instruction will be easier. Let's take the GNOME manager, Nautilus, as an example. Right-click on our program or script object to open the context menu, then select properties:

КАК УСТАНОВИТЬ ФАЛГ ИСПОЛНЯЕМОСТИ В GUI

Go to the permissions tab and check the "Allow the file to run as a program" checkbox:

Разрешить выполнение файла как программы:

Now it will be launched by the system directly from the manager. That's the whole instruction. Now you will have no difficulties with launching a program or script from the Internet.