1 安全加固
密码:
- 建立严格密码并设置密码验证次数
- 设置公钥私钥方式免密登录
- 建立堡垒机统一入口登录
权限:
- grep 更适合单纯的查找或匹配文本
- sed 更适合编辑匹配到的文本
- awk 更适合格式化文本,对文本进行较复杂格式处理
指定,为分隔符,取第一列和第二列
cat test.log | awk -F, {‘print $1,$2’}
附加变量输出(打印第一列,第二列的值为第一列+a,a=1)
cat test.log | awk -va=1 {‘print $1,$1+a’}
使用awk脚本
cat test.log | awk -f name.awk
过滤指定条件的列
cat test.log | awk ‘$1>1’
cat test.log | awk ‘$1>1 {print $1}’
cat test.log | awk ‘$1>1 && $2==”hello” {print $1}’
显示行号
cat test.log | awk -F, {‘print NR,$1,$2’}
输出第二列包含 “th”,并打印第二列与第四列
awk ‘$2 ~ /th/ {print $2,$4}’ log.txt
忽略大小写
awk ‘BEGIN{IGNORECASE=1} /this/‘ log.txt
2. grep```shell#查找文件中的指定字段grep hello test.log#查找指定字段并显示下一行grep -A 1 hello test.log#查找指定字段并显示上一行grep -B 1 hello test.log#递归查找指定目录下包含指定字段grep -r hello /etc/test#反向查找,不显示指定字段grep -v hello test.log#查找指定目录下,指定文件后缀,指定字段,并显示行号find /etc -type f -name "*.log" | xargs grep -n "hello"#不区分大小写grep -i hello test.log
sed -e
在指定行的下一行插入数据
sed -e ‘4a hello’ test.txt
在指定行的上一行插入数据
sed -e ‘4i hello’ test.txt
在指定行删除数据
sed -e ‘2,4d’ test.txt
在指定行修改数据
sed -e ‘3c hello’ test.txt
sed -i
可以用上面的语法
指定字段替换
sed -i ‘s/nihao/hello/g’ test.txt
```
