Liunx常用相关指令
创建文件目录及
touch xxx.txt xxx2.txt 创建文件
mkdir xxx 创建文件夹
chmod +x file 设置可执行程序
chmod 755 catalogs 目录权限
444 r--r--r--
600 rw-------
644 rw-r--r--
666 rw-rw-rw-
700 rwx------
744 rwxr--r--
755 rwxr-xr-x
777 rwxrwxrwx rwx所有者具有读取、写入、执行权限
查看目录大小
du -sh 路径 #查看指定目录的总大小,加空格可看多个
du -h 路径 #查看目录中每个子目录的大小
更新包
apt autoremove && apt-get dist-upgrade 一条龙搞定
解压
rar a -r test.rar file tar压缩
tar -zxvf FileName.tar.gz tar解压
zip -r test.zip file zip压缩
unzip FileName.zip zip解压
复制移动文件
mv 源文件路径 目标目录 移动
cp 源文件路径 目标目录 复制
查找
find / -name xxx 根据名称全盘查找
ps -ef | grep 名称 获取进程PID
ps -p 进程PID -o comm= 返回完整进程名称
后台挂起
nohup python xxx & tail -f file nohup挂起xxx后台运行file
nohup bash MonitoringScripts.sh nohup挂起脚本
screen -S 名称 python3 myscript.py screen开启新窗口
Ctrl + a + d 后台挂起窗口
screen -ls 查看所有窗口
screen -r 切入窗口
screen -r 名称 确如指定窗口
screen -S 名称 -X quit 关闭窗口
pyinstaller打包
pyinstaller -w -F 青之OCR识别.py
-w:打包程序运行后隐藏控制台窗口
-F:单文件模式。在打包完成后只会生成一个单独的exe文件
青之OCR识别.py:要打包的文件名称
docker相关
docker ps 正在运行的容器
docker start $(docker ps -a | awk '{ print $1}' | tail -n +2) 启动所有容器
docker ps -aq 列出所有容器的ID
docker stop $(docker ps -aq) 停止所有容器
docker rm $(docker ps -aq) 删除所有容器
docker rmi $(docker images -q) 删除所有镜像
如果您使用的是 Docker Compose 来管理多个容器
docker-compose up -d 启动docker-compose所有容器,注意:进入配置文件目录启动
docker-compose stop 停止所有服务
docker-compose stop Server-name 停止指定名称的服务
查看后台运行服务
top 实时显示最活跃的进程
top -d 10 每10秒更新一次进程列表
htop 可视化的进程监视器
vim粘贴原格式
set paste 进入指令模式 使用paste模式粘贴
文件上传下载
scp -p 22 用户名@IP:/root/shell文件.sh /home/ubuntu/桌面/ #服务下载文件
scp /home/ubuntu/桌面/shell文件.sh 用户名@IP:/root/ #服务上传文件
ubuntu22.04防火墙
ufw status 查看防火墙状态
ufw disable 禁用防火前
ufw enable 启用防火墙
ufw allow 6500:6800/tcp 允许使用 TCP 的端口范围
ufw allow 6500:6800/udp 允许使用 UDP 的端口范围
ufw allow from 192.168.1.1 允许指定 IP 地址连接
设置防火墙规则
iptables -F 清空所有现有的防火墙过滤规则。
iptables -X 删除所有自定义的防火墙规则链,不包括默认的规则链。
iptables -Z 将所有防火墙规则的流量计数器归零,但保持规则不变。
开放 22, 80, 和 443 端口的进入流量
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
确保已经建立的连接可以继续通信。
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables-save 保存规则
关机重启
shutdown -h now 立即关机
reboot 重启
端口相关
nmap IP 查看开启端口
nmap -sP www.xxx.com/24 || namp -sP 192.168.1.* #C段存活主机探测
nmap -A -v -p1-1000 -Pn -T4 -sS 175.6.245.227 --script http-methods --script-args http.useragent="Mozilla/5.0(macintosh; Intel mac OS x 10.15; rv:87.0)Gecko/20100101 Firefox/87.0" #绕安全检测
软件设置
systemctl enable 名称 程序开机自启
systemctl start 名称 启动程序
systemctl status 名称.service 查看程序状态
systemctl restart 名称.service 重启程序
systemctl reload 名称 重新加载程序配置文件
BBR拥塞控制算法
#Linux内核4.9或以上
uname -r
#输入一下命令启用TCP BBR
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
#保存文件并应用新的系统配置
sysctl -p
#确认BBR已经启动
sysctl net.ipv4.tcp_congestion_control
#查看BBR是否工作
lsmod | grep bbr
域名证书相关
安装证书工具
curl https://get.acme.sh | sh; apt install socat -y || yum install socat -y; ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
申请证书
~/.acme.sh/acme.sh --issue -d 你的域名 --standalone -k ec-256 --force --insecure
安装证书
~/.acme.sh/acme.sh --install-cert -d 你的域名 --ecc --key-file /安装目录的路径/server.key --fullchain-file /安装目录的路径/server.crt
命令 | 用法 |
---|---|
man | 显示其他命令的手册页面 |
shutdown | 关闭您的机器 |
htop | 显示进程和资源信息 |
apt,yum,pacman | 包管理器 |
echo | 显示文本行 |
cat | 打印文件内容 |
vim | 高效文本编辑 |
history | 显示以前的命令列表 |
which | 返回程序的完整二进制路径 |
shred | 覆盖文件以隐藏其内容 |
less | 以交互式检查文件 |
tail -f /home/aa.log | 实时查看日志 |
head | 显示文件的第一行 |
grep | 打印与给定条件匹配行 |
whoami | 输出用户名 |
whatis | 显示单行说明 |
wc | 字数文件 |
uname | 显示操作系统信息 |
neofetch | 显示操作系统和硬件信息 |
wget | 从互联网检索文件 |