整理Linux常用命令,方便使用。
1、查看防火墙状态:
##查看火墙状态 systemctl status firewalld firewall-cmd --state
##开启火墙服务 systemctl start firewalld
##关闭火墙服务 systemctl stop firewalld
##开机自动开启 systemctl enable firewalld
##开机不自启 systemctl disable firewalld
##冻结火墙服务 systemctl mask firewalld
##解冻火墙服务 systemctl unmask firewalld
2、查看端口是否开放:
查看状态:lsof -i:端口
开放端口:firewall-cmd --zone=public --add-port=端口/tcp --permanent
# 配置立即生效:firewall-cmd --reload
3、查看目标服务器端口是否开通:telnet ip 端口
4、指定日志输出启动jar包:nohup java -jar xxx.jar >log.out &
5、复制文件:cp -r 需拷贝的文件夹/文件名 目标文件夹/文件名
6、查看ubuntu系统 休眠状态命令:systemctl status sleep.target
7、关闭ubuntu系统休眠:systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
8、修改ubuntu系统DNS重启还原问题:
1、/etc/resolv.conf里面DNS配置是动态文件:sudo vi /etc/resolv.conf
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
2、直接修改/etc/systemd/resolv.conf:sudo vi /etc/systemd/resolv.conf.
[Resolve]
DNS=8.8.8.8 8.8.4.4
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no-negative
#DNSStubListener=yes
#ReadEtcHosts=yes
3、依次执行命令:
sudo systemctl restart systemd-resolved
sudo systemctl enable systemd-resolved
sudo mv /etc/resolv.conf /etc/resolv.conf.bak
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
4、sudo reboot重启服务器,查看DNS配置生效。
9、解压缩zip文件、压缩文件为zip文件
解压缩:unzip file.zip -d /path/to/destination ,file.zip需要解压的文件名称,-d 文件解压位置。
压缩文件夹:zip -r compressed_folder.zip folder_to_compress,compressed_folder.zip想要压缩的名称,folder_to_compress文件夹名称。