linux命令随时添加
查看某个端口的进程
lsof -i:端口号
lsof -i :5601
kill -9 进程号
kill -9 2633
开启/关闭防火墙 (默认设置是’disable’)
sudo ufw enable|disable
查看防火墙状态
sudo ufw status
查看具体的某个进程
ps -aux | grep 进程服务名
后台挂起运行
nohup /root/start.sh &
追踪文件
tail -f 文件名
上传文件
rz 文件名
rz命令(Receive ZMODEM),使用ZMODEM协议,将本地文件批量上传到远程Linux/Unix服务器,注意不能上传文件夹
日志管理
1.查看日志常用命令 tail: -n 是显示行号;相当于nl命令;例子如下: tail -100f test.log 实时监控100行日志 tail -n 10 test.log 查询日志尾部最后10行的日志; tail -n +10 test.log 查询10行之后的所有日志; head: 跟tail是相反的,tail是看后多少行日志;例子如下: head -n 10 test.log 查询日志文件中的头10行日志; head -n -10 test.log 查询日志文件除了最后10行的其他所有日志; cat: tac是倒序查看,是cat单词反写;例子如下: cat -n test.log |grep "debug" 查询关键字的日志 2. 应用场景一:按行号查看---过滤出关键字附近的日志 1)cat -n test.log |grep "debug" 得到关键日志的行号 2)cat -n test.log |tail -n +92|head -n 20 选择关键字所在的中间一行. 然后查看这个关键字前10行和后10行的日志: tail -n +92表示查询92行之后的日志 head -n 20 则表示在前面的查询结果里再查前20条记录 3. 应用场景二:根据日期查询日志 sed -n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log 特别说明:上面的两个日期必须是日志中打印出来的日志,否则无效; 先 grep '2014-12-17 16:17:20' test.log 来确定日志中是否有该 时间点 4.应用场景三:日志内容特别多,打印在屏幕上不方便查看 (1)使用more和less命令, 如: cat -n test.log |grep "debug" |more 这样就分页打印了,通过点击空格键翻页 (2)使用 >xxx.txt 将其保存到文件中,到时可以拉下这个文件分析 如:cat -n test.log |grep "debug" >debug.txt
查找
1、查找文件 find / -name 'filename' 2、查找文件夹(目录) find / -name 'path' -type d 3、查找内容 find . | xargs grep -ri 'content' 3.1、只显示文件名称 find . | xargs grep -ril 'content' 只显示文件名称
删除乱码文件
首先执行ls -i命令,此时在文件前面会出现一个数字,这个数字是文件的节点号:
接着,执行命令
find -inum 节点号 -delete
设置redis密码
config set requirepass 123456
防火墙:
CentOS 7.0默认使用的是firewall作为防火墙 查看防火墙状态 firewall-cmd --state 停止firewall systemctl stop firewalld.service 禁止firewall开机启动 systemctl disable firewalld.service – 开放指定端口 firewall-cmd --zone=public --add-port=1935/tcp --permanent – 关闭指定端口 firewall-cmd --zone=public --remove-port=5672/tcp --permanent – 重启防火墙 firewall-cmd --reloadl