- How to run binary file in Linux
- 13 Answers 13
- how to open .bin file using terminal in linux
- 5 Answers 5
- How to Run .bin Files in Linux?
- Method 1: How to Run .bin Files in Linux via CLI?
- Step 1: Change the .bin File Permissions
- Step 2: Run the .bin Files
- Method 2: How to Run .bin Files in Linux via GUI?
- Step 1: Open the “.bin” file Properties
- Step 2: Change the “.bin” File Permissions
- Step 3: Execute the “.bin” file
- Conclusion
- How to view a binary file?
- 11 Answers 11
- Update
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.
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 open .bin file using terminal in linux
I have one .bin file.in that file some data which is important for me and and i want to open that file by using terminal so please help me.I have not any software for that. so give me and command.
.bin files or .run files are usually, in my experience, self extracting shell scripts. Where did you get this from? What’s the name? What is it supposed to contain?
do you want to open (read) it or run it? call file my.bin , see if its a shell script and then run it with sh my.bin . i hope the source of the file is trustworthy!
5 Answers 5
You have to be sure of what you’re downloading (because a .bin file extension is also used for CD/DVD images and backups). Check with the «provider» (Web Page, CD/DVD instructions, etc. ) of the file that it can be executed as a program.
A binary file is a computer file that is not a text file. The term «binary file» is often used as a term meaning «non-text file». Many binary file formats contain parts that can be interpreted as text; for example, some computer document files containing formatted text, such as older Microsoft Word document files, contain the text of the document but also contain formatting information in binary form.
- Open your terminal and go to ~$ cd /Downloads (where ~/Downloads is the folder where you bin file is)
- Give it execution permissions (just in case it doesn’t have it already):
~/Downloads$ sudo chmod +x filename.bin - Write: ./ followed by the name and extension of your bin file. In this example it would be: ~/Downloads$ ./filename.bin
- If filename.bin needs administrator priviledges to be executed (like an installer would), write ~/Downloads$ sudo ./filename.bin and type your password.
- ~/Downloads folder is only an example. You can place your bin file anywhere you feel comfortable (yes, even a USB Drive or a SDCard).
How to Run .bin Files in Linux?
The “.bin” files represent the “Binary files” in Linux. These files contain information like videos, images, metadata, and compiled files in a coded text format. Generally, these files do not have the permissions required for execution purposes. For running these files, Linux offers the “chmod” command to make them executable. Additionally, it can also be done by changing its permissions using GUI.
This post illustrates the possible ways to run Linux’s “.bin” files. The content of this post is specified below:
Let’s start discussing the methods to run .bin files in Linux.
Method 1: How to Run .bin Files in Linux via CLI?
Linux is a well-known operating system due to its productive commands. These commands perform different operations and functionalities. The whole system can be quickly accessed and managed by these commands. This section provides step-by-step instructions to run .bin files in Linux using the command line interface.
Step 1: Change the .bin File Permissions
First, change the permissions of the specific “.bin” file using the “chmod” command. Type the below “chmod” command in the terminal for making the “sample.bin” executable:
Step 2: Run the .bin Files
After changing the permissions of the above “.bin” file, execute the below command to start the installation and run the “.bin” file:
The result displays the output of the “sample.bin” file which is “This is the sample binary file.”
Method 2: How to Run .bin Files in Linux via GUI?
The user can also run the “.bin” file with the help of the graphical user interface. Follow the steps below to run the .bin file visa GUI
Step 1: Open the “.bin” file Properties
Open the directory where the desired “.bin” file is saved or downloaded. In our case, the file named “Lato-Regular.bin” is available in the “Downloads” directory:
Right-click on the file and choose the “Properties” option from the dropdown list:
The “Lato-Regular.bin Properties” window will be opened:
Step 2: Change the “.bin” File Permissions
Hit the “Permission” icon located in the menu bar of the “properties” window. Tick the highlighted checkbox “Allow executing file as a program”:
Step 3: Execute the “.bin” file
Now, double-click on the “.bin” file and install it:
That’s how bin files can be run on Linux.
Conclusion
The “.bin” files can be run by changing the permissions via the “chmod” Linux command and making them executable. Furthermore, it can also be done using the “Permissions” option available in the “Properties” window via GUI. Both methods are beneficial for performing this task. This guide has explained both the Command line and graphical user interface method to run the “.bin” files in Linux.
How to view a binary file?
From what I understand, a compiler makes a binary file that consists of 1’s and 0’s that a CPU can read. I have a binary file but how do I open it to see the 1’s and 0’s that are there? A text editor says it can’t open it. P.S. I have an assembly compiled binary that should be plain binary code of 1’s and 0’s?
no — OP specified «assembly compiled binary». That does not address the question. For instance, it’s not a music file, and it has structure. Without OP providing additional information, an unstructured tool is the place to start.
See my answer. And be warned that the term binary is used in two ways totally different in practice : «A binary file» means a file whose context is not pure ASCII-text. «A binary number» means a number written using its binary form.
You’re not going to get what you’re asking for. On a hard drive, the file is represented by magnetic changes. When the file is read, it’s turned into electrical pulses, which in turn are turned into binary by the processor. Binary itself is only a representation of a number as stated in the answers below. These numbers are then interpreted by the individual programs as the format expected by them, whether this is text or images or something different. You won’t see 1s and 0s by opening a binary file in nano.
11 Answers 11
unless you want to edit it of course. Most Linux distros have hexdump by default (but obviously not all).
Update
xxd does both binary and hexadecimal
For bin :
Various people have answered some aspects of the query, but not all.
All files on computers are stored as 1’s and 0’s. Images, text files, music, executable applications, object files, etc.
They are all 0’s and 1’s. The only difference is that they are interpreted differently depending upon what opens them.
When you view a text file using cat , the executable ( cat in this case) reads all the 1’s and 0’s and it presents them to you by converting them into characters from your relevant alphabet or language.
When you view a file using an image viewer, it takes all the 1’s and 0’s and turns them into an image, depending on the format of the file and some logic to work it all out.
Compiled binary files are no different, they are stored as 1’s and 0’s.
arzyfex’s answer gives you the tools to view those files in different ways, but reading a file as binary works for any file on a computer, as does viewing it as octal, or hex, or indeed ASCII, it just might not make sense in each of those formats.
If you want to understand what an executable binary file does, you need to view it in a way which shows you the assembler language (as a start), which you can do using,
which is a disassembler, it takes the binary content and converts it back into assembler (which is a very low level programming language). objdump is not always installed by default, so may need to be installed depending on your Linux environment.
NB: as @Wildcard points out, it’s important to note the files don’t contain the characters 1 and 0 (as you see them on the screen), they contain actual numeric data, individual bits of information which are either on (1) or off (0). Even that description is only an approximation of the truth. They key point is that if you do find a viewer which shows you the 1’s and 0’s, even that is still interpreting the data from the file and then showing you the ASCII characters for 0 and 1. The data is stored in a binary format (see the Binary number link above). Pierre-Olivier’s community wiki entry covers this in more detail.