文章目录
- 查看文件内容
- 编辑文件
- vi中更改指定文件内容
- 查端口占用
- Linux中怎么通过PID号找到对应的进程名及所在目录
- 从根目录下查找指定名称的文件
- 杀进程
- 远程登陆
- 远程登陆并传送文件
- 启动springboot的jar包
- 杀springboot的jar包
- springboot启动debug模式
- 查看防火墙列表
- 开启防火墙
- 关闭/启动/重启防火墙
- 防火墙新增端口
- 防火墙删除端口
- 查看防火墙是否开启
- 启动nginx
- 重启nginx
- 查日志后200行
- 时间段内日志
- 查看底部最新300行并且时时刷新,筛选是含有ERROR的前后10行。error色高亮
- 压缩文件
- 解压缩
- 递归删除
- 移动文件
- curl调用http服务
- 汇总某路径下一共占用多少内存
- 查看磁盘状况
- 目录占用空间大
- 时间同步
- 更改目录所有者命令
- 更改目录权限命令
- dmesg排查消失的进程
- 获取进程详细信息
- 查询占用端口号的程序名或pid
- 保证某个进程不被内核杀掉可以这样操作
- 时间相关
- 看端口通不通
- 查进程所在绝对路径
- linux下获取占用CPU资源最多的10个进程,可以使用如下命令组合
- 查磁盘满了思路
查看文件内容
- cat -n xxx.log
- tail -200f xxx.log
编辑文件
- vi
vi中更改指定文件内容
- sed -i “s/nifi.web.http.host=/nifi.web.http.host=127.0.0.1/g” nifi.properties
查端口占用
- windows
- netstat -ano |findstr ‘1114’ -> tasklist |findstr “进程id号” -> taskkill /F /IM java.exe
- linux
- netstat -anp |grep port
- netstat -nultp
- lsof -i:port
Linux中怎么通过PID号找到对应的进程名及所在目录
- ps -aux |grep -v grep|grep PID
从根目录下查找指定名称的文件
- find / -name tomcat
杀进程
- kill -9 PID
远程登陆
- ssh root@106.15.186.155 ->输入密码:xxxx
- ssh -p 1557 -i 密钥位置 密钥对应用户名@ip地址
远程登陆并传送文件
- scp 本地文件路径 用户名@ip:目标路径
- scp -p 1557 -i 密钥位置 本地文件路径 密钥对应用户名@ip地址:目标文件路径
启动springboot的jar包
- nohup java -jar test.jar >/dev/null 2>&1
杀springboot的jar包
- ps -ef|grep “java -jar test.jar”|grep -v grep|awk ‘{print $2}’|xargs kill -9|echo $?
springboot启动debug模式
- nohup java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 test.jar >log.log &
查看防火墙列表
- centos 6
- cat /etc/sysconfig/iptables
- centos7
- firewall-cmd --zone=public --list-ports
开启防火墙
- centos 6
- vi /etc/sysconfig/iptables
- -A INPUT -p tcp -m state --state NEW -m tcp --dport ${port} -j ACCEPT
- centos7
- firewall-cmd --zone=public --add-port=${port}/tcp --permanent
关闭/启动/重启防火墙
- centos 6
- chkconfig iptables off/service iptables stop
- chkconfig iptables on/service iptables start
- service iptables restart
- centos7
- systemctl stop firewalld
- systemctl start firewalld
- firewall-cmd --reload
防火墙新增端口
- centos7
- firewall-cmd --zone=public --add-port=8000/tcp --permanent
- centos6
- vi /etc/sysconfig/iptables
- -A INPUT -p tcp -m state --state NEW -m tcp --dport 8000 -j ACCEPT
- vi /etc/sysconfig/iptables
防火墙删除端口
- centos7
- firewall-cmd --zone= public --remove-port=8000/tcp --permanent
查看防火墙是否开启
- centos7
- firewall-cmd --state
启动nginx
- ./nginx
重启nginx
- ./nginx -s reload
查日志后200行
- tail -200f xx.log
时间段内日志
- grep -E ‘2017-09-05 11:1[0-5]’ admin-server.log | grep --color ‘ERROR’ -C 5
查看底部最新300行并且时时刷新,筛选是含有ERROR的前后10行。error色高亮
- tail admin-server.log -n 300 -f |grep ‘ERROR’ -C 10 —color
压缩文件
- tar -czvf writer.tar.gz writer
解压缩
- tar -xzvf writer.tar.gz
递归删除
- rm -rf -r /home/test/lib
移动文件
- mv 源 目标
curl调用http服务
- curl http://ip:port/test/test -X GET -H “appKey-auth:123”
汇总某路径下一共占用多少内存
- du -sh 路径
- ls -lh
- du -h
查看磁盘状况
- df -h
目录占用空间大
- du -sh *
时间同步
更改目录所有者命令
- chown -R 用户名称 目录名称
更改目录权限命令
- chmod -R 755 目录名称
dmesg排查消失的进程
- dmesg |grep java
- dmesg|grep -i kill|less
获取进程详细信息
- ll /proc/42005
查询占用端口号的程序名或pid
- netstat -nlp|grep port
保证某个进程不被内核杀掉可以这样操作
- echo -17 > /proc/$PID/oom_adj
时间相关
- tzselect(5,91,1)
- ntpdate 202.120.2.101 (上海交通大学网络中心NTP服务器地址 ntp.sjtu.edu.cn)
- date ‘+%Y-%m-%d %H:%M:%S’
看端口通不通
- ping ip
- telnet ip port
查进程所在绝对路径
- pwdx PID
linux下获取占用CPU资源最多的10个进程,可以使用如下命令组合
- ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head
查磁盘满了思路
- df -h 找出设备挂载
- du -h --max-depth=1
- ls -lh