ubuntu常用命令
注意:
1
2
3
4
当使用 apt-get 或 apt 命令安装一个软件包时(或在软件中心安装 DEB 包),APT 包管理器会以 .deb 格式下载软件包及其依赖关系,并将其保存在 /var/cache/apt/archives 文件夹中
## 安装软件
apt install package_name
清除安装软件缓存
1
2
3
4
5
apt-get clean 清除 APT 缓存
apt-get autoclean 只删除那些无法从仓库中下载的包
autoclean: 假设你安装了包 xyz。它的 deb 文件仍然保留在缓存中。如果现在仓库中有新的 xyz 包,那么缓存中现有的这个 xyz 包就已经过时了,没有用了。`autoclean` 选项会删除这种不能再下载的无用包
设置网络
ubuntu22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
1. 查看网络连接名称是否存在
> nmcli con show
NAME UUID TYPE DEVICE
Wired connection 1 cdb09401-937f-395d-81a7-fe992b9b763d ethernet eno1
ethernet-ens106f0 b68d52a5-e540-49d7-a4d6-08e0ddb6e92f ethernet ens106f0
tun0 49dc8ef5-2e2c-4fb8-acab-b7808a684558 tun tun0
Wired connection 2 942fe649-dd49-397c-a065-8c29295850d7 ethernet eno2
Wired connection 7 8392e9f6-987e-36a1-878c-6d74ff241c98 ethernet enxbe3af2b6059f
ethernet-ens106f0-1 3d544e6b-e3ee-4bf5-b81b-4765f125bb5e ethernet --
Wired connection 3 2e0bc01b-92ea-3ad3-9bd2-6d2ad4dd4507 ethernet --
Wired connection 4 d51bc6ff-e8f0-35b1-92ff-e05270c4eb8c ethernet --
Wired connection 5 e993b5a2-0fb6-35f7-80c9-fa656bcb6cdd ethernet --
Wired connection 6 f541333e-1372-3c64-a366-ccc2e93bf7da ethernet --
绿色:表示该网络连接当前是活动的(已连接的)。
黄色:表示该网络连接当前是非活动的,但是在过去曾经被激活过。
白色:表示该网络连接从未被激活过。
2. 修改或新增连接
> nmcli con mod Wired\ connection\ 1 ifname eno1 ipv4.method manual ipv4.addresses 121.46.234.179/29 ipv4.gateway 121.46.234.177 ipv4.dns 119.29.29.29 connection.autoconnect yes
ifname eno1:将网络接口设置为 eno1。
ipv4.method manual:将 IPv4 配置方法设置为手动。
ipv4.addresses 121.46.234.179/29:为网络接口分配了 IP 地址 121.46.234.179,子网掩码为 /29。
ipv4.gateway 121.46.234.177:设置默认网关为 121.46.234.177。
ipv4.dns 119.29.29.29:设置 DNS 服务器地址为 119.29.29.29。
connection.autoconnect yes:设置网络连接在可用时自动连接。
确保 "Wired connection 1" 是正确的连接名称
3. 只配置ip地址
> nmcli connection modify Wired\ connection\ 5 ifname ens106f0 ipv4.method manual ipv4.addresses 10.200.0.11/24 connection.autoconnect yes
将网络连接名称: Wired\ connection\ 5 的ipv4地址改为: 10.200.0.11/24(掩码24)
4. 配置失败,无法修改配置类型的
a. 删除当前的网卡配置信息,会默认变成: 黄色(网卡存在,连接是未激活的)
> nmcli connection delete ethernet-ens106f0(网络连接名称)
b. 删除后会自动变成黄色,直接继续执行修改即可
5. 启停网卡连接
启动> nmcli device connect en02(网卡名称)
停止> nmcli device disconnect en02(网卡名称)
6. 网卡开机自启、不自动连接
禁止开启自启
> nmcli connection modify "Wired connection 2" connection.autoconnect no
查看是否生效
> nmcli connection show "Wired connection 2"|grep connection.autoconnect:
connection.autoconnect: no
7. 修改网络连接名: 修改前查看对应的网络 连接信息
> nmcli connection modify 修改前网络连接名 connection.id 修改后网络连接名
执行命令后,为了使更改生效,你可能需要重新启动网络连接。你可以使用以下命令来重新启动连接:
> nmcli con down "Wired connection 1" && nmcli con up "Wired connection 1"
创建/删除用户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 创建用户 包含 家目录、用户、用户组
adduser(ubuntu通常使用)
1. 不带参数会自动创建主目录;
2. 有人机交互模式,提示操作者按照步骤设置;
直接执行
> adduser newuser
useradd
1. 不带参数,创建用户没有密码和主目录
2. 创建用户的过程,用户名,密码和主目录三个过程是分开进行
1. useradd newuser
2. passwd newuser
3. useradd -d /home/newuser newuser
# 删除用户、用户组、用户家目录
deluser --remove-home cdn
# 添加组,不是替换组
usermod -aG root fyl 将fyl添加至root组
## 删除组
gpasswd -d 用户名 组名
gpasswd -d mth xpt 将mth从xpt中删除
设置文件夹目录下新增
设置sudo权限
1
2
3
4
5
6
7
8
第一种: 文件修改
文件增加一行: /etc/sudoers
newuser ALL=(ALL) ALL
第二种: 命令授权
adduser newuser sudo
本文由作者按照
CC BY 4.0
进行授权