一、录制终端会话
脚本如下:
script -t 2>timing.log -a output.session
#timing.log 用于存储时序信息,描述命令何时执行,output.session 用于存储命令输出
# -t 用于将时许数据导入stderr 2> 将stderr 重定向到output.session
开始录制
输入命令: commands……
退出录制: exit
视频回放
scriptreplay timing.log output.session
ctrl +D 或者 ctrl +Z 退出播放
二、find
2.1、 基本用法
查找当前目录及子目录的文件和文件夹
语法 find base_path # base_path 可以放在任意位置 find 会从该位置开始查找
find . -print #打印文件和目录列表
# . 指定当前目录, .. 指定父目录
(2) 在当前目录下查找文本
find log.txt
2.2、正则表达式检索
(1) 根据文件名或者正则表达式进行搜索
选项: -name 的参数 指定了文件名必须匹配的字符串 *.txt 必须以.txt结尾
查找 所有txt文件
find /home/wanghao/ -name "*.txt" -print
选项: -igname(忽略字母大小写)
查找i开头的sh文件
find -iname "i.sh"
选项: -path 参数可以使用通配符来匹配文件路径。
查找 /usr/local路径下含有bin路径的文件
find /usr/local -path "*/bin/*"
(2) 正则表达式
正则规则:[a-z0-9]+ # +表示出现一次或或者多次
选项: -regex
选项 -iregex 表示 正则表达式忽略大小写
find -regex ".*\(\.txt\|\.sh\)$"
查找txt文件或者sh文件
2.3 否定参数
find用! 表示否定参数的含义
來看查找不是txt格式的文件
find . ! -name “*.txt”
2.4、基于目录深度的探索
深度选项 :
-maxdepth 指定最大深度 从当前目录开始算起
-mindepth 指定最小深度
來看查找 /usr/local开头的bin目录
find /usr/local -maxdepth 1 -path "*/bin*"
来看当当吧深度改为2时:
-maxdepth 和 -mindepth 应该作为 find 的第三个参数出现。如果作为第4个或之后的参数,就可能会影响到 find 的效率
2.5、根据文件类型检索
选项: -type
文件具有不同的类型: 普通文件,目录,字符设备,块设备,符号链接,硬链接、套接字以及FIFO
(1)列出所有目录
find /usr/local/biin -type d -print
(2) 列出普通文件
find /usr/local/biin -type f -print
(3) 列出符号链接
find /usr/local/ -type l
(4) type 参数列表
2、6 根据文件时间检索
每个文件有三个时间戳
1、访问时间(-atime) 用户最近一次访问文件的时间
2、修改时间(-mtime) 文件内容最后一次被修改的时间
3、变化时间(-ctime) 文件元数据(如权限或所有权)最后一次改变时间
它们都可以作为find的时间选项 整数指定 单位是天 还可以带- 或+ 表示小于或大于
(1) 实例最近7天被访问的所有文件
find . -type f -atime -7
(2) 刚好 昨天 访问的文件
find /home/wanghao -type f -atime 1
(3) 访问超过7天的文件
find /home/wanghao -type f -atime +7
同理 单位是分钟的三个时间分别为
amin、mmin、cmin
(4) 7分钟前访问的
find /home/wanghao -type f -amin +7
2.7、根据文件大小
选项 -size
(1) 大于1k的文件
find . -type f -size +1k
(2) type 其他参数
2.8、删除匹配文件
选项- delete
删除 所有的txt 文件代码如下:
find . -type f -name "*.txt" -delete
2.9、根据用户匹配
选项 -user 根据某个特定用户
find /usr/local/ -type d -user wanghao