Bitness:- File in Linux

Background

One of the great technical leaps in IT Technology in the last 20 years or so, is the co-existence of 32 and 64-bit computing on the same machine.

Linux

If you are curious as to whether a binary file is 32 or 64-bit and you are on a Linux machine, please use the file command.

 

File Command

Syntax


file <file-name>

Sample

32-bit file

Command


file bin/x32/helloWorld_x32.exe

 

Output

Output – Text

bin/x32/helloWorld_x32.exe: PE32 executable (console) Intel 80386, for MS Windows

Output – Image

64-bit file

Command


file bin/x64/helloWorld_x64.exe

 

Output

Output – Text

bin/x64/helloWorld_x64.exe: PE32+ executable (console) x86-64, for MS Windows

Output – Image

 

Summary

If 32-bit, the file command will return:-

  1. PE Flag:- PE32
  2. Console/GUI:- console
  3. Processor:- Intel 80386
  4. OS:- MS Windows

On the other hand, If the fie is compiled for 64-bit, the file command will return:-

  1. PE Flag:- PE32+
  2. Console/GUI:- console
  3. Processor:- x86-64
  4. OS:- MS Windows

 

Disclaimer

So you are on a MS Windows machine and you compiled your application using Visual Studio.

The executable runs well on a Windows machine.

Take same application to a MS Windows and try to run as is.

But, not so quick.

Make file runnable


chmod +x bin/x64/helloWorld_x64.exe

Run Command


bin/x64/helloWorld_x64.exe

Output

Textual


-bash: bin/x64/helloWorld_x64.exe: cannot execute binary file: Exec format error

Image

 

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s