How to run binary file linux

How to run binary file in Linux

I have a file called commanKT and want to run it in a Linux terminal. Can someone help by giving the command to run this file? I tried ./commonRT but I’m getting the error:

"bash: ./commonrt: cannot execute binary file" [blackberry@BuildMc MainApp]$ ls -al commonKT -rwxrwxr-x. 1 sijith sijith 10314053 Feb 27 16:49 commonKT 

Assuming the problem isn’t just a mixup over names ( commonrt vs commonKT ), what does the command file commonKT /bin/sh say? If it gives two different architectures (perhaps one for ARM and one for Intel), then that’s why you can’t run the ARM one on an Intel machine.

In addition of using file , I also suggest using ldd ; perhaps the dynamic linker or some core shared library is different or missing.

Why does this question have so many upvotes? It contains so many variants of the questioned filename (commonrt, commonKT, commanKT, commonRT), that it’s not even clear what was asked. Also interesting: Does the last comment of Sijith mean that it is answered? And why did user1978011 receive bountys?

13 Answers 13

To execute a binary, use: ./binary_name .

bash: ./binary_name: cannot execute binary file

it’ll be because it was compiled using a tool chain that was for a different target to that which you’re attempting to run the binary on.

For example, if you compile ‘binary_name.c’ with arm-none-linux-gnueabi-gcc and try run the generated binary on an x86 machine, you will get the aforementioned error.

To execute a binary or .run file in Linux from the shell, use the dot forward slash friend

and if it fails say because of permissions, you could try this before executing it

 chmod +x binary_file_name # then execute it ./binary_file_name 

The volume it’s on is mounted noexec .

🙂 If not typo, why are you using ./commonRT instead of ./commonKT ??

It is possible that you compiled your binary with incompatible architecture settings on your build host vs. your execution host. Can you please have a look at the enabled target settings via

on your build host? In particular, the COLLECT_GCC_OPTIONS variable may give you valuable debug info. Then have a look at the CPU capabilities on your execution host via

cat /proc/cpuinfo | grep -m1 flags 

Look out for mismatches such as -msse4.2 [enabled] on your build host but a missing sse4_2 flag in the CPU capabilities.

If that doesn’t help, please provide the output of ldd commonKT on both build and execution host.

@craq I see that you gave me your bounty, thanks! Can you please give some info what the error was about?

This is an answer to @craq :

I just compiled the file from C source and set it to be executable with chmod. There were no warning or error messages from gcc.

I’m a bit surprised that you had to ‘set it to executable’ — my gcc always sets the executable flag itself. This suggests to me that gcc didn’t expect this to be the final executable file, or that it didn’t expect it to be executable on this system.

Читайте также:  Linux links and symbolic links

Now I’ve tried to just create the object file, like so:

$ gcc -c -o hello hello.c $ chmod +x hello 

( hello.c is a typical «Hello World» program.) But my error message is a bit different:

$ ./hello bash: ./hello: cannot execute binary file: Exec format error` 

On the other hand, this way, the output of the file command is identical to yours:

$ file hello hello: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped 

Whereas if I compile correctly, its output is much longer.

$ gcc -o hello hello.c $ file hello hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=131bb123a67dd3089d23d5aaaa65a79c4c6a0ef7, not stripped 

What I am saying is: I suspect it has something to do with the way you compile and link your code. Maybe you can shed some light on how you do that?

Источник

How to run binary file in linux?

A binary file is a type of file that contains machine-readable instructions and data, instead of human-readable text. These files are compiled from source code and are executed directly by the operating system. On a Linux system, executing a binary file can sometimes be confusing, as it requires certain permissions and environmental variables to be set correctly. In this article, we will outline the methods for executing a binary file on a Linux system, and provide guidance for troubleshooting common issues.

Method 1: Direct execution with ./

To run a binary file in Linux, you can use the direct execution method with «./» followed by the name of the binary file. Here are the steps to do it:

  1. Open the terminal in Linux.
  2. Navigate to the directory where the binary file is located using the «cd» command.
  3. Type «./» followed by the name of the binary file to execute it.
cd /path/to/binary/file ./binary_file

Example 1: Running a C++ binary file named «hello»

cd /home/user/my_programs ./hello

Example 2: Running a Python binary file named «my_script»

cd /home/user/my_scripts ./my_script

Example 3: Running a Java binary file named «my_program»

cd /home/user/my_programs ./my_program

That’s it! By using the direct execution method with «./», you can easily run binary files in Linux.

Method 2: Adding execute permissions using chmod

To run a binary file in Linux, you need to add execute permission to the file. This can be done using the chmod command. Here are the steps:

  1. Open a terminal window.
  2. Navigate to the directory where the binary file is located using the cd command.
-rwxr-xr-x 1 user user 12345 Jan 1 00:00 filename

Here are some additional examples of using the chmod command:

    To add execute permission for all users:

Method 3: Setting the PATH environment variable

In Linux, to run a binary file, you need to specify the full path to the file or execute it from the current directory using the ./ prefix. However, setting the PATH environment variable can simplify the process of running binary files. Here are the steps to follow:

Step 1: Create a directory for your binary files

Create a directory where you will store your binary files. For example, let’s create a directory named bin in your home directory:

Step 2: Add the directory to the PATH environment variable

To add the directory to the PATH environment variable, open the .bashrc file in your home directory:

Add the following line at the end of the file:

Save and close the file by pressing Ctrl+X , then Y , and finally Enter .

Step 3: Move the binary file to the directory

Move the binary file to the bin directory that you created in step 1. For example, let’s move a binary file named myprogram to the bin directory:

Step 4: Make the binary file executable

Make the binary file executable using the chmod command:

Step 5: Run the binary file

Now you can run the binary file from anywhere in the terminal by simply typing its name:

If you have multiple binary files in the bin directory, you can run any of them using the same method.

That’s it! You have successfully set up the PATH environment variable to run binary files in Linux.

Method 4: Running with an absolute or relative path

To run a binary file in Linux, you can use the command line interface and specify the absolute or relative path to the file. Here are the steps to do it:

Running with an absolute path

Replace path/to/binary_file with the absolute path to the binary file you want to run.

Running with a relative path

  1. Open the terminal.
  2. Navigate to the directory where the binary file is located using the cd command:

Replace path/to/directory with the relative path to the directory where the binary file is located.

Replace binary_file with the name of the binary file you want to run.

./home/user/my_project/bin/my_binary cd ~/my_project/bin ./my_binary

In the above examples, my_project is the name of the project directory, bin is the directory where the binary file is located, and my_binary is the name of the binary file.

Note that you may need to make the binary file executable before you can run it. You can do this by using the chmod command:

Replace binary_file with the name of the binary file you want to make executable.

That’s it! You should now be able to run binary files in Linux using an absolute or relative path.

Источник

How to Execute Binary Files in Linux

Binary files or bin files are executable files in the operating system also known as non-text files. These files can contain anything in it like images, compiled files, metadata, chain of sequential bytes or a text file having encoded binary data.

In Linux and Unix-like operating systems, .bin files contain machine code in it and can be executed on the system. All the data encoded in binary files cannot be readable by humans. These files can store anything except text.

How to Execute Binary Files in Linux:

To execute a binary file in a system, all you need to do is work as a super user with all privileges and permissions.

To run binary files on a Linux system, we need to make it executable by accessing them using a terminal. It can be done by following 3 steps.

    1. Open the command-line prompt by pressing ctrl+alt+t.
    2. The next step is to run without giving permission.

    Now, the file is ready to run on Linux system, again open the terminal and type the command:

    In this file doesn’t open and shows permission denied message, use sudo in command and run it again:

    Conclusion

    The .bin files are the binary files that contain information to be executed in a system. They are encoded with machine code and cannot be readable. The article has shown how we can make binary files executable by giving them permission. These files cannot be executed without permission access and sudo privileges.

    About the author

    Syeda Wardah Batool

    I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.

    Источник

    How to Execute .bin and .run Files in Ubuntu

    How to start bin and run files on Ubuntu

    How to start bin and run files on Ubuntu

    Before we explain how to run .bin and .run files on your Ubuntu system, let’s first define what exactly these file extensions are:

    Bin file: A binary or BIN file in Ubuntu refers to installation packages, which are mostly self-extracting executable files used to install software on your system. You can install most software packages through the Ubuntu Software Manager, such as .deb packages and .tar.xz packages. However, there is software that is not available in these formats. This mainly includes newer software and newer versions of software, usually beta versions, that are not otherwise available. The bin packages are simply run from the Ubuntu command line, the terminal.

    Run File: These are also executable files typically used to install Linux programs. Run Files contain program data and instructions for installation; they are often used for distributing device drivers and software applications. Run packages are easily executed from the Ubuntu command line, the terminal.

    In this article, we will explain how to run/execute the files with .run and .bin extensions on Ubuntu Linux.

    We have run the commands and procedures mentioned in this article on an Ubuntu 22.04 LTS system. We will use the Ubuntu command line, the terminal, to explain how to run bin and run files. You can open the terminal application either by searching in the system application launcher or by pressing Ctrl+Alt+T.

    Note: Make sure that your .run and .bin files are from a reliable source, because running an unsafe file can damage your system and even compromise your system security.

    Executing .bin and .run files

    The process of running both the run and BIN files is pretty simple and straightforward in Ubuntu.

    We are assuming that you have already downloaded your bin/run file in a known location on your Ubuntu.

    Open the Terminal application and move to the location where you have saved the executable file.

    For example, I would use the following command to move to my Downloads folder:

    Go to the Downloads folder

    Now use the following command to make your .bin/.run file executable:

    In this example, I will be making a sample .run file named samplefile.run executable.

    If your .run/.bin file does not exist in the current location, you can specify the exact file path/location in the above commands.

    Make .run file executable

    My file is now marked as executable. The system indicates it by a change in color of the filename when listed through the ls command:

    Check file permissions

    Once your .bin/.run file has become executable, you can use the following command to execute/run it:

    You can specify the path of the executable file in the above command if it does not exist in the current folder you are in.

    Execute .run file

    My sample file is pretty much an empty file. In the case of a proper installation package, the installation process will begin after you execute the file.

    This is the power of the Ubuntu command line. You can install rare software packages available in the .run and .bin formats easily on your system.

    About This Site

    Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.

    Latest Tutorials

    Источник

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