Execute linux executable file

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.

Читайте также:  Rsa public key linux

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

Читайте также:  Linux размер swap раздела

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

Источник

How to make a file (e.g. a .sh script) executable, so it can be run from a terminal

I have a script.sh file and type of this file is shellscript file. I want to make this file as application/x-executable file. How can I make it?

It is not a duplicate, because I have asked specifically about making it application/x-executable. The other question just asks for opening sh file in terminal.

4 Answers 4

You can mark the file as executable:

You can then execute it like this:

If you want to use a different command to start it, you can add an alias:

Add this at the end of the file:

Open a new terminal session or type source ~/.bashrc in your terminal to apply. Then simply use the new name to start the script.

Do you know how to use sudo command after entering the command as: «alias command1 = ‘/home/user_name/dir/script.sh’. In mine, it works without sudo, but not with it.

@user1993 Generally, using ./filename.sh specifies a file in the current directory and using filename.sh specifies a file in the current directory or any directory of PATH. The first usage removes any uncertainty as to which file is accessed. In this case, you are attempting to execute the script with bash or another interpreter (by virtue of assumed #!/bin/bash as first line in your script) just by entering the filename. This usage requires the directory is specified. Alternatively, you can try bash filename.sh which seems to work with unspecified directory.

There are two ways of making a file executable:

Right-click the file and select Properties. Go to the permissions tab, then tick the box Execute: [ ] Allow executing file as program or in Nautilus Program: [ ] Allow this file to run as a program in Thunar.

Читайте также:  Linux remap bad sectors

enter image description here

Terminal / Command method:

chmod +x filename.extension

chmod +x /path/to/your/filename.extension

chmod does also have some more advanced options:

The spaces are to show that it is split up: — rwx — —

The first set of — is User. The second is Group and the last is Other (anyone else)

r stands for Read, w for Write and x for eXecute.

So to allow everyone to read it, but only Group to execute and User to read and write it (but for some reason not execute) would be:

-rw- rx- r— But this would be added to the command as:

chmod +rw-rx-r— /path/to/file.extension

chmod also can do this in numbers. It is based on binary (I think, as it is 1,2 and 4)

So there are these numbers:

Execute by user is 100 . Execute by group is 010 . Execute by other is 001 .

Write by user is 200 . Write by group is 020 . Write by other is 002 .

Read by user is 400 . Read by group is 040 . Read by other is 004 .

Then you add these together to get the desired combination.

So to allow everyone to read it, but only Group to execute and User to write it (but for some reason not execute) would be:

400 + 040 + 004 and 010 and 200

That adds up to 600 + 050 + 004 = 654.

You could then run the command.

chmod +654 /path/to/file.extension to set it.

And to set all permissions you can type:

chmod +rwxrwxrwx /path/to/file.extension

Or (this is a bit easier to write, but harder to remember each one):

chmod +777 /path/to/file.extension

chmod -777 /path/to/file.extension

To take all permissions away from everyone.

chmod +300 /path/to/file.extension

To add read and write for user, without affecting any other permissions (e.g. Execute permissions).

This website has a very useful little grid checkbox thing, whereby you can tick the options you want and it gives you the command:

enter image description here

However, not all the possible combinations are sensible to use; the main ones that are used are the following:

755 — Owner has all, and Group and Other can read and execute

644 — Owner can read and write, and Group and Other can read

600 — Owner can read and write

And, if you’re using non-trivial user groups:

775 — Owner can read and write, and Group and Other can read

770 — Owner and Group have all, and Other can read and execute

750 — Owner has all, and Group can read and execute

664 — Owner and Group can read and write, and Other can just read

660 — Owner and Group can read and write

640 — Owner can read and write, and Group can read

777 and 666 are rarely used, except in /tmp.

Thanks Ilmari Karonen for pointing out the ones in common usage!

Источник

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