1、主机的系统时间配置
1)查看主机系统时间
date
date '+%Y-%m-%d'
date '+%Y-%m-%d:%H:%M:%S'
2)更改(设置)系统时间
date -s
date -s '2023-12-12 12:12:12'
3)如何将时间更改回来?
方法一:Linux硬件的时间的设置
hwclock
设置系统硬件时间:
hwclock --set --date '20240522 20:00:00'
硬件时间和系统时间同步:
①以系统时间同步硬件时间
hwclock --systohc
hwclock -w
②以硬件时间同步系统时间
hwclock --hctosys
hwclock -s
方法二:NTP服务器时间的同步
1)NTP服务器安装
yum install -y ntp
2)启动ntp服务器
systemctl start ntpd
3)停止ntp服务器
systemctl stop ntpd
4)查看ntp服务器状态
systemctl status ntpd
5)ntp时间同步
命令格式:ntpdate [NTP服务器IP或主机名]
ntpdate ntp1.aliyun.com
2、显示系统当前日历
cal
显示某年日历:
cal [年份]
3、find命令
将从指定目录向下递归的遍历其各个子目录,将满足条件的文件或者目录显示子啊终端;
基本语法:find [搜索范围] [选项]
选项说明:
1)find /home -name hello.txt
2)find /opt/ -user nobody
3)查找整个linux系统下大于200M的文件(+n大于 -n小于 n等于,单位:k,M,G)
find / -size +200M
4、locate命令
可以快速定位文件路径,locate指令利用事先建立的系统中所有文件名称及路径的locate数据库实现快速定位给定的文件。locate无需遍历整个文件系统,查询速度比较快。为了保证查询结果的准确度,管理员必须要定期更新locate时刻;
基本语法:locate 搜索文件
1)必须使用updatedb指令创建locate数据库;
2)updatedb ---> locate hello.txt
3)which可以查看某个指令在那个目录下面;
5、grep指令和管道符号
grep 过滤查找,管道符“|",表示将前一个指令的输出结果输出传递给后面的命令处理;
基本语法:grep [选项] 查找内容 源文件
1)grep -n yes hello.txt 或者cat hello.txt | grep -n 'yes'
2)忽略字母大小写过滤:
grep -i -n 'yes' /home/hello.txt 或者 cat hello.txt | grep -i -n 'yes'