Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to temporary adjust date/time in Linux shell

Tags:

date

linux

time

I want to write some testscripts that create some files and execute commands that change behaviour depending on the current date. For testing purposes I would like to change the time to different dates (in the past and future) and check the behaviour.

Is it possible to change the date exclusively just for a singe shell-session, or fool a single application about the current date? - how could this be done?

like image 977
ducky Avatar asked Sep 14 '11 09:09

ducky


People also ask

How do you change date and time in Unix?

The date command under UNIX displays date and time. You can use the same command set date and time. You must be the super-user (root) to change the date and time on Unix like operating systems. The date command shows the date and time read from the kernel clock.


1 Answers

this can be done to a program with libfaketime which is preload library i.e. LD_PRELOAD.

like image 157
Dan D. Avatar answered Oct 05 '22 12:10

Dan D.