![fcb5bea16e5ed08cf2dc4279a9ad064a.png](https://i-blog.csdnimg.cn/blog_migrate/f06cdef2c4904e06afb29416b53665b9.jpeg)
linux基础操作:主要介绍了,时间和搜索类的指令
- 时间日期类指令。
1.date[显示日期时间,以下例子+是必备符号,其他符号和汉字可以自定义,注意字母区分大小写]
例子1:date 表示显示当前的时间[年月日时分秒]
例子2:date "+%Y" 表示仅显示年份
例子3:date "+%m" 表示仅显示月份
例子4:date "+%d" 表示仅显示日
例子5:date "+%H:%M:%S" 表示显示时分秒
例子6:date "+%Y年%m月%d日"表示显示年月日
例子7:date "+%Y年%m月%d日%H时%M分%S秒" 表示年月日时分秒
2.date -s [表示设置系统日期,主要用来修改系统时间]
例子:date -s "2019-12-02 19:24:50" 表示以字符串格式设置系统时间。
3.cal [表示显示日历]
例子1:cal 表示显示当月的日历。
例子2:cal 2018 表示显示2018年的日历
- 搜索查找类指令
1.find [搜索文件和目录]
例子1:find /home -name hello.txt 表示查找home目录下的名为hello.txt的文件。
例子2:find /home -user root 表示查找home目录下所属root用户的文件
例子3:find /home -size +20M 表示查找home目录下大于20M的文件。
例子4:find /home -size -20M 表示查找home目录下小于20M的文件。
例子5:find /home -size 20M 表示查找home目录下等于20M的文件。
2.locate[基于数据库快速定位查找文件]
例子:updatedb 表示建立搜索需要的locate数据库信息。 locate hello.txt 表示通过updatedb 建立的数据库快速搜索hello.txt的文件。
3.grep [查找文件内容-n显示行号,-i忽略字母大小写]
例子1:grep "hello" hello.txt 表示查找hello.txt文件内的hello字符串。
例子2:grep -n "hello" hello.txt 表示查找hello.txt文件内的hello字符串并显示所在位置的行号。
例子3:grep -i "Hello" hello.txt 表示查找hello.txt文件内的hello字符串并忽略字母大小写问题。
例子4:cat hello.txt | grep hello 表示使用cat以只读形式读取文件后再使用grep命令查找文件的内容hello字符串,可选参数-n和-i。