Linux版本区别

CentOS

  • CentOS ISO:DVD是标准安装盘,一般下载这个就可以了,里面包含大量的常用软件,大部分情况下安装时无需再在线下载,体积为4G;
  • Minimal ISO:精简版本,包含核心组件,体积才600多MB;
  • Everything ISO:顾名思义,包含了所有软件组件,当然体积也庞大,高达7G。对完整版安装盘的软件进行补充,集成所有软件;
  • NetInstall ISO:网络安装镜像;
  • LiveGNOME ISO:GNOME桌面版;
  • LiveKDE ISO:KDE桌面版;
  • LiveCD ISO:光盘上运行的系统,类拟于winpe;

常用的指令

linux查看软件的安装位置

使用whereis语句可以查看软件的安装位置

1
2
root@ecs-205380:# whereis git
git: /usr/bin/git /usr/share/man/man1/git.1.gz

可以看到Git的安装路径在/usr/bin/git

用sed插入内容

以下命令表示将这是插入的内容插入到/opt/test.txt文件的第五行前面

1
sed -i '5i 这是插入的内容' /opt/test.txt

创建文件、文件夹

创建文件夹

创建文件夹
1
2
3
mkdir dir # 创建一个名为dir的目录(创建单个文件夹)
mkdir {dir1,dir22} #创建,dir1文件夹和dir2文件夹(都在当前目录下)
mkdir -p dir1/dir2 # 创建dir1,并且在dir目录里面创建dir2(创建多级目录)

删除文件、文件夹

删除文件、文件夹

删除文件
1
2
rm -rf file # 删除file文件(不可恢复)
rm -rf dir # 删除dir文件夹的所有文件(不可恢复)

其实,删除文件和删除文件夹是一样的命令

移动文件、文件夹

移动一个文件或者一个文件夹

移动一共文件或者文件夹
1
mv file ./a  # 意思是将file文件移动到当前文件夹下的a文件夹里面

移动文件或者文件夹的命令是一模一样的

移动多个文件或者文件夹

1
2
3

# 移动多个文件、文件夹时
mv {file1,file2,file3} /home/ # 表示将file1、file2、file3移动到/home目录下

{}来选择多个文件或者多个文件夹

给文件、文件夹重新命名

改名
1
mv file1 file2 # 意思是将file1改名为file2

{}来选择多个文件或者文件夹,细心的你可能发现了,文件改名和文件移动的命令是一样的,其实就是一样的,mv这个命令既是移动也是命名

更改文件、文件夹属性

有时候我们需要给一些文件赋予特殊的权限,比如新建的test.sh脚本文件,我们想要在Linux系统执行这个脚本文件,那我们就要给他执行权限。

赋予权限
1
chmod 777 test.sh # 表示test.sh开放所有权限

查看文件或文件夹大小

查看文件占用大小

查看当前文件夹下的文件大小

1
ls -lh
  • -h:表示以M为单位展示文件大小,如果不加,则表示使用K为单位

查看文件夹占用大小

查看当前文件夹下的文件夹占用大小

1
du -sh *
  • -h:表示以M为单位展示文件大小,如果不加,则表示使用K为单位

Linux解压、压缩命令

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
# .tar
解包:tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)

# .gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName

# .tar.gz 和 .tgz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName

# .bz2
解压1:bzip2 -d FileName.bz2
解压2:bunzip2 FileName.bz2
压缩: bzip2 -z FileName

# .tar.bz2
解压:tar jxvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName

# .bz
解压1:bzip2 -d FileName.bz
解压2:bunzip2 FileName.bz

# .tar.bz
解压:tar jxvf FileName.tar.bz

# .Z
解压:uncompress FileName.Z
压缩:compress FileName

# .tar.Z
解压:tar Zxvf FileName.tar.Z
压缩:tar Zcvf FileName.tar.Z DirName

# .zip
解压:unzip FileName.zip
压缩:zip FileName.zip DirName

# .rar
解压:rar x FileName.rar
压缩:rar a FileName.rar DirName

# .lha
解压:lha -e FileName.lha
压缩:lha -a FileName.lha FileName

# .rpm
解包:rpm2cpio FileName.rpm | cpio -div

# .deb
解包:ar p FileName.deb data.tar.gz | tar zxf -

# .tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp .arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea
解压:sEx x FileName.*
压缩:sEx a FileName.* FileName

添加root权限用户

打开sudoers文件

1
2
su root  				# 进入root时需要输入密码,密码是不显示的
vim /etc/sudoers # 打开sudoers文件

CentOS添加新用户

滑到最下面找到root

root下面添加

1
2
3
新用户名 ALL=(ALL) ALL 
# 新用户必须要存在才能添加
# lilbai518这个用户,我之前已经创建过了

Ubuntu更换源

备份源文件

1
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

打开sources.list文件

打开sources.list文件,将里面的内容全部删掉

1
sudo gedit /etc/apt/sources.list

将下面的代码其中一段复制进去

删完内容后,将以下其中一段代码粘贴进去,粘贴进去后,更新以下源

阿里源
1
2
3
4
5
6
7
8
9
10
11
12
#  阿里源
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

清华源
1
2
3
4
5
6
7
8
9
10
11
12
# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

中科大
1
2
3
4
5
6
7
8
9
10
11
12
#  中科大源

deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
网易
1
2
3
4
5
6
7
8
9
10
11
# 网易163
deb http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse

备份Ubuntu官方源(备份用)

官方源
1
2
3
4
5
6
7
8
9
10
11
#deb cdrom:[Ubuntu 20.04.3 LTS _Focal Fossa_ - Release amd64 (20210819)]/ focal main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ focal main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ focal universe
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://cn.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse

更新源

1
sudo apt-get update

CentOS换源2022.9

CentOS 8 换源

用wget工具下载aliyun最新repo文件

1
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

如果你没有wget工具,那你也可以使用Linux自带的curl工具下载

使用curl工具下载aliyun最新repo文件

1
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

清除缓存

1
yum clean all

生成新的缓存

1
yum makecache

CentOS 7换源

备份一下源

先进入管理员模式

1
su # 输入密码

创建文件夹存放源

1
mkdir /etc/yum.repos.d/repo_backup

复制源文件到repo_baclup

输入cp /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_backup之后,会有以下这样的输出,连续回车即可

1
2
3
4
5
6
7
8
9
[root@localhost yum.repos.d]# cp /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_backup
cp: overwrite ‘./repo_backup/CentOS-Base.repo’?
cp: overwrite ‘./repo_backup/CentOS-CR.repo’?
cp: overwrite ‘./repo_backup/CentOS-Debuginfo.repo’?
cp: overwrite ‘./repo_backup/CentOS-fasttrack.repo’?
cp: overwrite ‘./repo_backup/CentOS-Media.repo’?
cp: overwrite ‘./repo_backup/CentOS-Sources.repo’?
cp: overwrite ‘./repo_backup/CentOS-Vault.repo’?
cp: overwrite ‘./repo_backup/CentOS-x86_64-kernel.repo’?

下载新的CentOS-Base.repo/etc/yum.repos.d/

下载aliyun
1
wget http://mirrors.aliyun.com/repo/Centos-7.repo

清除缓存

1
yum clean all

生成新的缓存

1
yum makecache

安装EPEL(Extra Packages for Enterprise Linux )源

1
yum install -y epel-release

查看启用的yum源和所有的yum源

1
2
yum repolist enabled
yum repolist all

更新源

1
yum -y update

用户、用户组

Linux查看所有用户、用户组

Linux查看所有用户

1
cat /etc/passwd

Linux查看所有用户组

1
cat /etc/group

将某用户添加到某用户组

新增用户组docker: groupadd docker

1
2
gpasswd -a 用户x 用户组y #将用户x添加到用户组y
newgrp 用户组 #刷新用户组

举个栗子-1:将当前用户添加到docker用户组

1
2
gpasswd -a $USER  docker #将当前用户添加到docker用户组
newgrp docker #添加完需要刷新用户组

举个栗子-2:将test用户添加到docker用户组

1
2
gpasswd -a test  docker
newgrp docker #添加完需要刷新用户组

Linux创建新用户、新用户组

新建用户

在Ubuntu中,新增用户有两个指令,useraddadduser,对应着两条删除用户指令userdeldeluser

区别

adduser:会自动为创建的用户指定主目录、系统shell版本,会在创建时输入用户密码。
useradd:需要使用参数选项指定上述基本设置,如果不使用任何参数,则创建的用户无密码、无主目录、没有指定shell版本。

1
useradd 选项 用户名

参数说明:

  • 选项:

    • -c comment 指定一段注释性描述。
    • -d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录。
    • -g 用户组 指定用户所属的用户组。
    • -G 用户组,用户组 指定用户所属的附加组。
    • -s Shell文件 指定用户的登录Shell。
    • -u 用户号 指定用户的用户号,如果同时有-o选项,则可以重复使用其他用户的标识号。
  • 用户名:

    指定新账号的登录名。

新建用户组

1
groupadd 选项 用户组
  • -g :GID 指定新用户组的组标识号(GID)。
  • -o :一般与-g选项同时使用,表示新用户组的GID可以与系统已有用户组的GID相同。

Linux删除用户、用户组

Linux删除用户

我现在需要删除用户名为:git的用户

删除内容

00删除步骤

一键删除用户以及相关信息

  • -r :表示删除用户相关的信息
1
userdel -r git

一般使用userdel -r git已经可以删除干净了,包括以下步骤的信息,如果不放心,可以使用以下步骤查看是否删除干净了

清理passwd

1
vim /etc/passwd

找到开头为git的用户,删除该行

01删除passwd信息

清理shadow

1
vim /etc/shadow

找到git开头的该行,删除该行

02删除shadow信息

清理用户组(可选)

1
vim /etc/group

我新建git用户时,新建的是git用户组,如果你也是新建一样名字的用户,可以删除,或者不删除也不影响

03删除用户组

清理gshadow

1
vim /etc/gshadow

找到git开头的该行,删除它

04删除gshadow信息

删除用户新建的邮箱

1
rm -rf /var/spool/mail/git

删除用户家目录

1
rm -rf /home/git

与服务器传输文件

上传文件到服务器

传输文件夹

1
scp -r 本机路径  username@服务器IP地址:服务器保存文件路径

传输文件

1
scp 本机路径  username@服务器IP地址:服务器保存文件路径

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[C:\~]$ scp -r C:\Users\Administrator\Desktop\会议.txt  lilbai@124.70.8.41:/home/lilbai/Downloads


Connecting to 124.70.8.41:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Password: *************
Start scp session to upload.
会议.txt 752 字节
Sent all of files.
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(124.70.8.41:22) at 23:56:22.

从服务器下载文件到本机

传输文件

1
scp username@IP地址:服务器文件路径 本机文件路径

传输文件夹

1
scp -r username@IP地址:服务器文件路径 本机文件路径

wget工具

wget我们一般用于下载文件最多,一般下载常见的指令有,指定下载文件后重命名、断点续传、后台下载、测试下载链接、增加下载重试次数、一次性下载多文件、将下载文件记录存入日志文件等等,下面我们一个个测试。

直接下载wget

1
2
3
root@ecs:/opt# wget https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0
root@ecs:/opt# ls
3.22.6.0

下载文件后文件名默认是URL最后一个文件名,如上URL下载后的文件名为3.22.6.0

下载文件后重命名 wget -O

1
2
3
root@ecs:/opt# wget -O test.tar.gz https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0
root@ecs:/opt# ls
test.tar.gz 3.22.6.0

指定路径并指定文件名

1
wget -P /opt/file -O inotify-tools.tar.gz https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0

断点续传 wget -c

断点续传一般用于下载大文件较多,或者网络不稳定的情况下用。

比如我们下载GitHub的文件,总所周知,GitHub下载文件完全是看命,有时候很稳定,有时候慢的不得了,用断点续传的话,即使网路不稳定也可以继续下载。

1
wget -c https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0

后台下载 wget -b

后台下载一般也是用于下载大文件时用,大文件下载比较占时间,不可能给他一直站着窗口看他下载吧,放后台下载,我们可以继续做其他的事嘛。

-b 的缩写应该是background,联想记起来也方便。

1
wget -b https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0

测试下载速度 wget -S

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
root@ecs:/opt# wget -S https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0
--2023-01-04 13:14:21-- https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://render.githubusercontent.com
content-disposition: attachment; filename=inotify-tools-3.22.6.0.tar.gz
Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type: application/x-gzip
ETag: "76c8997f7ea7d30c43fd3141bf4d832299d2316ac23165bcbb6b6d673ce22609"
Strict-Transport-Security: max-age=31536000
Vary: Authorization,Accept-Encoding,Origin
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
Date: Wed, 04 Jan 2023 05:14:21 GMT
Transfer-Encoding: chunked
X-GitHub-Request-Id: 8B04:01E5:9A9E:1BAA0:63B50B2D
Length: unspecified [application/x-gzip]
Saving to: ‘3.22.6.0’

3.22.6.0 [ <=> ] 90.74K 317KB/s in 0.3s

2023-01-04 13:14:22 (317 KB/s) - ‘3.22.6.0’ saved [92918]

下载重试次数 wget -t=次数

如果网络有问题或下载一个大文件也有可能失败。wget默认重试20次连接下载文件。

如果需要,你可以使用–t增加重试次数。

1
wget -t=30 https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0

下载多文件 wget -i

list.txt文件放的是下载的URL

1
wget -i list.txt

list.txt文件

1
2
3
URL1
URL2
Url3

存储下载日志wget -o

存储下载日志和下载重命名的的指令都是o,下载重命名文件是-O大写的,日志是小写的,要区分。

1
wget -o download.log https://codeload.github.com/inotify-tools/inotify-tools/tar.gz/refs/tags/3.22.6.0

更多命令

1
wget --help

Linux PS指令

P S(英文全拼:process status)命令用于显示当前进程的状态,类似于 windows 的任务管理器。

语法格式:

1
ps [options] [--help]

查找进程

我们经常需要查询某进程是否正在运行,我们就可以使用ps指令查询了

1
ps -ef | grep 进程关键词
  • -e:显示所有进程

  • -f:全格式显示

  • au:显示较详细的资讯

  • aux:显示所有包含其他使用者的进程

  • 进程关键词:关键词可以是进程全程或一般进程中一段字符,关键词可以模糊查询进程。

查找结果的第二列是**进程号**

示例:

1
ps -aux | grep rp
  • aux:显示所有包含其他使用者的进程,这里使用-ef也是可以的。
  • |:表示管道,用于配合后面的grep过滤使用
  • grep:根据后面的关键词过滤出带有后面关键词的文本

我想查询frps,但我只是搜索rp,结果也可以搜索到frps,这是因为,在全部进程中,含有rp的进程名只有frps有,所以也可以搜索。

01-模糊查询-服务器 - root@ecs-2053820230104-669

Q:细心的同学可能就发现了,为什么搜索结果有两行?有两个进程号?

A:结果返回确实有两行,但真实的返回结果其实只有一行,我们在搜索的时候,使用指令搜索,系统会给我们分配一个进程,这个进程带着我们搜索的关键词去搜索全部进程,然后给我们返回结果,但这个全部进程也包括我们正在运行的搜索进程,所以才出现了有两条结果原因。

显示所有进程信息

  • -ef:显示时会带上进程的部分信息
1
2
3
4
5
6
7
8
# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 2 0 0 2022 ? 00:00:00 [kthreadd]
root 3 2 0 2022 ? 00:00:00 [rcu_gp]
root 4 2 0 2022 ? 00:00:00 [rcu_par_gp]
root 6 2 0 2022 ? 00:00:00 [kworker/0:0H-kblockd]
root 9 2 0 2022 ? 00:00:00 [mm_percpu_wq]
...省略部分结果

显示某用户下的全程进程

1
ps -u usernmae

示例

1
2
3
4
5
6
7
8
9
10
# ps -u root
PID TTY TIME CMD
1 ? 00:05:47 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
6 ? 00:00:00 kworker/0:0H-kblockd
9 ? 00:00:00 mm_percpu_wq
10 ? 00:00:11 ksoftirqd/0
...省略部分结果

显示系统全部进程

显示只有进程名,不包含进程信息

1
2
3
4
5
6
7
8
9
# ps -A
PID TTY TIME CMD
1 ? 00:05:47 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
6 ? 00:00:00 kworker/0:0H-kblockd
9 ? 00:00:00 mm_percpu_wq
...省略部分结果

查看内存/CPU占用前10的进程

查看CPU占用情况、内存占用前10的进程,并自定义输出格式

1
ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head

参数的含义:

  • -e: 显示所有进程信息。
  • -o: 指定输出格式,以逗号分隔列。
  • pid: 进程 ID。
  • ppid: 父进程 ID。
  • %mem: 进程内存占用百分比。
  • %cpu: 进程 CPU 占用百分比。
  • cmd: 进程命令行。

--sort=-%mem 表示按照内存使用率降序排序,换句话说就是从大到小排序。

head 命令则可以限制结果显示前 10 行。

参考文章

Ubuntu下创建新用户