MENU

自用Shell实用脚本/命令

March 20, 2021 • Read: 252 • 技术

常用Shell命令集

本文仅缝合我个人常用的Bash指令/脚本以供我自己方便复制粘贴,若有任何问题请去对应Gayhub找作者反馈而不要找我反馈。谢谢合作。

请善用右侧文章目录以获取更好的阅读体验。


实用技巧

Starship

curl -fsSL https://starship.rs/install.sh | bash
Bash:

echo '' >> ~/.bashrc
echo '# Starship Prompt Configuration' >> ~/.bashrc
echo 'eval "$(starship init bash)"' >> ~/.bashrc
source ~/.bashrc

Zsh:

echo '' >> ~/.zshrc
echo '# Starship Prompt Configuration' >> ~/.zshrc
echo 'eval "$(starship init zsh)"' >> ~/.zshrc
source ~/.zshrc

Fish:

echo '' >> ~/.config/fish/config.fish
echo '# Starship Prompt Configuration' >> ~/.config/fish/config.fish
echo 'starship init fish | source' >> ~/.config/fish/config.fish
fish_update_completions

Thefuck 安装

Docker 安装

镜像源:

curl -sSL https://get.daocloud.io/docker | sh

国外源(推荐):

curl -sSL https://get.docker.com/ | sh 
systemctl start docker 
systemctl enable docker

CentOS:

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker

Ubuntu:

apt-get update
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker

常用测速脚本

快速测试:

curl -fsL https://ilemonra.in/LemonBenchIntl | bash -s fast

完整测试:

curl -fsL https://ilemonra.in/LemonBenchIntl | bash -s full
Superbench: 测试硬盘I/O以及中国网路连接

curl -Lso- -no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash

Superspeed: 仅测试中国网路连接

curl -Lso- -no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/superspeed.sh | bash
Bench.sh: 基本系统/性能/网络测试

wget -qO- bench.sh | bash

SuperBench2 + CDN: 新增更多国内测速节点

curl -Lso- -no-check-certificate https://raw.githubusercontent.com/zzycwmx/CDN/master/superbench2.sh | bash

91YunTest: 服务器一键测试

运行参数

io - 硬盘IO测速
bandwidth - 使用Speedtest来测试服务器带宽
chinabw - Speedtest 国内节点测速
download - 使用wget测试世界各地下载
backtraceroute - 回程路由测试
gotoping - 国外ping测试
benchtet - UnixBench跑分测试
参数使用半角逗号分隔,如"io,download"。

当然也可以到官网一键生成脚本。

wget -N --no-check-certificate https://raw.githubusercontent.com/91yun/91yuntest/master/test.sh && bash test.sh -i "<参数>"

流媒体解锁测试脚本

CentOS:

yum install epel-release -y
yum install curl jq -y
bash <(curl -sSL "https://github.com/CoiaPrant/MediaUnlock_Test/raw/main/check.sh")

Ubuntu:

apt install curl jq -y
bash <(bash <(curl -sSL "https://github.com/CoiaPrant/MediaUnlock_Test/raw/main/check.sh"))
bash <(curl -sSL https://raw.githubusercontent.com/xb0or/nftest/main/netflix.sh)

rClone 安装

curl https://rclone.org/install.sh | sudo bash

fGit 安装

git clone https://hub.fastgit.org/FastGitORG/fgit
sudo install -Dm755 fgit/bin/fgit.sh /usr/local/bin/fgit
rm -rf fgit/

Frps Onekey

wget https://raw.fastgit.org/MvsCode/frps-onekey/master/install-frps.sh -O ./install-frps.sh
chmod 700 ./install-frps.sh
./install-frps.sh install

网络配置

BTPanel 7.5.1 / aaPanel

CentOS:

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

Ubuntu:

wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh

更新内容

1.插件列表同步官方
2.升级落后官方版本的插件
3.升级ngnix 防火墙 8.8.4 版本
4.升级第三方插件
5.优化插件服务器

1.移除宝塔插件 【测试版】节点同步工具
2.移除第三方插件 服务器日志分析与流量统计
3.移除第三方插件 frp 服务端管理器(基础版)
4.移除第三方插件 百度网盘管理器

1.增加宝塔插件 腾讯云CDN 插件
2.增加宝塔插件 腾讯云DNS解析 插件
3.增加宝塔插件 腾讯云COSFS 插件
4.增加宝塔插件 宝塔企业防火墙-测试版 插件
5.增加专业版插件 宝塔负载均衡-重构版 插件
6.增加第三方插件 Encryption365™ 免费证书
7.增加第三方插件 花生壳
8.增加第三方插件 宝塔west_fss
9.增加第三方插件 Jexus Http Web Server
10.增加第三方插件 URGoAccess
11.增加第三方插件 GEP分销

企业版破解:

bash <(curl -sSL "https://download.fenhao.me/ltd/install/update6.sh")

专业版破解:

bash <(curl -sSL "https://download.fenhao.me/install/update6.sh")
aaPanel 为 堡塔面板在国外发行的版本,相对纯净。

   请不要使用左侧“Crack”标签中的脚本,aaPanel无需破解

bash <(curl -sSL "http://www.aapanel.com/script/install-ubuntu_6.0_en.sh")

常用端口转发脚本

wget --no-check-certificate -O gost.sh https://raw.githubusercontent.com/KANIKIG/Multi-EasyGost/master/gost.sh && chmod +x gost.sh && ./gost.sh

wget -N --no-check-certificate https://git.io/realm.sh && chmod +x realm.sh && ./realm.sh
rm -rf brook-pf-mod.sh;wget -N --no-check-certificate "https://raw.fastgit.org/yulewang/brook/master/brook-pf-mod.sh"
mkdir /usr/local/brook-pf;cd /usr/local/brook-pf;rm -rf /usr/local/brook-pf/*
wget -N --no-check-certificate "https://www.isyunyi.com/download/linux/brook";chmod +x brook
echo >  /usr/local/brook-pf/brook.conf
wget https://raw.fastgit.org/ToyoDAdoubi/doubi/master/service/brook-pf_centos -O /etc/init.d/brook-pf;chmod +x /etc/init.d/brook-pf;chkconfig --add brook-pf;chkconfig brook-pf on
yum install bind-utils -y
cd ~;chmod +x brook-pf-mod.sh;./brook-pf-mod.sh

Docker版本WebDAV

docker run --name=webdav -d -e USERNAME=<name> -e PASSWORD=<pwd> -v <path>:/webdav -p <port>:80 idelsink/webdav

php Composer 安装

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
# 更改 Composer 服务器地址
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

系统使用

允许root用户登录

修改sshd_config

sudo sed -i 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo service restart sshd

(若需要)设置root用户的密码

sudo passwd root

创建Swap分区

自行替换[size]为整数,单位为M。

dd if=/dev/zero of=/mnt/swap bs=1M count=[size]
mkswap /mnt/swap
swapon /mnt/swap
echo "/mnt/swap swap swap defaults 0 0" >> /etc/fatab
bash <(curl -sSL "https://www.moerats.com/usr/shell/swap.sh")

DD一键重装脚本

wget --no-check-certificate -O AutoReinstall.sh https://git.io/AutoReinstall.sh && bash AutoReinstall.sh
wget -N --no-check-certificate https://raw.githubusercontent.com/veip007/dd/master/dd-od.sh && chmod +x dd-od.sh && ./dd-od.sh
wget -N --no-check-certificate https://raw.githubusercontent.com/veip007/dd/master/dd-gd.sh && chmod +x dd-gd.sh && ./dd-gd.sh

BBR

wget -N --no-check-certificate "https://github.000060000.xyz/tcp.sh" && chmod +x tcp.sh && ./tcp.sh

BBRPlus lkl-haproxy - OVZ 7+

lkl-linux+HaProxy hack 版本 BBRPlus,此脚本在 OpenVZ 上工作良好。
注意: 需要开启 TUN/TAP 和至少 256M 空闲内存。

wget --no-cache -O lkl-haproxy.sh https://github.com/mzz2017/lkl-haproxy/raw/master/lkl-haproxy.sh && bash lkl-haproxy.sh

常见服务器监控卸载

# 卸载阿里云盾
wget http://update.aegis.aliyun.com/download/uninstall.sh
sh uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh
sh quartz_uninstall.sh
# 删除阿里云盾文件残留
pkill aliyun-service
rm -fr /etc/init.d/agentwatch /usr/sbin/aliyun-service
rm -rf /usr/local/aegis*
# 屏蔽阿里云盾IP
iptables -I INPUT -s 140.205.201.0/28 -j DROP
iptables -I INPUT -s 140.205.201.16/29 -j DROP
iptables -I INPUT -s 140.205.201.32/28 -j DROP
iptables -I INPUT -s 140.205.225.192/29 -j DROP
iptables -I INPUT -s 140.205.225.200/30 -j DROP
iptables -I INPUT -s 140.205.225.184/29 -j DROP
iptables -I INPUT -s 140.205.225.183/32 -j DROP
iptables -I INPUT -s 140.205.225.206/32 -j DROP
iptables -I INPUT -s 140.205.225.205/32 -j DROP
iptables -I INPUT -s 140.205.225.195/32 -j DROP
iptables -I INPUT -s 140.205.225.204/32 -j DROP
bash /usr/local/qcloud/stargate/admin/uninstall.sh
bash /usr/local/qcloud/YunJing/uninst.sh
bash /usr/local/qcloud/monitor/barad/admin/uninstall.sh
systemctl stop tat_agent
systemctl disable tat_agent
rm -f /etc/systemd/system/tat_agent.service

COSFS 挂载

# Installation
sudo apt-get install automake autotools-dev g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config fuse -y
git clone https://github.com/tencentyun/cosfs /usr/cosfs && cd /usr/cosfs
./autogen.sh && ./configure && make&& sudo make install
cosfs --version
# Configuration
echo '<BucketName-APPID>:<SecretId>:<SecretKey>' > /etc/passwd-cosfs
cosfs examplebucket-1250000000 /cosfs -ourl=http://cos.ap-guangzhou.myqcloud.com -odbglevel=crit
echo 'cosfs#examplebucket-1250000000 /mnt/cosfs fuse _netdev,url=http://cos.ap-beijing.myqcloud.com,dbglevel=crit,allow_other' >> /etc/fstab

CentOS 7 防火墙基操

systemctl stop firewalld.service
systemctl disable firewalld.service
开放[port]端口

firewall-cmd --zone=public --permanent --add-port=port/[port]

关闭[port]端口

firewall-cmd --zone=public --permanent --remove-port=port/[port]

重载防火墙

firewall-cmd --reload

  余下部分涉及隐私,故禁用。

此处内容需要评论回复后方可阅读

Archives Tip
QR Code for this page
Tipping QR Code