fakeroot Command Examples in Linux

“fakeroot” is a command-line tool in Linux-based systems that allows a user to run a command in an environment that mimics root privileges for file manipulation. This means that a user can execute commands as if they were the root user, without actually having root access.

The main use of fakeroot is to create a package or a package-like environment while running as a normal user, allowing the user to create files with permissions and ownership that would normally require root access. This is useful for creating Debian packages, for example, as the package maintainer does not need to run the process as root.

Fakeroot uses the LD_PRELOAD mechanism to intercept system calls that change the file ownership and permissions, and redirects them to an internal library. This library keeps track of the changes and applies them when the command finishes.

fakeroot Command Examples

1. Start the default shell as fakeroot:

# fakeroot

2. Run a command as fakeroot:

# fakeroot -- command command_arguments

3. Run a command as fakeroot and save the environment to a file on exit:

# fakeroot -s path/to/file -- command command_arguments

4. Load a fakeroot environment and run a command as fakeroot:

# fakeroot -i path/to/file -- command command_arguments

5. Run a command keeping the real ownership of files instead of pretending they are owned by root:

# fakeroot --unknown-is-real -- command command_arguments

6. Display help:

# fakeroot --help
Related Post