linux@提高shell命令行环境易用性@终端美化@国内网络环境友好一条龙美化(ohmyzsh)
windows上msys2也使用pacman来管理软件包,pacman可以获取很新的软件包,并且换源简单,而且安装速度很快。可以分别检查以下软件包,如果已经安装过的,就从列表中删除,避免重复按装浪费资源。安装fzf(建议用brew来安装,版本比较新,apt安装的版本比较老)先更换软件镜像源(不同发行版有不同的源,另见它文),然后执行下列任务。如果服务器在国外,那么访问github比较快,可以不用更
文章目录
快速linux命令行美化指南
- 主要适配于Debian系的linux发行版
- 由于不同发行版换源的动作各有差异,这里就不展开了(默认用户都搞定了,最好还搞定了ssh链接)
- 主要介绍利用Oh my zsh来美化,并且在国内网络环境下也能够快速下载安装的开门见山的脚本集合
- 理想情况下,不需要太多时间就可以完成部署.
环境准备:换国内源加速
如果是国外服务器,通常不需要此环节,直接跳转到"基础软件"开始
先更换软件镜像源(不同发行版有不同的源,另见它文),然后执行下列任务
ubuntu 22
# ubuntu 更换国内镜像源(清华源为例)
# 备份:backup the origin source.list(or just rename(use move command))
# 注意sources.list 不要拼错(带s)
cd /etc/apt
sudo mv sources.list sources.list.bak_bySh
# 切换到家目录,写入国内镜像源到一个文件中(文件名为sources.list),采用多行输入的方式写入
#这里以阿里源为例
cd ~
# 多行输入
sudo tee >sources.list <<EOF
#换源内容粘贴在这里面
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
#结束文档
EOF
#上面的EOF间的内容不要写入其他与源无关的内容(除了注释和源,其他命令不要写在里头)
# 检查写入的内容:
echo "check the conetent of the file 'source.list'"
## 将家目录下的sources.list 转移到/etc/apt目录下(sodu可以作用与mv/cp等命令,
## 但好像不可以直接作用于cat,所以没有直接在/etc/apt目录下创建新文件)
sudo mv sources.list /etc/apt
cat /etc/apt/sources.list
# 更新并使得apt配置文件生效
echo "updating the apt..."
sudo apt update
#可选的升级
#sudo apt upgrade
ubuntu 24ltsc
传统格式
以ubuntu 24 ltsc为例的一键换源脚本(模板)
# ubuntu 更换国内镜像源(清华源为例)
# 备份:backup the origin source.list(or just rename(use move command))
# 注意sources.list 不要拼错(带s)
cd /etc/apt
sudo mv sources.list sources.list.bak_bySh
# 切换到家目录,写入国内镜像源到一个文件中(文件名为sources.list),采用多行输入的方式写入
#这里以阿里源为例
cd ~
# 多行输入
sudo tee >sources.list <<EOF
#换源内容粘贴在这里面
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
#结束文档
EOF
#上面的EOF间的内容不要写入其他与源无关的内容(除了注释和源,其他命令不要写在里头)
# 检查写入的内容:
echo "check the conetent of the file 'source.list'"
## 将家目录下的sources.list 转移到/etc/apt目录下(sodu可以作用与mv/cp等命令,
## 但好像不可以直接作用于cat,所以没有直接在/etc/apt目录下创建新文件)
sudo mv sources.list /etc/apt
cat /etc/apt/sources.list
# 更新并使得apt配置文件生效
echo "updating the apt..."
sudo apt update
#可选的升级
#sudo apt upgrade
deb格式
cd /etc/apt/sources.list.d
#sudo vim tuna.sources
# 多行输入
sudo tee tuna.sources <<EOF
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble noble-updates noble-backports
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# Types: deb-src
# URIs: http://security.ubuntu.com/ubuntu/
# Suites: noble-security
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 预发布软件源,不建议启用
# Types: deb
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# # Types: deb-src
# # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# # Suites: noble-proposed
# # Components: main restricted universe multiverse
# # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
#结束文档
EOF
# 最后将原来的`ubuntu.sources`移动到备份目录
cd /etc/apt/sources.list.d
sudo mkdir /etc/apt/sources.list.d/bak
sudo mv ubuntu.sources ./bak
#执行刷新
sudo apt update
kali-linux
# 备份:backup the origin source.list(or just rename(use move command))
# 注意sources.list 不要拼错(带s)
cd /etc/apt
sudo mv sources.list sources.list.bak_bySh
# 切换到家目录,写入国内镜像源到一个文件中(文件名为sources.list),采用多行输入的方式写入
#这里以阿里源为例
cd ~
# 多行输入[国内源]
cat >sources.list <<EOF
deb https://mirrors.aliyun.com/kali kali-rolling main non-free contrib
deb-src https://mirrors.aliyun.com/kali kali-rolling main non-free contrib
EOF
#上面的EOF间的内容不要写入其他与源无关的内容(除了注释和源,其他命令不要写在里头)
# 检查写入的内容:
echo "check the conetent of the file 'source.list'"
## 将家目录下的sources.list 转移到/etc/apt目录下(sodu可以作用与mv/cp等命令,
## 但好像不可以直接作用与cat,所以没有直接在/etc/apt目录下创建新文件)
sudo mv sources.list /etc/apt
cat /etc/apt/sources.list
# 更新并使得apt配置文件生效
echo "updating the apt..."
sudo apt update
# 其他写法:探索中
# sourceCN="
# deb https://mirrors.aliyun.com/kali kali-rolling main non-free contrib
# deb-src https://mirrors.aliyun.com/kali kali-rolling main non-free contrib
# "
# echo $sourceCN
# sudo cat>>source.list<<EOF
# echo $sourceCN
# EOF
基础软件🎈
apt系列
# 工作目录设定为用户家目录
cd ~
sudo apt update
sudo apt install zsh curl git man wget -y
pacman系列
可以分别检查以下软件包,如果已经安装过的,就从列表中删除,避免重复按装浪费资源
windows上msys2也使用pacman来管理软件包,pacman可以获取很新的软件包,并且换源简单,而且安装速度很快
cd ~
pacman -S zsh curl git man wget
Oh my zsh
-
https://github.com/ohmyzsh/ohmyzsh
-
镜像加速站:Gitee 极速下载/oh-my-zsh
-
以下两种安装方式,如果网络环境不好,容易失败
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
基础软件环境准备
参考上一节
安装命令
国外环境安装omz
注意,仍然要预先安装依赖软件(比如zsh,git等)
如果服务器在国外,那么访问github比较快,可以不用更改源
ohmyzsh/ohmyzsh basic installation
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 或
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
Basic Installation:
Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either curl, wget or another similar tool.
| Method | Command |
|---|---|
| curl | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| wget | sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| fetch | sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
国内ip的额外选择
Alternatively, the installer is also mirrored outside GitHub. Using this URL instead may be required if you’re in a country like China or India (for certain ISPs), that blocks raw.githubusercontent.com:
| Method | Command |
|---|---|
| curl | sh -c "$(curl -fsSL https://install.ohmyz.sh/)" |
| wget | sh -c "$(wget -O- https://install.ohmyz.sh/)" |
| fetch | sh -c "$(fetch -o - https://install.ohmyz.sh/)" |
Note that any previous .zshrc will be renamed to .zshrc.pre-oh-my-zsh. After installation, you can move the configuration you want to preserve into the new .zshrc.
国内gitee源安装方式
# 工作目录设定为用户家目录
cd ~
wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
# 由于国内网络问题,可能需要多尝试几次一下source 命令才可以安装成功.(我将其注释掉,采用换源后再执行clone
#source install.sh
#本段代码将修改install.sh中的拉取源,以便您能够冲gitee上成功将需要的文件clone下来.
# 本段代码会再修改前做备份(备份文件名为install.shE)
sed '/(^remote)|(^repo)/I s/^#*/#/ ;
/^#*remote/I a\
REPO=${REPO:-mirrors/oh-my-zsh}\
REMOTE=${REMOTE:-https://gitee.com/${REPO}.git} ' -r ~/install.sh > gitee_install.sh
# 执行安装
source gitee_install.sh
#返回到脚本所在目录(以便执行新的脚本)
cd -
修改默认shell(可选)
使用chsh命令来修改默认shell
查看可用shell
chsh -l
切换默认shell,例如将当前用户默认shell改为/usr/bin/zsh
chsh -s /usr/bin/zsh
omz+常用插件部署
这里是手动操作说明,可以直接使用下一节中的一键部署方案.
这里推荐插件(让体验向fish靠拢):
- zsh-users/zsh-autosuggestions: Fish-like autosuggestions for zsh (github.com)
- zsh-users/zsh-syntax-highlighting: Fish shell like syntax highlighting for Zsh.
- zsh-users/zsh-history-substring-search: 🐠 ZSH port of Fish history search (up arrow)
- marlonrichert/zsh-autocomplete: 🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.
下面是基本步骤(下一节提供一键部署脚本)
-
下载插件到对应的目录(
.oh-my-zsh)-
使用浅克隆加速
# 将两个插件下载到指定目录下:(git 已经指定好了目录) git clone --depth 1 https://gitee.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions git clone --depth 1 https://gitee.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting git clone --depth 1 https://gitee.com/mirror-hub/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search # zsh-completions这个项目gitee官方可能没有镜像,使用个人用户的自镜像版本(建议有需要的可以自己拉取一份比较安全) # 另外这个插件比其他zsh插件不同,在配合oh my zsh使用时需要额外注意配置文件的写法; git clone --depth 1 https://gitee.com/duchenpaul/zsh-completions.git \ ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions
-
-
调用sed来配置.zshrc文件,将相关插件配置到zsh插件(plugins)中
-
进入到zsh刷新
~/.zshrc,让zsh的配置生效(直接输入zsh即可) -
配置oh my zsh主题
一键在线部署命令🎈
注意,第一次使用,可能需要运行2次.
bash <(curl -sSfL https://gitee.com/xuchaoxin1375/scripts/raw/main/wp/woocommerce/woo_df/sh/deploy_omz.sh) -s gitee
-
国内可以考虑用gitee,但是可能要登录账号;如果有需要,还可以将链接中的gitee换为github
-
使用
-h获取使用帮助 -
这里的链接gitee也可以换成github
其他
针对ubuntu
美化ls的输出
使用lsd,eza等现代化的ls代替品来提高列举体验
修改系统时间
修改为北京时间
sudo timedatectl set-timezone Asia/Shanghai
主机名
sudo hostnamectl set-hostname "NewHostName"
#重载日志服务(否则许多日志还是使用旧主机名,例如:/var/log/auth.log)
systemctl restart rsyslog
然后启动一个新shell查看变化
配置fzf
-
安装fzf(建议用brew来安装,版本比较新,apt安装的版本比较老)
-
绑定shell
openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构
更多推荐


所有评论(0)