Opening bin 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.

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?

Читайте также:  Clone linux to vmware

Источник

How to open .bin file using terminal in linux

Note: I don’t know the size of file and name of the file as well but it’s a binary file, I mean the user can change the binary file at terminal it should work for all the number of binary files he check for output. Solution: First of all you should read from file opened in binary mode with where should be defined as and used as The second important point is reading from file for more than one number — you need loop that is controled by condition that check stream.

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.

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.

If your .bin file is an installer/executable, then follow these steps:

  1. Open your terminal and go to ~$ cd /Downloads (where ~/Downloads is the folder where you bin file is)
  2. Give it execution permissions (just in case it doesn’t have it already):
    ~/Downloads$ sudo chmod +x filename.bin
  3. 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).

where is your text editor and is the file name

Remember to navigate to the folder first

to be honest i’ve got the same issue many many times i’ve downloaded some files.bin , however the only best solution that i’ve done is to extract the file.bin from windows vmware , you just need to set the share network from windows vmware to linux machine and extract it with winearchiver software to linux as you are connect to the share folder , even if you use chmod 755 file.bin and then ./file.bin , it won’t works generally speaking , i am talking as linux user and not windows user , however in some cases combine the solution with windows vmware in order to solve quickly the problem rather than rubbish solutions that won’t work .

Читайте также:  Просмотр прав файла linux

6 years later. I hope it’ll be useful.

losetup -f —show «/path/to/filename.bin» LOOP=$$(losetup | grep «filename.bin» | cut -d ‘ ‘ -f1) kpartx -l $LOOP | cut -d ‘ ‘ -f1 mount -v /dev/mapper/loop0p1 /mnt/

How to open . files with terminal Code Example, open file command line. open file from comand line mac. open file from terminal ,a. open file in application terminal. open file from terminal command …

How to read a binary file given as input at terminal in c#

I am new to c# and trying to read a binary file. I do so in c++ like this :

int main(int argc, char * * argv) < FILE * fp; fp = fopen(argv[1], "rb"); //argv[1] because while executing at terminal the binary file to be read is at second postion like "./filename.c BinaryInutFile.bin" so at argv[0] we have ./filename.c and at argv[1] we have Binaryfile.bin ch = fgetc(fp); while (fread( & ch, sizeof(ch), 1, fp)) < add_symbol(ch); //this add_symbol()i will use somewhere else, so not so important for now. >fclose(fp); > 

So i want help in writing equivalent c# code.Thanks to the helpers. Note: I don’t know the size of file and name of the file as well but it’s a binary file, I mean the user can change the binary file at terminal it should work for all the number of binary files he check for output. And i will execute at terminal like this «mono filename.exe BinaryFile.bin» where filename.exe is the file which was formed by compiling the filename.cs (by doing «gmcs filename.cs») which contain this code and BinaryFile.cs will be the bbianry file to be tested on my code and «mono» i have used because i am working on Ubantu and i compile using «gmcs FileName.cs» which will give Filename.exe and then execute it as «mono filename.exe BinaryFile.bin»

There are lots of ways to read a file in C#. If you want a stream approach it looks like:

public static void Main(string[] args) < // your command line arguments will be in args using (var stream = new BinaryReader(System.IO.File.OpenRead(args[0]))) < while (stream.BaseStream.Position < stream.BaseStream.Length) < // all sorts of functions for reading here: byte processingValue = stream.ReadByte(); >> > 

If you are processing a smaller file, there is also the option of reading the entire file into memory (string variable) with the following call:

string entireFile = System.IO.File.ReadAllText(fileNamePath); 

Either works well — the use is going to depend on your situation. Best of luck!

EDIT — Edited the example to include a main routine so that could be demonstrated. To use this example you need to create a «console application» project and build using either visual studio or using the command line (MSBuild or equivalent). Hope that sets you on the right track!

Open file in finder from terminals Code Example, #With the command «open + the file you want to open» you open the file you choose in the Finder open

How to open and read a binary file in C++ by a given bin file?

Is there anyone could help me to check where I did wrong? Or explain why? I am a beginner and I tried my best to open the binary file. But it just runs out «file is open» «0». Nothing came out.

The objective: The Count3s program opens a binary file containing 32-bit integers (ints). Your program will count the number of occurrences of the value 3 in this file of numbers. Your objective is to learn about opening and accessing files and apply your knowledge of control structures. The name of the file containing data used by the program is «threesData.bin».

Читайте также:  Linux compressing file system

my code as below, please help me if you know it. Thank you in advance!

#include #include using namespace std; int main() < int count=0 ; ifstream myfile; myfile.open( "threesData.bin", ios::in | ios :: binary | ios::ate); if (myfile) < cout else cout

First of all you should read from file opened in binary mode with

where buffer should be defined as

The second important point is reading from file for more than one number - you need loop that is controled by condition that check stream. For example:

 while (myfile.good() && !myfile.eof()) < // read data // then check and count value >

And the last thing, you should close file, that was successfully oppened, after you finished reading:

 myfile.open( "threesData.bin", ios::binary); if (myfile) < while (myfile.good() && !myfile.eof()) < // read data // then check and count value >myfile.close(); // output results > 

1) int is not always 32-bit type, so consider using int32_t from ; and if your data has more than 1 byte, may be byte order is important, but it was not mentioned in the task description

2) read allows reading more than one data object per one call, but in that case you should read to array instead of one variable

3) read and try examples from references and other available resources like this.

Источник

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.

  1. Open your terminal and go to ~$ cd /Downloads (where ~/Downloads is the folder where you bin file is)
  2. Give it execution permissions (just in case it doesn't have it already):
    ~/Downloads$ sudo chmod +x filename.bin
  3. 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).

Источник

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