LinuxCommandLibrary

faketime

Run programs with a faked system time

TLDR

Fake the time to this evening, before printing the result of date

$ faketime '[today 23:30]' [date]
copy

Open a new Bash shell, which uses yesterday as the current date
$ faketime '[yesterday]' [bash]
copy

Simulate how a program would act next Friday night
$ faketime '[next Friday 1 am]' [path/to/program]
copy

SYNOPSIS

faketime [options] <timestamp> [--] <command> [<args>...]

PARAMETERS

-l, --log[=file]
    Write log messages to file (default: faketime.log)

-t, --timestamp-format fmt
    Use strptime(3)-compatible format fmt (default: %Y-%m-%d %H:%M:%S)

-u, --user-time
    Fake only user time (via gettimeofday, etc.), not system time (clock_gettime(CLOCK_MONOTONIC))

-s, --sys-time
    Fake only system time, not user time

-m, --mark[=mode]
    Mark the faketime process (modes: pid, absolute; default: pid)

-h, --help
    Display help and exit

-V, --version
    Output version information and exit

DESCRIPTION

The faketime command allows users to execute any other program with the system time appearing different than the actual time. It achieves this by preloading a small shared library (libfaketime) that intercepts and modifies calls to common time functions like gettimeofday(), time(), and others in glibc. This is particularly useful for testing time-sensitive applications, reproducing issues tied to specific dates (e.g., leap seconds or Y2K-like bugs), creating reproducible builds where timestamps must be consistent, or running software that enforces time-based licenses or restrictions.

Faketime supports absolute timestamps (e.g., '2023-01-01 12:00:00'), relative offsets (e.g., '+1h30m', '-2d'), Unix timestamps ('@1640995200'), or zone-aware times. It affects only the executed command and its child processes, leaving the host system's clock unchanged. The tool is lightweight, portable across Linux distributions via the libfaketime package, and commonly used in CI/CD pipelines, containerized environments like Docker, and development workflows.

CAVEATS

Relies on LD_PRELOAD, so ineffective on statically linked binaries, programs bypassing libc (e.g., direct syscalls, some Go/Rust apps), or setuid executables. Affects process tree only; nested faketime calls may conflict. Not thread-safe in all scenarios. Requires libfaketime installed.

TIMESTAMP FORMATS

Absolute: 2023-01-01 12:00:00
Offset: +1h30m, -2d12h (s/m/h/d/y)
Unix: @1672531200
Zone: 2023-01-01 12:00:00 UTC-5

EXAMPLES

faketime '2000-01-01' date → Shows Y2K date.
faketime -f '+1y' touch file.txt → Ages file by 1 year.
faketime 'now -30m' make → Builds with time 30min ago.

HISTORY

Developed as part of libfaketime library around 2008 by Bernhard R. Link (initial versions) and contributors like Tianon Gravi. Gained popularity post-2015 for reproducible builds (e.g., Coreboot, Linux kernel). Actively maintained on GitHub; versions track glibc changes for new time APIs.

SEE ALSO

date(1), hwclock(8), timedatectl(1)

Copied to clipboard