- 下载ps.txt文件
sz ps.txt
- 上传(-y是确定覆盖,没有同名文件可不写)
rz -y
- 端口占用
netstat -naolp | grep "8080"
- 查找
find / -name memcache
- 回到上一次目录
cd -
- 当前文件夹下,文件大小
du -sh *
- 关机
shutdown -h 0
- 文件清空
cat /dev/null > catalina.out
- 反向查看日志
tac logs/catalina.out | more
- 查看当前的磁盘分区信息(主要是分区表信息)
fdisk -l
- for循环压缩日志(只压缩,不删除)
for item in `ll -h | grep 'access_log_2021_05_07' | awk '{print $NF}'`; do tar -cvzf $item.tar.gz $item; echo "----------"; done;
- for循环压缩日志,并删除原来日志文件
for item in `ll -h | grep 'access_log_2021_05' | awk '{print $NF}'`; do tar -cvzf $item.tar.gz $item; rm -fr $item; echo "----------"; done;
- 不解压缩,直接查看压缩包里的内容
zcat access_log_2021_05_03.tar.gz | more
- 创建软连接
ln -s /usr/local/sshpass/bin/sshpass /usr/bin/sshpass
- 远程拷贝
scp root@192.168.0.200:/data/123.tar.gz .
sshpass -p 'password' scp root@192.168.0.200:/data/123.tar.gz .
16.查看日志
①查询字符串命令: cat fileName|grep ‘要查找的字符串’
cat catalina.out|grep 'hello'
②根据某个字符串,查询该字符串前后文本命令:grep-A|B n"key"file
其中:
A:表示在字符串之后 after context
B:表示在字符串之前 before context
n:要获取多少行文本 line number
key:为要查找的字符串
file:文件名
grep -A 100 -B 100 -i 'hello' catalina.out
-i表示忽略大小写。
获取异常日志的前10行和后10行,不用加-A和-B:
grep -10 -i 'hello' catalina.out