时间日期和查找类命令
时间日期类命令:
date:
//显示当前时间
date
//显示当前年月日
date "+%Y-%m-%d"
//设置系统当前时间
date -s "2020-11-05 20:00:00"
cal:日历
//显示本月日历
cal
//显示一年日历
cal 2020
查找类命令:
find:查找满足条件的文件名或者目录
-name:按照名字查找 -user:按照文件所属用户查找 -type:按文件类型查找
-mtime -n | +n:根据更改时间查找(天)-mmin -n | +n:根据更改时间查找(分)
-size -n | +n:按照文件大小查找
//精确搜索
find /Desktop -name kk.txt
//模糊搜索
find Desktop -name kk*
find Desktop -name *.txt
//忽略大小搜索
find Desktop -iname kk*
字节 byte 1kb=1024b 1mb=1024kb
//查找大于200M的文件(+n:大于 -n:小于 n:等于,单位有k,M,G)
find /home -size +200M
//通过所属人搜索文件
find Desktop -user fddd
//-5:5分钟之内被更改过的txt文件(通过时间查找文件)
find Desktop -mmin -5 -name '*.txt'
//按文件类型搜索(f:文件 d:文件夹)
find Desktop -type f
-exec 命令 {} \; :对搜索到的文件执行特定的操作
//在当前目录下(包含子目录),查找所有txt文件并找出含有字符串"bin"的行
find ./ -name "*.txt" -exec grep "bin" {} \;
//在当前目录下(包含子目录),删除所有txt文件
find ./ -name "*.txt" -exec rm {} \;
locate:快速定位文件路径
运行前需要先执行updatedb指令创建locate数据库
//快速定位hello.txt文件所在目录
locate hello.txt
grep:过滤查找
-n:显示匹配行及行号 -i:忽略字母大小写
//在hello.txt文件中,查找yes所在行,并且显示行号
cat hello.txt | grep -n "yes"
grep -n "yes" hello.txt

浙公网安备 33010602011771号