JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

How to solve the problem of not being able to execute binary files in Linux

Author:JIYIK Last Updated:2025/03/23 Views:

In this article, we will learn how to execute binary files in Linux. We will also learn how to troubleshoot the error if Linux fails to execute the binary file.

Usually, this error occurs when we run shell scripts in Linux. This article will provide all the working methods to help you resolve this issue.


Linux binaries

In programming, binary means two and a binary file has two characters (1,0). Binary files are used to store information and data.

In Linux, binary files have the extension .bin. Binary files can be executed in Linux using the syntax ./file.bin.

When we execute binary files in Linux system, sometimes we get the error "cannot execute a binary file". This error means that the Linux system does not recognize it as a shell script or executable file.

Let us see how to fix this error in Linux.


Solve the "Cannot execute binary file" error in Linux

The reason could be that the architecture type of the binary does not match. Another reason could be that the user does not have permission to execute the binary.

We will provide you with several solutions to eliminate this problem in Linux. Try one of the following solutions and check if the error is resolved.

Check the file structure

The first thing you need to do when you get this error is to make sure you got the right binary. Because if you have a 32-bit binary and execute it on a 64-bit system, it will not execute and will give you the error.

32 bit binaries will not work on 64 bit systems and vice versa. We can check the architecture of any file in Linux using the following command.

The syntax of the command:

$ file filename

Commands for file structures:

$ file test.sh

Check the file structure

As shown in the figure, we have used the terminal command file test.sh. We can see the architecture of the file named test.sh in the output.

This way, we can also find the architecture of a binary file.

If the architecture of your binary does not match the system you are running it on, you will need to run your binary on a matching architecture system.

Check your binary file format

We run binaries on Windows, Linux, and macOS. Binaries made for Windows will not run on other operating systems, and vice versa.

These binaries have different formats to help users distinguish between them. If you run a binary made for Windows or macOS on a Linux system, it will not work.

You must be on a Linux operating system to run binaries made for Linux.

Installing GCC and Gfortran packages in Linux

If these two packages GCC and Gfortran are not installed in our Linux system, then this may be the reason why our Linux system cannot execute the binary files. These packages (GCC and Gfortran) must be installed in order for multiple binary files to compile and execute correctly.

We can install these libraries using the following commands in our terminal.

Command to install the Gfortran package:

$ sudo apt-get install gfortran

Installing Gfortran package in Linux system

Command to install the GCC package:

$ sudo apt-get install build-essential

Install GCC package in Linux system

After installing these two packages in your Linux system, you can resolve the error of unable to execute binary file.

Try to unzip the binary file

Sometimes we compress binary files to make them easier to share on the Internet. If the binary file you are executing is compressed, try uncompressing the file.

We can decompress the binary file using the following command in the terminal.

Command to unzip the file:

$ xz -d ./filename

Check binary file permissions

Another reason why the binary file cannot be executed on Linux system could be that the user does not have permission to change or read the file binary. We can fix this issue by granting execution permissions to the binary file using the following command in the terminal.

Command to grant execute permission to a file:

$ chmod +x filename

After setting the permissions, we can run the binary using this command in the terminal:

$ ./filename

Use dos2unix command to execute binary files

The best solution to fix the problem of not being able to execute binary files is to use dos2unix command in Linux. This command helps us to run binary files made for DOS on our Linux system.

Command to convert DOS binary files to Unix format:

$ dos2unix filename.bin

After using this command in the terminal, the binary file in DOS format will be converted to Unix format. Then, our Linux system can execute the binary file.

This article explains all the possible solutions to fix the cannot execute binary file error in Linux. We hope you found this Linux article helpful in understanding how to execute binary files in Linux.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

ps aux command in Linux

Publish Date:2025/03/23 Views:57 Category:OPERATING SYSTEM

If you are using Linux and are looking for a tool that can monitor all the processes running on your system, then you should use the command ps aux. This command will show you an overview of all running processes. It is very useful for trou

NTP in Linux

Publish Date:2025/03/23 Views:58 Category:OPERATING SYSTEM

NTP is a core protocol used by most IT infrastructures. Its purpose is to synchronize date and time information. However, it is very important to configure NTP for your servers, clients, and other network devices. NTP uses a UDP port number

Creating a Progress Bar in Bash

Publish Date:2025/03/23 Views:94 Category:OPERATING SYSTEM

A progress bar is a visual indicator that shows the progress of a task, such as a long-running script or command. It can be used to provide feedback to the user about the status of a task and can also help estimate the time remaining before

Redirecting Stderr and Stdout to a file in Bash

Publish Date:2025/03/23 Views:187 Category:OPERATING SYSTEM

In this article, we will discuss standard output and standard error in Linux. We will see how to redirect standard output and standard error in Bash. Let us start by understanding the terms standard output and standard error in Linux. Stand

Deleting Duplicate Lines in Bash

Publish Date:2025/03/23 Views:123 Category:OPERATING SYSTEM

Duplicate entries can cause a variety of problems in Bash scripts, such as incorrect or inconsistent results, and they can also make the script difficult to maintain. Removing duplicate entries from a script is often necessary to avoid thes

Count unique lines in a file in Linux

Publish Date:2025/03/23 Views:190 Category:OPERATING SYSTEM

Counting unique lines in a file is a common task in Linux, and there are a number of different tools and methods that can be used to perform this operation. In general, the appropriate method depends on the specific requirements and constra

Counting files in a directory in Bash

Publish Date:2025/03/23 Views:178 Category:OPERATING SYSTEM

Counting how many files are in a directory is a common task in Bash, and there are a number of different tools and methods that can be used to perform this operation. In general, the appropriate method depends on the specific requirements a

Execute commands in a variable in a Bash script

Publish Date:2025/03/23 Views:111 Category:OPERATING SYSTEM

This article is about storing Bash commands in a variable and then executing it directly from that variable. First, we will discuss the various ways to execute commands contained in a variable, followed by several script examples. Let’s g

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial