常用linux命令

mac2024-01-25  43

文章目录

查看文件内容编辑文件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.logtail -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 portnetstat -nultplsof -i:port

Linux中怎么通过PID号找到对应的进程名及所在目录

ps -aux |grep -v grep|grep PID

从根目录下查找指定名称的文件

find / -name tomcat

杀进程

kill -9 PID

远程登陆

ssh root@106.15.186.155 ->输入密码:xxxxssh -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 stopchkconfig iptables on/service iptables startservice iptables restart centos7 systemctl stop firewalldsystemctl start firewalldfirewall-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

防火墙删除端口

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 -lhdu -h

查看磁盘状况

df -h

目录占用空间大

du -sh *

时间同步

更改目录所有者命令

chown -R 用户名称 目录名称

更改目录权限命令

chmod -R 755 目录名称

dmesg排查消失的进程

dmesg |grep javadmesg|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 iptelnet 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=1ls -lh
最新回复(0)