LINUX常用命令记录

查看分区大小

df -h

端口情况

ss -tnl
lsof -i:端口号
lsof -i:8080:查看8080端口占用
lsof abc.txt:显示开启文件abc.txt的进程
lsof -c abc:显示abc进程现在打开的文件
lsof -c -p 1234:列出进程号为1234的进程所打开的文件
lsof -g gid:显示归属gid的进程情况
lsof +d /usr/local/:显示目录下被进程开启的文件
lsof +D /usr/local/:同上,但是会搜索目录下的目录,时间较长
lsof -d 4:显示使用fd为4的进程
lsof -i -U:显示所有打开的端口和UNIX domain文件

netstat -tunlp | grep 端口号
netstat -ntlp //查看当前所有tcp端口
netstat -ntulp | grep 80 //查看所有80端口使用情况
netstat -ntulp | grep 3306 //查看所有3306端口使用情况

内存

free -h

防火墙

启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

  • 查看版本: firewall-cmd --version
    查看帮助: firewall-cmd --help
    显示状态: firewall-cmd --state
    查看所有打开的端口: firewall-cmd --zone=public --list-ports
    更新防火墙规则: firewall-cmd --reload
    查看区域信息: firewall-cmd --get-active-zones
    查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
    拒绝所有包:firewall-cmd --panic-on
    取消拒绝状态: firewall-cmd --panic-off
    查看是否拒绝: firewall-cmd --query-panic
怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent

调整默认策略(默认拒绝所有访问,改成允许所有访问):
firewall-cmd --permanent --zone=public --set-target=ACCEPT
firewall-cmd --reload
对某个IP开放多个端口:
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.159.60.29" port protocol="tcp" port="1:65535" accept"
firewall-cmd --reload

进程
pstree -p 查看sh进程树
ps aux 查看当前正在运行的程序
tty 查看当前终端设备
ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | less 执行以上命令可查看各个程序进程内存使用的内存情况

VSZ:虚拟内存占用大小,单位:kb(killobytes)
RSS:实际内存占用大小,单位:kb(killobytes)
%CPU:进程占用CPU百分比
%MEM:进程占用内存百分比
TTY:终端类型
STAT:进程状态
START:进程启动时刻
TIME:进程运行时长

ps -aux|grep 进程名字
ps -aux 查看所有进程
删除进程 kill -9 3664(具体进程号)

1.CPU占用最多的前10个进程:
ps auxw|head -1;ps auxw|sort -rn -k3|head -10

2.内存消耗最多的前10个进程
ps auxw|head -1;ps auxw|sort -rn -k4|head -10

3.虚拟内存使用最多的前10个进程
ps auxw|head -1;ps auxw|sort -rn -k5|head -10

查看更详细的内存占比

cat /proc/15816/status 其中VmRSS为进程所占用的内存

%MEM 进程的内存占用率
MAJFL is the major page fault count,
VSZ 进程所使用的虚存的大小
RSS 进程使用的驻留集大小或者是实际内存的大小(RSS is the “resident set size” meaning physical memory used)
TTY 与进程关联的终端(tty)

history

history 查看历史命令
history -c 清空历史
!20(命令编号) 执行这条历史命令
mandb 命令数据库介绍安装
whatis ls 查看当前命令用途
type 查看当前命令属于内部还是外部命令

posted @ 2023-03-15 17:27  freedomlog  阅读(39)  评论(0编辑  收藏  举报