Ubuntu

How to Check Executable File in Linux/Ubuntu?

How to test executable file in Linux

An Executable File in Ubuntu is a File that contains a program or a code that the user or system can run. Executable Files in Ubuntu tells the Ubuntu System what to do and it instructs the CPU on how to do it. With Executable Files, there is no need for Additional Software to be Installed or any Dependency to be Added. An Ubuntu User can easily download and share executable files that can easily be executed.

This article describes the methods to check executable files in Ubuntu.

How to Check an Executable File in Linux/Ubuntu?

The Executable Files in Ubuntu are either the ASCII Text Files, Text Executable Files, or the ELF 64-bit LSB pie Executable Files. The ELF or the Executable & Linkable File Format is a common Binary File Format in Ubuntu for Executable Files. The Text Executable file is the file that the user makes executable, i.e. a Text file or a script file is made executable using the “chmod +x” command. To learn more about “chmod” and to Make Files Executable, follow the complete Guide. ASCII Text Files are those that contain simple Text Content inside. The File Type tells us if the File is Executable or not. To Check the File Type in Ubuntu, the following common methods are used:

  • Check if a File is Executable with the “file” Command.
  • Check if a File is Executable with the “find” Command.
  • Check if a File is Executable with the “ls” Command.
  • Check if a File is Executable through the File Properties.

Check the Executable File using the “file” Command

One of the most widely used commands to check if the File is Executable or not is the “file” command. The “file” command returns the file type in the Terminal. The “file” command in the Terminal can simply be used along with the File Name:

file <fileName>

In our case, to check the executable files, we navigated to the Home Directory and opened the Terminal:

Now, in the Home Directory, to check the File type of the “encrypted.txt” file, execute the “file” command as follows:

file encrypted.txt

The File Type will return in the Terminal Confirming if it is Executable or not. In our case, the file “encrypted.txt” is simply an ASCII Text File meaning it cannot be executed:

Now, in the same directory, to check the File Type of the File “script.sh”, the “file” command used will be:

file script.sh

In this case, the Terminal returns the File Type of the “script.sh” file to be ASCII text Executable. This means that the file initially was not an executable file, rather it was made executable by the user:

Multiple files can also be checked if they are executable or not with the “file” command:

file <file1> <file2> ... <fileN>

In our case, to check the “pythonScript.sh” and the “rubygems” file, the “file” command will be:

file pythonScript.sh rubygems-3.3.7.tgz

The Terminal displays the File Type of both the files line by line and you can see the “pythonScripts.sh” file is an ASCII Text Executable File whereas the “rubygems” is the Compressed File:

To check the File Type of the file “new” in our current working directory, the “file” command will be executed as follows:

file new

The “new” file is an ELF 64-bit Executable File:

Check the Executable File using the “find” Command

The “find” command can also be used to list and check the Executable Files in a Directory. The “find” Command usually finds files and directories but with the “type” option, you can list the Executable Files as well. In our case, we will list all the Executable Files in the Home Directory:

The “find” command to list all the Executable files in the Home Directory is:

sudo find . -type f -executable -print

The “f” option looks for the Regular Files and the “-executable” option will return only those files in the Terminal that are executable:

With the “find” command, you can also return all the non-executable files. The command to list all the Non-Executable Files with the “find” command will be:

sudo find /usr/local -type f ! -executable -print

All the Non-Executable files in the Current Working Directory will be displayed:

Check the Executable File Using the “ls” Command

The “ls” command is another useful way to find the Executable Files in a Directory. The “ls” command displays all the files and directories inside a specific working directory:

ls

In our case, we are working in the Home Directory:

Now, to display all the files and the directories inside the Home Directory, the “ls” command is used. To display the details of each file and directory as well, the “-l” option is used along with the “ls” command:

ls -l

This will display the files and directories along with the details:

Notice the First Column of the Listed Files and Directories and you will see the file and directories permission. In the Permissions, the “-x” is displayed with the file that is executable. All the files having the “-x” permission are ASCII Text Executable Files as well as the ELF 64-bit Executable Files:

This is how users can check if a file is executable or not using a Linux terminal.

Check the Executable File through the File Properties

Checking the File Type through the File Properties in the GUI is the easiest and simplest way to see if the File is Executable or not. You can access the File Properties through the Properties option by right-clicking on a specific file. Considering our case, we have a file “new” in our Home Directory:

To check the File Type, right-click on the File which will list the options available. Click on the Properties Option:

The Basic Properties Menu will appear. The Type of File can be seen under the Name details of the File. In our case, the File “new” is of Executable File Type:

The “executable” file type verifies that the file “new” is an ELF 64-bit Executable File.

Similarly, we can check the file type of the file “script.sh” in our Home Directory:

Right-clicking on the file will list the options, and among the Options, we will select “Properties”:

The file “script.sh” as seen in the File Type of File Properties, is a Shell Script File:

The Shell Script File in Ubuntu is also an Executable File or ASCII Text Executable File. Thus the file “script.sh” is considered an Executable File as it was made executable with the “chmod” command.

Conclusion

The Executable Files in the Ubuntu System are either the ASCII Text Executable Files or the ELF 64-bit LSB pie Executable Files. The ASCII Text Executable are those files that are made executable by the user using the “chmod” command. To list or check the Executable Files in the Ubuntu System, the “file”, “find”, or “ls” commands can be used. Apart from the commands, the File Properties through the GUI can also display if the File is Executable or not. All the mentioned commands to check executable files are explained in detail in this article.

Similar Posts