Unix Executable File Explained: How Programs Run
Unix executable file basics: see how execute permissions and ELF or shebang headers determine whether a program runs, then inspect it with terminal tools.

tl;dr the short answer
A Unix executable file is a file the system can launch, either as machine code in a format such as ELF or as a script whose shebang names an interpreter. Running it requires execute permission, a format and CPU architecture the system supports, and any needed interpreter or libraries; tools such as `file` and `readelf` can inspect it without launching it. Check a file before granting permission or running it, because its executable status does not prove it is safe.
Ever typed a script name and got “Permission denied”? On Unix-like systems, a file is runnable when it has the execute permission and its first bytes match a format the kernel understands. There’s no magic here, and you can check both yourself.
This post walks through the ELF (Executable and Linkable Format) that most compiled programs use, plus shebang scripts that start with a line like #!/bin/bash. We’ll also cover the Linux terminal tools that reveal what’s really inside.
What Makes a Unix Executable File Runnable
Unix is a family of operating systems built on small, cooperating programs, and Linux and macOS follow that design. Here’s how the system decides, and how we can check each step.
Setting execute permission and finding programs
Files carry permission bits, and the execute bit decides whether anything runs. Set it with chmod +x and clear it with chmod -x, then confirm with ls -l, and check the type with file.
The shell searches your PATH folders in order and runs the first match, so where a file sits matters as much as its name. Use which backup to see the winner. If it isn’t on PATH, use an absolute path or a ./ prefix.
A student with a backup script in ~/Projects can move it into ~/.local/bin, a folder many Linux setups already put on PATH, and run it anywhere. A noexec mount blocks execution even when the bit is set, a safety layer worth knowing.
Why executables need no file extension
No extension is needed on Unix. A compiled binary holds encoded instructions the CPU runs directly, with no .exe tag. The compiler sets the execute bit, and that permission metadata marks it runnable.
A photo is bytes an app interprets, but a binary is bytes the CPU executes.
How CPU family and ABI shape executables
Machine code is tied to a CPU family, so x86-64 instructions (Intel and AMD) won’t run on an ARM chip. Copy one to an ARM board and you’ll see an Exec format error.
The application binary interface (ABI) defines calling conventions (the rules for passing arguments), and system calls are essential: they’re how programs ask the kernel for files and network access.
A 32-bit program needs support on a 64-bit machine, and the x32 ABI pairs 64-bit instructions with 32-bit pointers. A fat binary bundles several machine-code versions so the right one runs.
What is an example of an executable file?
Two kinds are common:
- Native binary executables. Compiled machine code, usually stored as an ELF (Executable and Linking Format) file on Linux, like
lsorgrep. - Text executables. Scripts run by an interpreter, a program that reads source code. The first line is a shebang (
#!) naming that interpreter, such as#!/bin/bash.
The launcher needs contents it can make sense of. A missing interpreter or Windows-style line endings break that first line. Get it right, and the script runs. Get it wrong, and nothing does.
The ELF Format Most Unix Programs Use
Most compiled programs on Unix-like systems share one layout, the Executable and Linkable Format (ELF). Learn to read it, and a mystery binary becomes a list of facts.
What ELF files are used for
ELF covers executables, shared libraries, object files (compiler output before linking), and core dumps (the memory snapshot a crashed program leaves behind). It describes the layout of a file, not the program inside it.
Other operating systems use their own formats, so ELF isn’t universal. It’s extensible and widely adopted, so you’ll meet it on nearly every Linux system. A Windows exe file is one such format, and our guide on how to run exe on linux covers it.
Spotting ELF files by their first bytes
Every ELF file starts with the same four bytes, 7f 45 4c 46. The last three spell ELF in ASCII. Dump them with a hex viewer such as hd or hexdump -C:
hexdump -C ./hello | head -n 1
- Hex viewers show the raw bytes so you can check the signature.
readelfparses the header and rejects non-ELF files, a quick type check.
The signature tells you what a file is, not whether you should trust it.
Reading the fields in an ELF header
Run readelf -h on a binary to see the key fields:
- Class: whether the program is 32-bit or 64-bit.
- Data: byte order, little-endian or big-endian.
- Machine: the CPU architecture it was built for.
- ABI: the application binary interface (ABI) it targets.
The entry point is the address where execution begins. It’s usually startup code that later calls main, so the entry point is not main. Header offsets point to the tables describing the file’s segments and sections.
Type is EXEC for fixed-address programs or DYN for shared objects and position-independent executables (PIE).
Say you’re a homelabber who grabbed a single-file tool for a Raspberry Pi, and it won’t start. If its Machine line says x86-64 and your board is ARM, you have your answer: you need a different build.

Build IDs, signatures, icons and comments
Extra metadata can ride along:
- Build IDs: a unique ID in a note section that helps match a binary to its debug symbols.
- Code signing: signatures come from tools or distributors, not the base ELF layout.
- Embedded icons: not a standard field, so they appear only when a tool stores one.
- Comments: compilers often record their version in a
.commentsection.
Metadata helps you investigate, but it doesn’t prove a file is safe.
Tools for Looking Inside Executables
Most of these tools read a binary without running it. Reading is the safe way to start.
Reading headers and sections with readelf
readelf prints the parts of an ELF (Executable and Linkable Format) file:
-hshows the ELF header, such as file type and target machine.-llists segments, the chunks the loader maps into memory.-Slists sections, named pieces like code and data.-slists symbols, the names of functions and variables.-dshows the dynamic section, naming the shared libraries needed.
Think of a homelabber whose copied binary won’t launch on a new server. Running readelf -d on it lists the libraries it wants, so they can install the missing one.
Disassembling code with objdump
objdump turns machine code back into readable assembly.
-ddisassembles code sections.-M intelswitches to Intel syntax instead of the default AT&T style.-Sinterleaves source code with the disassembly, when debug info exists.-Rshows dynamic relocations, the spots the loader fixes at runtime.
Other handy tools for checking binaries
- file identifies what you’re holding, like an ELF executable or a shell script.
- nm lists symbols, and strings pulls out readable text such as paths and error messages.
- ldd lists shared library dependencies, but it can actually run untrusted binaries. Never point it at a file you don’t trust. Read first.
- lddtree (from pax-utils) prints the same dependencies as a tree. Reach for
readelf -dinstead when you’re unsure. - size reports section sizes, and hexdump (also hd on some systems) shows raw bytes.
- elfutils offers its own ELF readers, and pyelftools is a Python library for scripting checks.
How Programs Are Compiled, Linked and Loaded
Several stages turn your source into a running program, and each leaves its mark. Knowing them helps when a build or a copied binary misbehaves.
From source code to a linked program
Your compiler turns each source file into an object file, machine code with gaps still to fill. The linker then joins those objects, pulls in the libraries they call, and produces the executable you run.
Both use ELF (Executable and Linkable Format), but an object file is unfinished while an executable is ready to run.
Choosing between dynamic and static linking
Shared libraries are stored once on your system, and many programs use the same copy. Static linking copies the library code into your binary instead, so the program carries what it needs.
Dynamic linking saves disk space, while static linking buys portability. Static builds also sidestep dependency hell, the tangle of mismatched library versions. Dynamic linking is often the default, so static linking is a choice you make on purpose.
Say you build a tool on your Arch laptop and copy it to an older Debian server. A dynamic build may fail there if its libraries don’t match, but a static build carries its own and runs.
How the dynamic loader finds needed libraries
A dynamic program’s ELF file has an INTERP entry naming the dynamic loader (usually ld-linux). The kernel starts that loader first.
The loader reads the NEEDED entries, which list each shared library the program requires, and resolves them by finding each one on your system. That NEEDED list is the first place to look when a library goes missing.
How the Loader Reads Program Segments
The loader reads a short list of segments, each with its own memory rules. Here’s how we’ll read that list.
Common segment types and what they do
The program header table has one entry per segment. These matter most:
- PHDR describes the program header table itself.
- INTERP names the dynamic loader, which links shared libraries.
- LOAD entries are file chunks copied into memory.
- DYNAMIC holds data the dynamic loader needs.
- NOTE stores small metadata like build IDs.
- TLS (thread-local storage) is the template for per-thread variables.
- GNU_EH_FRAME points to unwinding tables used for exceptions.
- GNU_STACK maps nothing; it says whether the stack may run code.
- GNU_RELRO marks memory locked read-only after startup linking.

Setting read, write and execute on segments
Each LOAD segment carries permission flags: R (read), W (write), and E (execute), which the loader applies to its memory.
Offset marks where bytes sit in the file, VirtAddr where they land in memory, and Align the boundary they must honor.
Code is usually R and E, data is R and W, and good builds keep them apart, so a write bug can’t easily produce runnable code.
Memory is mapped in whole pages, usually 4,096 bytes, so the file offset and memory address must line up within a page.
Consider a Raspberry Pi user whose build crashes at startup. Running readelf -l shows the bad segment in seconds.
Why memory size can exceed file size
Each entry lists FileSiz (bytes in the file) and MemSiz (bytes needed in memory). Extra MemSiz bytes are zero-filled.
Usually that gap is .bss, which holds zeroed global variables, so the file only records its size.
Loading creates runtime state: the loader maps pages, zeroes the gap, and fixes up addresses. The file says what to copy, but the loader decides how much memory exists at launch.
The file is only a blueprint.
How sections map into segments
Sections serve the linker and debugging tools, while segments serve the loader. One segment usually holds several sections with matching permissions.
Run readelf -l ./hello to see it. The program headers print first, then a Section to Segment mapping table lists each segment’s sections.
That’s a quick way to confirm .data landed in a writable segment.
Working with Sections, Symbols and Stripping
Sections and symbol tables are where you look when a binary misbehaves, and they’re what stripping takes away.
Common sections you’ll see most often
.textholds the machine code..rodataholds read-only data, like string constants..dataholds initialized, writable data..bssholds zero-initialized data that takes no space in the file..dynsymand.dynstrhold the dynamic symbol table and its strings, used to find shared library functions at load time.- Debug sections start with
.debug_and hold file names and line numbers.
Section sizes add up to the file size, give or take headers and padding. Run readelf -S ./hello to see yours.
Why sections and segments aren’t the same
Segments map the file into memory for the loader, asking where each piece goes. Sections serve the linker and analysis tools, asking what each piece is. One segment can hold several sections, so they aren’t synonyms.
Consider a packager shrinking a binary: sections show what’s big, while segments show what actually loads.
What symbol and string tables hold
The symbol table lists names for functions and data, plus the addresses they live at. Each name sits in a companion string table. When the linker combines object files, it matches each call to its definition and fills in the address.
Stripping removes the symbol table, so you lose the names but not the code. Stripped is not encrypted. A disassembler can still read every instruction, just without the labels.
A sysadmin on a shared server gets a crash report of bare addresses from a stripped vendor binary. Running nm ./vendor-tool reports no symbols, so they hunt for an unstripped build to map those addresses back to function names.
What Happens When an Executable Runs
Running a program is a handoff. Your shell calls execve, the system call that asks the kernel to start a file, and the kernel does the rest.
What the kernel loader does on execve
Native programs are ELF (Executable and Linkable Format) files, and the kernel works through these steps in order:
- Maps the program. Code and data get placed into memory.
- Validates permissions and memory. It checks that you can run the file and that the memory setup is sound.
- Copies arguments to the stack. Your arguments and environment variables go onto the new process’s stack.
- Initializes registers. The processor’s registers get their starting values.
- Jumps to the entry point. Control moves to the first instruction, and your code finally runs.
The kernel’s binfmt_misc feature (miscellaneous binary formats) lets you register a handler for a foreign format, so the kernel passes that file to an interpreter.
Picture a developer with a binary built for a different processor: they register an emulator as the handler, and the file just runs.

Random load addresses with ASLR and PIE
ASLR (address space layout randomization) shuffles where the stack, heap, and libraries load, so attackers can’t predict addresses.
The program’s own code joins in only when it’s built as a PIE (position-independent executable), which can run from whatever address the loader picks. A non-PIE binary loads at the same spot every time, but a PIE gets a different one each run.
Say you’re a student on a ten-year-old ThinkPad, and your crash log shows a new address every run. That’s ASLR doing its job, so you can stop hunting for a bug that isn’t there. Same program, different address. That’s the point.
Running Shell Scripts as Executables
Here’s how we make a script runnable, handle its arguments, and track down what breaks.
How a shebang line picks the interpreter
The first two characters, #!, are a shebang (a magic number the system checks for). The path after it names the interpreter, like #!/bin/sh, and the kernel hands your file to that program.
Your file also needs execute permission: run chmod +x backup.sh once, then start it with ./backup.sh. No permission, no run.
Writing shell scripts and handling arguments
A script is a sequence of commands the shell runs top to bottom. Arguments become positional parameters: $1 is the first argument, $2 the second, and $* holds them all for looping.
Quoting trips people up. A homelab tinkerer runs ./backup.sh "My Photos", but an unquoted cp -r $1 /backup/ splits the name, so the copy fails. Writing cp -r "$1" /backup/ keeps it whole.
Quoting changes how the shell reads a value, not the value itself. Always quote your parameters.
Tracking down bugs in your scripts
Don’t rewrite the whole thing. Work through these three steps:
- Isolate the problem. Run one command at a time until you find the smallest piece that still breaks.
- Add echo output. Print variables and checkpoints, like
echo "copying $1", to see what the script believes is happening. - Trace with
sh -x. Runsh -x backup.shto print each command with a+prefix, showing what the shell actually ran, not what you meant.
Print it, trace it, fix it.
How Unix Executable Formats Changed over Time
Unix never kept one executable format forever. The swaps were less about features and more about limits, and we’ll trace each one.
The oldest Unix format, called a.out
The a.out format is the oldest Unix executable format. Ken Thompson named it, and the name is a clue to its origins: the File Formats reference explains that a.out is short for “assembler output.” It’s also the default output name.
When no output name is given, the assembler and the C compiler write to a file called a.out. Each file is built from seven sections, and the format came in several variants.
The BFD documentation says those variants differ mainly in structure sizes on disk and in the shape of their relocation information, the data that adjusts addresses at load time.
The COFF format that replaced a.out
In System V, COFF (Common Object File Format) took over from a.out. A case study in software portability describes the a.out file in System V.2 as COFF and says the format was uniform across those implementations.
COFF added more sections than a.out, which gave debuggers more to work with. But COFF was limited, so vendors extended it in their own directions.
Which operating systems adopted ELF
ELF (Executable and Linkable Format) is the format you’ll meet on Linux, and it’s shared well beyond it. Linux made the switch after kernel 1.2, and FreeBSD, OpenBSD, NetBSD, and Minix adopted it too. Game consoles use it as well.
A Breakpoint explainer on AnyPS5 notes that a PS5 executable is an ELF, the same family Linux uses, just stamped for Sony’s operating system.
How macOS uses Mach-O binaries
macOS uses Mach-O, its own executable format, and its signature trick is the fat binary: one file that carries machine code for several CPU families. Think of a student who buys a new Mac with a different chip and wants an app to keep running.
The fat binary already holds code for each family, so nothing needs rebuilding. One file, several chips.
Once you know the two checks, runnable files stop feeling like magic. The execute bit tells the system it may launch a file, and the file’s first bytes tell it how.
ELF binaries and shebang scripts follow the same logic, and the terminal tools we covered let you verify each step.
Before you chmod +x a file you downloaded, run file on it and read what it does. Check first, and you’ll never get caught off guard by a file.
References
- A CASE STUDY IN SOFTWARE PORTABILITY: THE UNIX? SYMBOLIC DEBUGGER — dl.acm.org (1985)
- GTA 6 on PC before Rockstar ports it? How AnyPS5 relinks PS5 games with no emulator — trybreakpoint.com (2026)
- a.out file format: the original Unix executable — fileformats.org
- aout (Untitled Document) — sourceware.org
Questions
What is an example of an executable file?
Examples of executable files include the compiled Unix programs `ls` and `grep`, commonly stored as ELF binaries on Linux. A shell script with a shebang line, such as `#!/bin/bash`, can also be executable when it has execute permission.
What exactly is Unix?
Unix is a family of operating systems built around small programs that work together. Linux and macOS are Unix-like systems that follow many of its design principles.
Sources
- a.out file format: the original Unix executable · File Formats, fileformats.org
- aout (Untitled Document), sourceware.org
- A CASE STUDY IN SOFTWARE PORTABILITY: THE UNIX? SYMBOLIC DEBUGGER, dl.acm.org,
- GTA 6 on PC before Rockstar ports it? How AnyPS5 relinks PS5 games with no emulator | Breakpoint, trybreakpoint.com,


