【开源项目】libfaketime安装、使用——小白教程

项目

Github:GitHub - wolfcw/libfaketime: libfaketime modifies the system time for a single application


libfaketime安装

01.切换路径,目标路径:/usr/local

(在/usr/local路径下git clone 开源项目)

切换路径指令:

复制代码
cd /usr/local

02.拉取

复制代码
git clone https://github.com/wolfcw/libfaketime.git

eg:

复制代码
root@DESKTOP-ER8E8NH:~# cd /usr/local
root@DESKTOP-ER8E8NH:/usr/local# ls -l
total 0
drwxr-xr-x 1 root root 4096 May 30  2023 bin
drwxr-xr-x 1 root root 4096 May 30  2023 etc
drwxr-xr-x 1 root root 4096 May 30  2023 games
drwxr-xr-x 1 root root 4096 May 30  2023 include
drwxr-xr-x 1 root root 4096 May 30  2023 lib
lrwxrwxrwx 1 root root    9 May 30  2023 man -> share/man
drwxr-xr-x 1 root root 4096 May 30  2023 sbin
drwxr-xr-x 1 root root 4096 May 31  2023 share
drwxr-xr-x 1 root root 4096 May 30  2023 src
root@DESKTOP-ER8E8NH:/usr/local# git clone https://github.com/wolfcw/libfaketime.git
Cloning into 'libfaketime'...
remote: Enumerating objects: 2536, done.
remote: Counting objects: 100% (660/660), done.
remote: Compressing objects: 100% (254/254), done.
remote: Total 2536 (delta 427), reused 555 (delta 399), pack-reused 1876 (from 1)
Receiving objects: 100% (2536/2536), 839.43 KiB | 55.00 KiB/s, done.
Resolving deltas: 100% (1596/1596), done.
root@DESKTOP-ER8E8NH:/usr/local# ls -l
total 0
drwxr-xr-x 1 root root 4096 May 30  2023 bin
drwxr-xr-x 1 root root 4096 May 30  2023 etc
drwxr-xr-x 1 root root 4096 May 30  2023 games
drwxr-xr-x 1 root root 4096 May 30  2023 include
drwxr-xr-x 1 root root 4096 May 30  2023 lib
drwxr-xr-x 1 root root 4096 Oct 28 21:51 libfaketime
lrwxrwxrwx 1 root root    9 May 30  2023 man -> share/man
drwxr-xr-x 1 root root 4096 May 30  2023 sbin
drwxr-xr-x 1 root root 4096 May 31  2023 share
drwxr-xr-x 1 root root 4096 May 30  2023 src
root@DESKTOP-ER8E8NH:/usr/local#

03.切换到libfaketime路径

指令:

复制代码
cd libfaketime

04.make

指令:

复制代码
make

eg:

复制代码
root@DESKTOP-ER8E8NH:/usr/local/libfaketime (master)# make
make  -C src all
make[1]: Entering directory '/usr/local/libfaketime/src'
cc -o libfaketime.o -c -std=gnu99 -Wall -Wextra -Werror -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_UTIME -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'/usr/local'"' -DLIBDIRNAME='"'/lib/faketime'"'  -Wno-nonnull-compare   libfaketime.c
cc -o libfaketime.so.1 -Wl,-soname,libfaketime.so.1  -Wl,--version-script=libfaketime.map -shared libfaketime.o -ldl -lm -lrt -lpthreadcc -o libfaketimeMT.o -c -std=gnu99 -Wall -Wextra -Werror -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_UTIME -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'/usr/local'"' -DLIBDIRNAME='"'/lib/faketime'"'  -Wno-nonnull-compare  -DPTHREAD_SINGLETHREADED_TIME libfaketime.c
cc -o libfaketimeMT.so.1 -Wl,-soname,libfaketimeMT.so.1  -Wl,--version-script=libfaketime.map -shared libfaketimeMT.o -ldl -lm -lrt -lpthread
cc -o faketime -std=gnu99 -Wall -Wextra -Werror -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_UTIME -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'/usr/local'"' -DLIBDIRNAME='"'/lib/faketime'"'  -Wno-nonnull-compare   faketime.c  -Wl,--version-script=libfaketime.map -lrt -lpthread
make[1]: Leaving directory '/usr/local/libfaketime/src'

05.make install

指令:

复制代码
make install

eg:

复制代码
root@DESKTOP-ER8E8NH:/usr/local/libfaketime (master)# sudo make install
make  -C src install
make[1]: Entering directory '/usr/local/libfaketime/src'

Copying the faketime libraries to /usr/local/lib/faketime and the faketime wrapper script to /usr/local/bin ...
install -dm0755 "/usr/local/lib/faketime/"
install -m0644 libfaketime.so.1 libfaketimeMT.so.1 "/usr/local/lib/faketime/"
install -Dm0755 faketime "/usr/local/bin/faketime"
make[1]: Leaving directory '/usr/local/libfaketime/src'
make  -C man install
make[1]: Entering directory '/usr/local/libfaketime/man'
install -Dm0644 faketime.1 "/usr/local/share/man/man1/faketime.1"
gzip -nf "/usr/local/share/man/man1/faketime.1"
make[1]: Leaving directory '/usr/local/libfaketime/man'
install -dm0755 "/usr/local/share/doc/faketime/"
install -m0644 README "/usr/local/share/doc/faketime/README"
install -m0644 NEWS "/usr/local/share/doc/faketime/NEWS"

libfaketime使用

修改时间

语法:

复制代码
export LD_PRELOAD=[libfaketime.so.1文件的绝对路径] FAKETIME="[@目标时间]"

eg:

复制代码
export LD_PRELOAD=/usr/local/libfaketime/src/libfaketime.so.1 FAKETIME="@2024-06-04 00:00:01"

同步时间

语法:

复制代码
export LD_PRELOAD=/usr/local/libfaketime/src/libfaketime.so.1 FAKETIME= date
相关推荐
bug攻城狮几秒前
彻底禁用 CentOS 7.9 中 vi/vim 的滴滴声
linux·运维·服务器·centos·vim
XMYX-038 分钟前
Linux 物理机如何区分 SSD 与 HDD ——以 DELL PERC H730 Mini 为例
linux·运维
轻松Ai享生活40 分钟前
5 天学习 Linux Kernel 主要原理 | Day 3:内存管理与Swap机制
linux
轻松Ai享生活41 分钟前
QAT 与 GPU 在SHA-1 运算中的优劣
linux
行思理1 小时前
linux 安全与防护,全方向讲解
linux·安全·github
tan180°2 小时前
Boost搜索引擎 查找并去重(3)
linux·c++·后端·搜索引擎
yongui478342 小时前
CentOS系统如何查看当前内存容量
linux·运维·centos
xzq_java2 小时前
CentOS操作系统虚拟机安装以及连接工具下载和远程连接工具远程连接
linux·运维·centos
逐梦吧!旅行者3 小时前
Linux之环境变量(内容由浅入深,层层递进)
linux·运维
IOT-Power3 小时前
树莓派 Ubuntu 24.04 开机换源总结
linux·数据库·ubuntu