
prelink Command in Linux
The prelink command in Linux prelinks ELF shared libraries and binaries to speed up the startup time of the programs. ELF-shared libraries are reusable code files in the Executable and Linkable Format (ELF) that multiple programs can share at runtime. These libraries reduce duplication by allowing programs to load and use common functions or resources without including them directly in the executable file.
The Linux prelink command works by precomputing some of the work that the operating system normally does every time a program starts.
Table of Contents
Here is a comprehensive guide to the options available with the prelink command in Linux −
- Installation of prelink Command
- Syntax of prelink Command
- prelink Command Options
- Examples of prelink Command in Linux
Note − While using the prelink command, the architecture is not supported error may appear. This error occurs when attempting to prelink on an unsupported architecture.
Supported Architectures −
- x86_64 (64-bit Intel/AMD)
- x86 (32-bit Intel/AMD)
Unsupported Architectures −
- ARM (ARMv7, ARM64)
- MIPS
- RISC-V
- PowerPC and other non-x86 architectures
Installation of prelink Command
By default, the prelink command may not install in Linux. To install the prelink command on Ubuntu, Kali Linux, Debian, and other Debian-based distributions, use the following command −
sudo apt install prelink
To install it on CentOS, use the following command −
sudo yum install prelink
To verify the prelink command installation, check its version −
prelink -V

Syntax of prelink Command
The syntax of the prelink command in Linux is as follows −
prelink [options] [files]
In the above syntax, the [options] field is used to specify various that modifies the behavior of the command. The [files] field is used to specify specific ELF binaries or shared libraries to prelink. One or more files or directories can be specified, and if omitted, the command can operate on all files as specified by certain options.
prelink Command Options
The options of the prelink command are listed below −
Flags | Options | Description |
---|---|---|
-v | --verbose | Verbose mode. Print assigned virtual address slots and prelinking status. |
-n | --dry-run | Don't prelink, just simulate and display actions. |
-a | --all | Prelink all binaries and libraries specified in /etc/prelink.conf. |
-m | --conserve-memory | Allow libraries to share memory slots unless used together. |
-R | --random | Start library address assignment at a random address to improve security. |
-r ADDRESS | --reloc-only=ADDRESS | Relink libraries to a specified base address without prelinking. |
-N | --no-update-cache | Skip saving the cache file after prelinking. |
-c CONFIG | --config-file=CONFIG | Use an alternate configuration file instead of /etc/prelink.conf. |
-C CACHE | --cache-file=CACHE | Use an alternate cache file instead of /etc/prelink.cache. |
-f | --force | Re-prelink all objects, even if dependencies are unchanged. |
-q | --quick | Use a faster method to check for unchanged files based on timestamps. |
-p | --print-cache | Display the contents of the prelink cache file and exit. |
--dynamic-linker=LDSO | Specify an alternate dynamic linker. | |
--ld-library-path=PATH | Specify a custom LD_LIBRARY_PATH for prelinking. | |
--libs-only | Prelink only shared libraries, not binaries. | |
-h | --dereference | Follow symbolic links when processing directory arguments. |
-l | --one-file-system | Limit directory processing to a single file system. |
-u | --undo | Revert prelinked binaries and libraries to their original state. |
-y | --verify | Verify if a binary or library is unchanged since prelinking. |
--md5 | Print the MD5 digest of a file instead of its original content. | |
--sha | Print the SHA1 digest of a file instead of its original content. | |
--exec-shield | Use kernel-supported Exec-Shield for memory layout adjustments. | |
--no-exec-shield | Disable Exec-Shield adjustments, overriding automatic detection. | |
-b PATH | --black-list=PATH | Exclude specified paths, libraries, or binaries from prelinking. |
-o FILE | --undo-output=FILE | Save original content during undo operation to a specified file. |
-V | --version | Display the version of prelink and exit. |
-? | --help | Show help information and exit. |
Examples of prelink Command in Linux
In this section, the usage of the prelink command in Linux will be discussed with examples −
Prelinking All Binaries and Libraries
To prelink all binaries and libraries, use the prelink command with -a or --all option −
prelink -a
The above command prelinks all binaries and their dependent libraries specified in /etc/prelink.conf with verbose output.
Prelinking All Binaries and Libraries with Verbose Output Enabled
To prelink all binaries and libraries, use the prelink command with -a or --all and -v or --verbose options −
prelink -av
Dry Running the Prelinking of Binaries and Libraries
To dry run the prelink process without making actual changes in the system, use the -n or --dry-run option −
prelink -nv all
This command performs a dry run on binaries and libraries in /usr/bin/ls, showing what would be prelinked.
Prelinking a Specific Binary
To prelink a specific binary and its dependencies, use the prelink command with the binary file name or path.
prelink -v /usr/bin/ls
Verifying the Prelinking
To verify the prelinking, use the -y or --verify option −
prelink -y /usr/bin/ls

The above command verifies the integrity of the specified file and prints the file content before prelinking if unchanged. If the exit status is 0, then the binary file is not modified.

If the exit status is 1 then the binary file has been modified.
Undoing Prelinking
To undo the prelinking of the binaries and libraries, use the -u or --undo option with the prelink command −
prelink -uv --all
To undo a specific binary, simply specify the path of the binary file.
Displaying the Contents of the Prelink Cache
To display the contents of the prelink cache, use the -p or --print-cache option with the prelink command −
prelink -p
The above command prints the number of objects prelinked.
Using the Custom Configuration File
By default, the prelink command uses the /etc/prelink.conf file for configuration. To use a different file, use the -c or --config-file option with the file path −
prelink -c /home/user/prelink.conf -a
The above command prelinks all binaries and libraries specified in the custom configuration file.
Forcing Re-prelinking
To force the re-prelinking even if the program is already prelinked, use the -f or --force option with the prelink command −
prelink -f /usr/bin/ls
Displaying Usage Help
To display the usage help of the prelink command, use the -? or --help option −
prelink -?
Conclusion
The prelink command in Linux optimizes the startup time of programs by prelinking ELF-shared libraries and binaries. It precomputes certain steps that the operating system usually performs at runtime, making the execution process faster. There are various options available to control how prelinking is performed, such as choosing specific files, running in verbose mode, simulating the process, or even undoing previous prelinking actions.