• 根据预设的条件递归查找对应的文件 – find [目录] [条件1] [-a|-o] [条件2] …
– 常用条件表示: -type 类型(f文件、d目录、l快捷方式) -name “文档名称” -size +|-文件大小(k、M、G) -user 用户名
-type 按照类型查找
[root@server0 ~]# find /boot/ -type l #查找快捷方式 [root@server0 ~]# ls /boot/grub/menu.lst [root@server0 ~]# ls -l /boot/grub/menu.lst [root@server0 ~]# find /boot/ -type f #查找是文本文件 [root@server0 ~]# find /boot/ -type d [root@server0 ~]# find /root/ -type d #查找是目录###################################################### -name '文档名称’
[root@server0 ~]# find /etc/ -name 'passwd' [root@server0 ~]# find /etc/ -name 'passwd*' [root@server0 ~]# find /etc/ -name '*passwd*' [root@server0 ~]# mkdir /root/asd01 [root@server0 ~]# touch /root/asd02.txt [root@server0 ~]# touch /root/asd03.txt [root@server0 ~]# find /root/ -name 'asd*' [root@server0 ~]# find /root/ -name 'asd*' -a -type d [root@server0 ~]# find /root/ -name 'asd*' -type d [root@server0 ~]# find /root/ -name 'asd*' -type f###################################################### -size +或-文件大小(k、M、G) -user 用户名 #按照所有者进行查找
[root@server0 ~]# find /boot/ -size +10M [root@server0 ~]# find /boot/ -size -10M [root@server0 ~]# find / -user student [root@server0 ~]# find /home -user student [root@server0 ~]# find /var -user student###################################################### • 根据名称查找,忽略大小写 – -iname
[root@server0 ~]# find /etc -name 'PASSWD' [root@server0 ~]# find /etc -iname 'PASSWD' /etc/passwd /etc/pam.d/passwd• 根据所属组 – -group
[root@server0 ~]# find /home/ -group 'student'• 限制目录查找的深度(最大层数) – -maxdepth
[root@server0 ~]# find /etc/ -maxdepth 1 -name '*.conf' [root@server0 ~]# find /etc/ -maxdepth 2 -name '*.conf' [root@server0 ~]# find /etc/ -maxdepth 3 -name '*.conf'• 根据文件修改时间(所有的时间都是过去时间) -mtime +10 :10天之前的文档 -10 :最近10天之内的文档
[root@server0 ~]# find /var/ -mtime +100 -type f [root@server0 ~]# find /var/ -mtime -5 -type f####################################################
– find … … -exec 处理命令 {} ; – 优势:以 {} 代替每一个结果,逐个处理,遇 ; 结束
]# find / -user student -type f ]# find / -user student -type f -exec cp {} /root/findfiles/ \; ]# ls -A /root/findfiles/ ]# find /boot -size +10M ]# find /boot -size +10M -exec cp {} /opt \; ]# ls /optNTP网络时间协议 • Network Time Protocol – NTP服务器为客户机提供标准时间 – NTP客户机需要与NTP服务器保持沟通 • RHEL7客户端的校时服务 – 软件包:chrony – 配置文件:/etc/chrony.conf – 系统服务:chronyd
**NTP时间服务器:虚拟机classroom NTP客户机:虚拟机server 1.安装chrony包进行安装
[root@server0 ~]# yum -y install chrony**软件包 chrony-1.29.1-1.el7.x86_64 已安装并且是最新版本 无须任何处理
[root@server0 ~]# rpm -q chrony2.修改配置文本(指定服务端位置)
[root@server0 ~]# vim /etc/chrony.conf #server 0.rhel.pool.ntp.org iburst #开头加上#号,变成注释 #server 1.rhel.pool.ntp.org iburst #开头加上#号,变成注释 #server 2.rhel.pool.ntp.org iburst #开头加上#号,变成注释 server classroom.example.com iburst #修改内容,指向classroom3.重起服务chronyd daemon:守护神;(希腊神话中)半人半神的精灵;[计]守护进程
[root@server0 ~]# systemctl restart chronyd [root@server0 ~]# systemctl enable chronyd #设置开机自起4.测试时间同步
[root@server0 ~]# date -s '2000-10-1 11:11:11' 2000年 10月 01日 星期日 11:11:11 CST [root@server0 ~]# date 2000年 10月 01日 星期日 11:11:13 CST [root@server0 ~]# systemctl restart chronyd [root@server0 ~]# date [root@server0 ~]# date [root@server0 ~]# date####################################################
**周期性任务 cron任务概述 • 用途:按照设置的时间间隔为用户反复执行某一项固定的系统任务 • 软件包:cronie、crontabs • 系统服务:crond • 日志文件:/var/log/crond
管理计划任务策略 • 使用 crontab 命令 – 编辑:crontab -e [-u 用户名] – 查看:crontab -l [-u 用户名] – 清除:crontab -r [-u 用户名] 如何编写crontab任务记录 • 配置格式可参考 /etc/crontab 文件
– 分 时 日 月 周 任务命令行(绝对路径)
0 23 * * * powerofff
30 8 * * * 0 18 * * 5 0 18 * * 1-5 0 18 * * 1,3,5,7 0 */2 * * * #每两个小时*:匹配范围内任意时间 ,:分隔多个不连续的时间点 -:指定连续时间范围 /n:指定时间频率,每n …
30 8 1 * 2 每月的一号的8点30分和每周二的8点30分 都执行 ``每分钟记录当前系统的时间,写入到/opt/time.txt [root@server0 ~]# date 2019年 03月 05日 星期二 15:30:04 CST [root@server0 ~]# date >> /opt/time.txt [root@server0 ~]# cat /opt/time.txt [root@server0 ~]# crontab -e -u root #以root身份编辑计划任 [root@server0 ~]# crontab -l -u root #查看root用户的计划任务 * * * * * date >> /opt/time.txt [root@server0 ~]# cat /var/spool/cron/root #任务文件 * * * * * date >> /opt/time.txt [root@server0 ~]#####################################################