What is Binary

 

A binary typically refers to compiled executable files or programs that the system can run directly. These binaries are written in Binary code (machine code) that the operating system's processor can understand and execute without further translation. They contrast with scripts or source code files, which require an interpreter or compiler to be run.

Types of Binaries


Executable Binaries:

  • These are compiled programs, usually in ELF (Executable and Linkable Format) on Linux System, and can be run directly by the operating system.

  • They are stored in directories such as /bin, /usr/bin, /sbin, and /usr/local/bin.


Library Binaries:


  • Library files, typically with .so extensions (e.g., libc.so), contain shared code that can be used by multiple programs. They are found in directories like /lib, /usr/lib, and /usr/local/lib.

  • These are dynamically linked at runtime to executable binaries that require them, helping save memory and disk space.


Kernel Binaries:


  • The Linux kernel itself and its modules are compiled binary files.

  • They reside in directories such as /boot and /lib/modules.

Common Characteristics of Binaries in Linux

  • Binary Format: Most Linux binaries are in the ELF format, which includes information such as sections, headers, and program data required for execution.

  • Permissions: Binaries need to have execute permissions to run.

  • Path Execution: Binaries in the system PATH (e.g., /bin, /use/bin) can be executed without specifying the full path, while others need an absolute or relative path.



Using Binaries in Linux

  • Running Binaries: If a binary is located in a directory that's part of the PATH environment variable, you can simply type its name in the terminal.


$ ls 


  • For binaries outside of the PATH, specify the full path:


$ /home/usr/scripts/program_name

Inspecting Binaries:


  • Use file command to determine the file type

$ file /bin/ls

  • Use ldd command to list shared libraries required by a binary

$ ldd /bin/ls


  • Use strace command to trace system calls and signals received by a binary

$ strace /bin/ls 

Locating Binaries:


  • Use which command to find a binary's path
    $ which ls


  • Use whereis command to locate binaries, source files, and manuals
    $ whereis ls 


Binaries are fundamental in Linux for running everything from core system programs to user applications. They form the backbone of system operations by offering efficient, precompiled code that the system can execute immediately.