1.2 Programs and Files
Prerequisites: The Basic Structure of a Computer
Estimated time: 8–12 minutes
You are ready to continue when: you can explain the relationship between files, paths, and programs, and identify the format of an executable file on your native system.
A program file can be saved, copied, and distributed, but it does not execute itself. It records bytes for a machine or interpreter to read. To separate a program from a process, first define a file precisely.
Files Are Not "Names Plus Content"
A regular file contains bytes and metadata. Metadata commonly includes size, permissions, owner, and timestamps. Paths allow programs to find files, and the path text is not part of the file's content.
In a Unix file system, directory entries associate names with file objects. The same file object can have multiple hard-linked names:
workdir=$(mktemp -d)
printf 'atlas\n' > "$workdir/original.txt"
ln "$workdir/original.txt" "$workdir/second-name.txt"
ls -li "$workdir/original.txt" "$workdir/second-name.txt"
rm -rf "$workdir"Type: runnableEnvironment: Linux or macOS, Bash Observation: The inode numbers of the two lines are the same, indicating that the two names on the same file system point to one file object. Hard links cannot cross file systems; equal inode numbers on different file systems do not identify the same file. Windows' NTFS also supports hard links, but the commands and permissions differ.
"Everything is a file" is the interface style of Unix: devices, pipes, and parts of process information can be accessed through interfaces similar to files. Processes, network connections, and windows are not therefore transformed into ordinary disk files.
Programs May Span Multiple Files
A program contains executable instructions and related data. It may be:
- Native executable files such as ELF, PE, or Mach-O;
- Scripts readable by interpreters such as Bash or Python;
- A set of files comprising Java bytecodes, JARs, shared libraries, configurations, and resources;
- macOS application packages or installation directories.
Thus, the statement "a program is just a machine code file" applies to only a portion of programs.
View File Format
file -L /bin/ls
file -L "$(command -v python3)"Type: runnableEnvironment: Linux or macOS with file installed Observation: -L follows symbolic links before determining the target format. On Linux, the common format is ELF; on macOS, it's Mach-O. Architecture, dynamic linker, and debugging symbol details depend on the local executable.
Windows PowerShell can first run:
Get-Command python | Format-List Source,CommandTypeThis will locate the command source, but it cannot fully parse the PE file structure. Do not treat the Linux ELF output as a cross-platform expected result.
Clarify Three Things
Before moving on from this page, try explaining to someone else: how paths locate files, what the difference is between file content and metadata, and why an interpreter can execute a Python script even though the script is not native machine code. Save the output of file -L for python3; the next page uses that executable.
Processes and Memory will bring this static program to life.