Linux make all files executable

How to Make a File Executable in Linux?

Every file or directory in Linux has “read”, “write”, and “execute” permissions. These permissions are assigned by default when the directory or file is created. But > can easily change it via the CLI and GUI. In CLI, it can be modified using the “chmod” command. While in GUI, the file “properties” window helps the user to perform this task.

This guide provides the possible effects to make the files executable in Linux through CLI and GUI. The outline of this article is as follows:

Let’s start with the first method.

Method 1: Make File Executable in Linux via CLI

Linux OS offers the productive commands to access and manage the system completely. This method comprises step-by-step instructions to make a file executable in Linux using the command line interface for the owner, group, others, and all.

Before moving on to the practical implementation, let’s look into the specific “NewFile” file permissions:

The highlighted part in the output displays that the “NewFile” does not have execution rights for any user. Now, let’s make it executable using the steps.

Step 1: Change the File Permissions

First, change the permissions of the specific file with the help of the “chmod” command. As an example. A file is created in the “nano” text editor having the name “NewFile” and the following content:

Now, the execution privileges can be granted to a specific user, following their key names, which are demonstrated below.

  • u: Denotes permissions for the owner of the file.
  • g: Represents permissions for the group of a file.
  • o: Allows permissions for other users.
  • a: Accesses permissions for all.

Make File Executable for Owner

Make File Executable for Group

Make File Executable for Others

Make File Executable for All

In this scenario the permissions are allowed to all users of current OS by utilizing the below-mentioned command:

Now, every user of the current OS can execute the “NewFile” file

Step 2: Execute the File

Once the execute permission is assigned to “NewFile”, run it in this way for the verification:

Hence, the “NewFile” is executed successfully and show the output of the “ls -l” command that is described in it.

Note: If the file has the “.bin” or “.run” extension, then use this file extension with its name. The generalized syntax for making these files executable is written below:

$ chmod u+x [file-name] [file-extension]

Make File Executable Using Octal Numbers

Apart from the above classes, the user can also change the file permissions using the “octal” numbers. While each octal value represents either “read”, “write”, or “execute” permission. Look at the table to understand what octal values are in the permissions scenario.

Читайте также:  Linux mint or linux mint debian edition
Octal-Value Permissions Representation Permissions Description
0 Represents no permission
1 –x Allow only the execute permission.
2 -w- Shows the write permissions only.
3 -wx Write and execute permissions, i.e. (1. execute) and (2. write)=3
4 r– Read permissions only.
5 r-x Read and execute permission as (1. execute) and (4. read)=5
6 rw- Read and write permissions as (4. read) and (2. write)=6
7 rwx All permissions such as (1. execute), (2. write) and (4. read)=7

Example

Use the above octal values to make the “File1” file executable for its owner, group, and others. Its permissions are shown below:

Type the octal value in the set as “6(4 read)(2 write)” for the owner, “7 (4 read)(2 write)(1 execute)” for the group, “4(4 read)” for others with the chmod command. This octal value will make the file executable only for its group:

The output verifies that only the “itslinuxfoss” group is allowed to execute the “File1”.

Method 2: How to Make File Executable in Linux via GUI?

The user can also execute the file with the help of the graphical user interface. Follow the steps below to run the .bin file visa GUI

Step 1: Open the file Properties

Open the directory where the desired file is saved or downloaded. In this case, the file named “Extra.bin” is located in the “Documents” directory:

Right-click on the file and choose the “Properties” option from the dropdown list:

The “Extra.bin Properties” window will be opened:

Step 2: Change the File Permissions

Hit the “Permission” icon in the menu bar of the “properties” window. Tick the highlighted checkbox “Allow executing file as a program”:

Step 3: Execute the file

Now, double-click on the “Extra.bin” file to run it:

That’s how to make files executable in Linux using CLI and GUI.

Conclusion

All the commonly used Linux distributions provide the “chmod” command to make the file executable. The “chmod” command assigns the execute permissions in two ways that are using the “permission levels” or the “octal values”. Furthermore, > can also perform this task efficiently through the Graphical User Interface. This guide has provided CLI and GUI methods to make file executable in Linux.

Источник

How To Make A File Executable In Linux

If you’re someone with a background in a Windows operating system, chances are you’re aware of the “.exe” files. These files are referred to as executable files because their purpose is to execute a series of commands that make up the whole program.

However, when you make the change to a Linux distribution, this division of executable vs. non-executable does not apply. Any file can be made executable in Linux since it does not require a certain extension to be declared as an executable.

This provides a lot of flexibility when it comes to file management.

If you’re someone looking to learn how to make a file executable in Linux, then this guide is meant for you. We’ll provide a step-by-step solution on how you can make any file executable, either using the CLI or the GUI method.

Читайте также:  Ramdisk on linux boot

Let’s take a look at the steps.

Method 1: Using The Command Terminal

The first method makes use of the Command Terminal. You can make any file executable by typing certain commands in the Terminal.

Although we’re going to be using Ubuntu 20.04 LTS in this guide, the steps shouldn’t be any different for other Linux distributions. With that said, just follow the steps explained with the help of an example.

First and foremost, open the Command Terminal on your system. The shortcut for Ubuntu is Ctrl + Alt + T.

For this guide, we’ll create a sample file using the echo command by using the following command:

This command will create a string literal with the text “This is a guide on how to make a file executable in Linux” and store it in a file called Test1.

To view the content of the file, type the following command:

You should notice that the file doesn’t end with an extension name. This means that you have the option to make the file executable.

In order to make Test1 an executable file, we’ll use the following command:

In case of a file extension, the command becomes:

Now you can call your file by typing its name in the Terminal as follow:

You can also execute the command in the following manner:

This will provide appropriate permission for the file to be executed.

If the CLI method seems complicated to you, worry not as you can achieve the same results with the help of the GUI.

Method 2: Using the GUI

Unlike the CLI method, the GUI method is much less daunting and simplified to understand what’s going on.

Follow these steps to make a file executable using the GUI.

Start by navigating to the file of your choice. Once you’ve navigated to the file, right-click on it and select “Properties”. A new window should appear.

Once a window opens, click on the Permissions tab.

In the Permissions tab, you should see an option titled “Allow executing file as program.”

You should now have the desired file in an executable format if you followed the steps correctly.

Understanding How File Execution Works

Learning how file execution works in Linux has its benefits as it provides more flexibility when it comes to an understanding of how the file works.

In Method 1, we used the command chmod +x. This was necessary in order to make the file executable since the file required “read” privileges. The “./” tells the Terminal to search for the location of the file.

Aside from Method 1, there are other ways to use the $ chmod command. This flexibility makes $ chmod extremely valuable. A list of options for the $ chmod command is given below:

  • $ chmod 775 . This mode allows anyone to execute the file. However, only the owner of the file has permission to write in that file.
  • $ chmod 0010 . Only users of a group will be allowed to execute the file.
  • $ chmod 0100 . Permission to execute the file belongs exclusively to the user.
  • $ chmod 777 . Provides permission to execute the file to all Linux users.
  • $ chmod -777 . Doesn’t allow any user to execute the file.
Читайте также:  Диск восстановления linux mint

Additional Information

Although the $ chmod command works for files without extension type, it should be noted that you’ll need to specify the file type in case it’s mentioned. For example, if you are dealing with a file that has a .run or .bin extension. The syntax for the execution command would be:

Additionally, make sure you have the correct name, file type, and file location before making any file executable.

Conclusion

If you followed the steps in the guide correctly, then the good news is you are now aware of how to make a file executable in Linux.

This guide covered different methods to make the file executable in Linux. We started by explaining the method involving the Command Terminal and followed up with the method to achieve the same with the help of the Graphical User Interface(GUI). We also covered additional uses of the $chmod command and the different permissions.

With this, we wish you all the best in your journey to master Linux.

Источник

How to find all .sh files and make them executable using bash in linux?

The safest and way both in terms of security and in terms of weird file names (spaces, weird characters, and so forth) is to use find directly:

find /home/user -name "*.sh" -execdir chmod u+x <> + 

You can check the comments and the manual of find why this is safe, but in short, it makes sure your file is properly quoted in the chmod command. execdir (rather then -exec ) is an extra security feature making sure the command is executed in the directory the file was found in avoiding race conditions (elaborated in the manual).

@hek2mgl For posterior: pointed out another solution now removed is unsafe since argument expansion fails on file names with spaces: passing $() the argument list to chmod .

Just one thing about the -execdir . In this case it doesn’t make a difference because chmod will have no side-effects except from changing the file permissions of the target file. It would make a difference if you, let’s say, going to execute the scripts find detects. In that case the working dir of those scripts when using -exec would be the directory where you execute find from. If now two scripts try something like if [ -f lock.file ] ; (meaning they try to access relative paths) then both would try to work on the same file instead of a file called lock.file in their directory

@ScottyC I’m not sure what you mean. execdir just executes the command in the directory it was found, with the file as an argument, instead of executing it relative to the original directory you ran find . This avoids several security issues that are mentioned in the man and around the internet. If you feel it’s unclear that would warrant a question on SO, but research first. If the command you’re running explicitly depends on being run from the original find directory (which is odd, and probably not a best choice of design) then it would obviously fail.

Источник

Оцените статью
Adblock
detector