Linux基础入门教程08课-Centos7编译安装软件包

通过编译的方式安装inotify-tools 软件工具,完成下列任务:

  1. 释放 inotify-tools-3.13.tar.gz 源码包
  2. 配置 ./configure
  3. 编译 make、安装 make install
  4. 测试inotifywait监控工具的用法及用途

编译安装软件包

步骤一:确认已配置好编译环境

[root@localhost ~]# yum -y install gcc gcc-c++ make
.. ..
[root@localhost ~]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
步骤二:编译安装inotify-tools软件包

1)解包inotify-tools-3.13.tar.gz文件

[root@localhost ~]# ls inotify-tools-3.13.tar.gz
inotify-tools-3.13.tar.gz
[root@localhost ~]# tar xf inotify-tools-3.13.tar.gz -C /usr/src/
2)配置 ./configure,安装目录默认(/usr/local/*/)

[root@localhost ~]# cd /usr/src/inotify-tools-3.13/ //进入源码目录
[root@localhost inotify-tools-3.13]# ./configure //配置操作
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
.. ..
configure: creating ./config.status
config.status: creating Makefile
.. ..

[root@localhost inotify-tools-3.13]# ls Makefile //检查配置结果
Makefile
3)编译 make

[root@localhost inotify-tools-3.13]# make
.. ..
Making all in src
make[2]: Entering directory `/usr/src/inotify-tools-3.13/src'
make[3]: Entering directory `/usr/src/inotify-tools-3.13'
make[3]: Leaving directory `/usr/src/inotify-tools-3.13'
.. ..
4)安装 make install

[root@localhost inotify-tools-3.13]# make install
.. ..
/usr/bin/install -c .libs/inotifywait /usr/local/bin/inotifywait
/bin/sh ../libtool --mode=install /usr/bin/install -c 'inotifywatch' '/usr/local/bin/inotifywatch'
.. ..

[root@localhost inotify-tools-3.13]# find /usr/local/ -name "inotify*"
/usr/local/bin/inotifywait //确认安装结果
/usr/local/bin/inotifywatch
/usr/local/include/inotifytools
/usr/local/include/inotifytools/inotifytools.h
步骤三:测试inotify-tools软件程序

软件包inotify-tools提供了一个主要程序inotifywait,可以用来监控指定目录或文档的变化,并及时给出通知。

1)开启对/opt目录的事件监控

[root@localhost ~]# inotifywait -mrq /opt & //开启监控
[1] 15568
2)修改/opt/目录内容,观察屏幕输出信息

[root@localhost ~]# touch /opt/a.txt //新建文件a.txt
/opt/ CREATE a.txt
/opt/ OPEN a.txt
/opt/ ATTRIB a.txt
/opt/ CLOSE_WRITE,CLOSE a.txt

[root@localhost ~]# mv /opt/a.txt /opt/b.txt //将文件改名
/opt/ MOVED_FROM a.txt
/opt/ MOVED_TO b.txt
3)结束inotifywait监控

杀死当前用户的第一个后台任务:

[root@localhost ~]# kill -9 %1
[1]+ Killed inotifywait -mrq /opt

     

您可以选择一种方式赞助本站

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: