Making a file executable one of the most common tasks needed for programming on a Raspberry Pi.
Follow along by setting up your Raspberry Pi…
Inside my home directory I have made a subdirectory named Examples. Move to your home directory by entering the following command.
Next, create the directory Examples and move into that directory.
$ mkdir Examples $ cd Examples
Next, create two empty files and make a subdirectory within Examples.
$ touch file1 file2 $ mkdir dir1
To see a simple list of these two files and the directory you made use the ls command by itself. To see the details about the files use ls -l.
$ ls $ ls -l
Deciphering ls -l output…
The results of the ls -l command is what you need to focus on because permissions for each file and directory are listed on the left side of the output. The dashes and letters, ten of them, describe the file and its permissions. If the first letter is “d” – it means it is a directory and if the first character is a dash then it means it is a file. The remaining nine characters describe the permissions for the file or directory. The nine characters are made of three groups of three. The first group of three is the permissions for the owner (that is you), the next group of three characters pertains to the group and the last group of three pertains to other users.
In our example notice that the owner permissions are set to “rw-“; therefore, I can read and write but cannot execute the file. If I could execute the file my permissions would be “rwx”. The group and other permissions, “r–“, means they can read but not write or execute.
Making the file executable…
The following command makes file1 executable by everyone with an account on your Raspberry Pi. The chmod keyword is followed by +x to add executability for everyone and file1 is the name of the file.
$ chmod +x file1