常用命令-ubuntu

修改主机名

1
2
hostnamectl # 显示当前主机名
hostnamectl set-hostname xxx

换源

一键换源,参考https://linuxmirrors.cn/

1
bash <(curl -sSL https://linuxmirrors.cn/main.sh)

手动换源

1
2
3
4
5
6
7
8
9
10
11
# 查看源
cat /etc/apt/sources.list
# 备份一下
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 使用阿里源覆盖之前设置
sudo tee -a /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF

更新软件包

1
2
apt update # 只检查,不更新
apt upgrade # 更新已安装的软件包