Linux零基础入门全攻略:发展史、虚拟机部署、终端原理与基础命令实操
Linux零基础入门全攻略:发展史、虚拟机部署与基础命令实操
一、前言
Linux 是服务器、云计算、运维、开发领域的基石系统。几乎所有后端服务、容器、云平台都基于 Linux 运行。想要真正掌握运维与网络,必须从 Linux 的起源、系统结构、命令行逻辑从零学起。
本文整理 Linux 完整入门体系:发展史、发行版区别、CentOS 安装流程、Shell 命令基础,适合零基础入门收藏。
二、Linux的前世今生(完整的发展脉络)
1. Multics:一切的开端
早期计算机为批处理模式,一次性提交任务、无法交互、资源利用率极低。
1965 年,MIT、贝尔实验室、GE 联合开发 Multics 分时操作系统,目标是实现多用户、交互式计算。但项目过于庞大复杂、成本高昂,最终贝尔实验室在 1969 年退出项目。
2. Unix 诞生(1969)
贝尔实验室工程师 Ken Thompson 为了运行自己写的太空大战游戏,在老旧 PDP-7 设备上从零开发小型系统。
经典三周开发奇迹:
-
第一周:实现 Shell 解释器
-
第二周:实现文本编辑器
-
第三周:实现汇编器
最初命名为 Unics(单任务系统),后谐音演化成 Unix。
3. Minix:教学开源系统
后续 Unix 商业化、授权昂贵,高校无法教学使用。
1987 年,荷兰教授编写 Minix,专为教学开源,但禁止社区二次修改合并。
4. Linux 内核诞生(1991)
Linus Torvalds 基于 Minix 启发,自行开发全新内核,并公开开源:免费、任何人可修改、可二次分发。1994 年正式发布 Linux 1.0。
5. GNU/Linux 体系
GNU 计划完善了系统工具、命令、程序环境,Linux 只提供内核。因此完整系统称为GNU/Linux。
三、主流linux发行版分类
1. RPM 系(企业服务器主流)
RHEL、CentOS、Rocky、OEL、Fedora
特点:稳定、适配服务器、企业生态完善,运维首选。
2. DEB 系(桌面、渗透、开发)
Debian、Ubuntu、Kali
特点:开源纯粹、社区活跃、适合桌面与开发。
CentOS 与 CentOS Stream 区别
CentOS 7 是经典稳定服务器版本(维护至 2024)。后续红帽推出 CentOS Stream,转为滚动更新的上游测试版本,不再适合生产服务器。
四、Centos 7.9虚拟机标准安装流程
1. 虚拟机硬件配置规范
为保证系统流畅运行,统一标准化配置:
-
新建虚拟机

-
自定义安装

-
下一步

-
稍后安装

-
选择linux版本

-
选择linux的名称和安装位置

-
设置cpu分配为2

-
设置内存为4GB

-
网络使用NAT模式

-
使用默认,下一步

-
默认设置,下一步

-
创建新磁盘

-
配置硬盘,建议设置80到200GB,且为单个文件

-
默认设置,下一步

-
完成设置

-
配置光盘
单击编辑虚拟机设置

设置镜像文件,单击确定

-
开启虚拟机开始安装

-
选择-Install CentOS 7-回车(先单击系统安装界面,通过上下键选择。)

2. 固定网络参数(统一实训环境)
-
选择安装过程中的语言

-
软件选择,选择GUI的模式安装,点击完成


-
选择安装位置,进入之后,默认设置,点击完成


-
关闭kdump

-
配置网络,进入2中设置网络,完成后点完成


-
设置主机名

-
开始安装

-
创建root密码和普通用户

创建root密码为123,单击2次完成

创建普通用户,密码为123,单击2次完成

-
安装完成之后,重启

-
许可证配置


- 完成配置

3.登录

环境界面一直点前进即可

五、Shell 详解与标准命令行语法
1. Shell 核心作用
Shell 是 Linux 命令行解释器,是用户与系统内核的中间桥梁:接收用户输入的命令、解析语法逻辑、转发给内核执行,最终将执行结果回显至终端。Bash 是 CentOS 系统默认、最通用的 Shell 解释器。
2. 命令提示符权限区分
-
$ 提示符:普通用户(fangbing),权限受限,仅可操作自有权限内容
-
# 提示符:root 超级管理员,拥有系统最高权限,可修改所有系统配置
3. 命令行三要素(标准语法)
Linux 命令以空格分隔,固定由三部分组成,语法严谨:
-
命令:首位必选,指定需要执行的操作程序
-
选项:可选,修饰命令执行效果,短选项
-、长选项-- -
参数:可选,命令的操作目标(文件、目录、路径、用户等)
按下回车键,Shell 即刻解析并执行命令。同时支持多命令并行执行,使用 分号 ; 分隔多条命令。
Linux命令行三要素实操演示图
以 ls -l /home 命令为例:
[fangbing@centos7 ~ 19:42:31]$ ls -l /home
总用量 4
drwx------. 16 fangbing fangbing 4096 7月 14 19:42 fangbing
drwx------. 3 laoma laoma 78 7月 14 13:55 laoma
六、高频基础命令全套实操
1. date 时间日期命令
用于查看系统时间、自定义格式化时间、时间偏移计算:
date # 查看本地当前时间
date -u / --utc # 查看UTC标准世界时间
date -d '-1 day' # 查看昨天时间
date -d '100 day' # 查看100天后时间
date -d "-1 year +3 month +10 days" # 复杂时间偏移
date +%Y-%m-%d # 格式化输出年月日
date +%Y/%m/%d # 斜杠格式时间
date命令全套实操效果图
[fangbing@centos7 ~ 19:44:43]$ date
2026年 07月 14日 星期二 19:45:20 CST
[fangbing@centos7 ~ 19:45:20]$ date -u
2026年 07月 14日 星期二 11:45:30 UTC
[fangbing@centos7 ~ 19:45:30]$ date -d '-1 day'
2026年 07月 13日 星期一 19:45:45 CST
[fangbing@centos7 ~ 19:45:45]$ date -d '+100 day'
2026年 10月 22日 星期四 19:46:00 CST
[fangbing@centos7 ~ 19:46:00]$ date -d "-1 year +3 month +10 days"
2025年 10月 24日 星期五 19:46:46 CST
[fangbing@centos7 ~ 19:46:46]$ date +%Y-%m-%d
2026-07-14
[fangbing@centos7 ~ 19:47:16]$ date +%Y/%m/%d
2. passwd 用户密码管理命令
用于修改、锁定、清空用户密码,区分普通用户与 root 管理员权限:
passwd # 普通用户修改自身密码
passwd 用户名 # root修改指定用户密码
passwd -d 用户名 # 清空用户密码,免密登录
passwd -l 用户名 # 锁定用户,禁止登录
passwd -u 用户名 # 解锁锁定用户
passwd密码管理实操图
分别展示普通用户改密、root管理员改密、锁定/解锁用户、清空密码的实操界面,区分不同权限的操作差异。
#普通用户修改密码
[fangbing@centos7 ~ 19:49:03]$ passwd
更改用户 fangbing 的密码 。
为 fangbing 更改 STRESS 密码。
(当前)UNIX 密码:
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[fangbing@centos7 ~ 19:49:21]$
#root用户修改指定用户密码
[fangbing@centos7 ~ 19:49:21]$ su -l root
密码:
上一次登录:二 7月 14 14:55:07 CST 2026:0 上
[root@centos7 ~ 19:50:36]# passwd fangbing
更改用户 fangbing 的密码 。
新的 密码:
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
#清除用户密码
[root@centos7 ~ 19:51:19]# passwd -d fangbing
清除用户的密码 fangbing。
passwd: 操作成功
#锁定用户密码,用户无法登录
[root@centos7 ~ 19:53:00]# passwd -l fangbing
锁定用户 fangbing 的密码 。
passwd: 操作成功
#解锁用户密码,用户可以再登录
[root@centos7 ~ 19:56:50]# passwd -u fangbing
解锁用户 fangbing 的密码。
passwd: 操作成功
3. 文件类型判定:file 命令
精准识别文件、目录、二进制程序、文本文件类型:
file /etc/yum # 判定为目录文件
file /etc/fstab # 判定为ASCII文本文件
file /bin/file # 判定为64位可执行二进制程序
file文件类型判定效果图
演示目录、文本文件、二进制程序三种不同文件的识别结果,帮助读者快速区分Linux各类文件类型。
[root@centos7 ~ 19:56:58]# file /etc/yum
/etc/yum: directory
[root@centos7 ~ 19:57:49]# file /etc/fstab
/etc/fstab: ASCII text
[root@centos7 ~ 19:58:21]# file /bin/file
/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=58f6c8b82ee70887d7136a7181ffc8fa18030cde, stripped
4. 文件查看命令:cat / head / tail / less
cat:一次性读取并输出文件全部内容,适合小文件
核心参数 -A:等价于 -vET,显示所有隐藏字符,行尾标注 $、Tab 键标注 ^I
head:查看文件头部内容,默认前10行,head -n 4 查看前4行
tail:查看文件尾部内容,默认后10行,tail -n 4 查看末尾4行,tail -n +4 从第4行查看至末尾
less:交互式分页查看大文件,支持上下翻页、/ 搜索、n/N 切换搜索结果、q 退出
文件查看命令实操对比图
- cat实操效果图
[root@centos7 ~ 19:58:32]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@centos7 ~ 19:59:50]# cat -A /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4$
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6$
[root@centos7 ~ 20:00:17]# cat /etc/hosts /etc/fstab
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#
# /etc/fstab
# Created by anaconda on Tue Jul 14 10:26:06 2026
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=4c79dc77-5f9e-4863-8050-88869f1ef0ba /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap
- head实操效果图
#默认显示前面10行
[root@centos7 ~ 20:00:37]# head /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
#显示文件前面4行
[root@centos7 ~ 20:02:02]# head -n 4 /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
- tail 实操效果图
#默认显示后面10行
[root@centos7 ~ 20:02:15]# tail /etc/profile
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
#显示最后4行
[root@centos7 ~ 20:05:02]# tail -n 4 /etc/profile
done
unset i
unset -f pathmunge
5. 文件统计:wc 命令
统计文件行数、单词数、字节数,常用于日志统计:
wc -l 文件名 # 统计文件行数
wc -w 文件名 # 统计文件单词数
wc -c 文件名 # 统计文件字节数
wc文件统计命令效果图
以/etc/hosts、/etc/fstab文件为例,展示单文件、多文件的行数、单词数、字节数统计结果,直观看懂统计规则。
[root@centos7 ~ 20:05:17]# wc -l /etc/hosts
2 /etc/hosts
[root@centos7 ~ 20:07:15]# wc -w /etc/hosts
10 /etc/hosts
[root@centos7 ~ 20:07:25]# wc -c /etc/hosts
158 /etc/hosts
[root@centos7 ~ 20:07:34]# wc /etc/hosts /etc/fstab
2 10 158 /etc/hosts
12 60 541 /etc/fstab
14 70 699 总用量
6. Tab 键补全功能
Linux 核心高效技巧,支持命令、选项、参数一键补全:
-
按一次 Tab:唯一匹配内容,自动补全
-
按两次 Tab:匹配内容不唯一,展示所有可选列表
Tab键补全功能演示图
分别演示命令补全、选项补全、路径参数补全三种场景,展示单次Tab、两次Tab的不同效果,帮助读者掌握高效操作技巧。
[root@centos7 ~ 20:08:19]# pas<tab><tab>
passwd paste pasuspender
[root@centos7 ~ 20:10:59]# pass<tab>
#自动显示为
[root@centos7 ~ 20:10:59]# passwd
#补全选项
[root@centos7 ~ 20:10:59]#passwd --d<tab>
#自动显示为
[root@centos7 ~ 20:12:11]# passwd --delete
#补全参数
[root@centos7 ~ 20:12:11]# passwd --delete fan
#自动显示为
[root@centos7 ~ 20:12:11]# passwd --delete fangbing
7. history 历史命令管理
查看、调用、清空历史执行命令,大幅提升操作效率:
history # 查看全部历史命令
history -c # 清空所有历史命令
history历史命令操作效果图
展示查看历史命令、清空历史执行命令的实操界面。
#显示执行的历史命令
[root@centos7 ~ 20:13:40]# history
1 2026-07-14 19:50:36 hostnae
2 2026-07-14 19:50:36 hostname
3 2026-07-14 19:50:36 hostname set-hostname centos7.fangbing.cloud
4 2026-07-14 19:50:36 hostname
5 2026-07-14 19:50:36 cat >> /etc/bashrc <<'EOF'
6 2026-07-14 19:50:36 PS1='[\[\e[91m\]\u\[\e[93m\]@\[\e[92;1m\]\h\[\e[0m\] \[\e[94m\]\W\[\e[0m\] \[\e[35m\]\t\[\e[0m\]]\[\e[93m\]\$\[\e[0m\] '
7 2026-07-14 19:50:36 HISTTIMEFORMAT="%F %T "
8 2026-07-14 19:50:36 EOF
9 2026-07-14 13:55:02 useradd laoma
10 2026-07-14 13:56:51 ls
11 2026-07-14 13:59:05 登出
12 2026-07-14 13:59:12 exit
13 2026-07-14 14:54:25 passwd -l fangbing
14 2026-07-14 14:55:29 passwd -u fangbing
15 2026-07-14 14:56:18 passwd -d fangbing
16 2026-07-14 14:57:25 passwd fangbing
17 2026-07-14 14:59:06 file /tmp/
18 2026-07-14 14:59:16 file /etc/
19 2026-07-14 14:59:33 file /etc/fstab
20 2026-07-14 15:01:00 file /boot/vmlinuz-
21 2026-07-14 15:05:52 cat /etc/fstab
22 2026-07-14 15:06:11 cat -b /etc/fstab
23 2026-07-14 15:09:18 cat -n /etc/fstab
24 2026-07-14 15:12:50 cat -A 自我介绍.txt
25 2026-07-14 15:12:59 exit
26 2026-07-14 19:50:49 passwd fangbing
27 2026-07-14 19:52:37 passwd -d fangbing
28 2026-07-14 19:53:00 psaawd -l fangbing
29 2026-07-14 19:53:08 passwd -l fangbing
30 2026-07-14 19:53:59 passwd -u fangbing
31 2026-07-14 19:54:11 passwd --
32 2026-07-14 19:54:36 passwd --unlock fangbing
33 2026-07-14 19:55:34 passwd fangbing
34 2026-07-14 19:56:50 passwd -l fangbing
35 2026-07-14 19:56:58 passwd -u fangbing
36 2026-07-14 19:57:49 file /etc/yum
37 2026-07-14 19:58:21 file /etc/fstab
38 2026-07-14 19:58:32 file /bin/file
39 2026-07-14 19:59:50 cat /etc/hosts
40 2026-07-14 20:00:17 cat -A /etc/hosts
41 2026-07-14 20:00:37 cat /etc/hosts /etc/fstab
42 2026-07-14 20:02:02 head /etc/profile
43 2026-07-14 20:02:15 head -n 4 /etc/profile
44 2026-07-14 20:05:02 tail /etc/profile
45 2026-07-14 20:05:17 tail -n 4 /etc/profile
46 2026-07-14 20:07:15 wc -l /etc/hosts
47 2026-07-14 20:07:25 wc -w /etc/hosts
48 2026-07-14 20:07:34 wc -c /etc/hosts
49 2026-07-14 20:08:19 wc /etc/hosts /etc/fstab
50 2026-07-14 20:10:39 passwd
51 2026-07-14 20:12:11 passwd --d
52 2026-07-14 20:14:40 history
#清空历史命令
[root@centos7 ~ 20:14:40]# history -c
[root@centos7 ~ 20:15:29]# history
1 2026-07-14 20:15:39 history
8. script 终端操作录制
全程录制终端所有操作与输出,适合实验复盘、作业留存、教学演示:
script -ttime.log record.log # 录制操作+时间日志
exit # 结束录制
scriptreplay -t time.log record.log # 动态回放操作全过程
script终端录制实操图
演示开启录制、执行操作、结束录制、回放录制文件的完整流程,展示生成的日志文件与回放效果。
[root@centos7 ~ 20:15:39]# script -ttime.log record.log
Script started, file is record.log
[root@centos7 ~ 20:16:28]# hello
bash: hello: 未找到命令...
[root@centos7 ~ 20:16:38]# ls -l
总用量 8
-rw-------. 1 root root 1743 7月 14 10:31 anaconda-ks.cfg
-rw-r--r--. 1 root root 1791 7月 14 10:33 initial-setup-ks.cfg
-rw-r--r--. 1 root root 0 7月 14 20:16 record.log
-rw-r--r--. 1 root root 0 7月 14 20:16 time.log
drwxr-xr-x. 2 root root 6 7月 14 11:22 公共
drwxr-xr-x. 2 root root 6 7月 14 11:22 模板
drwxr-xr-x. 2 root root 6 7月 14 11:22 视频
drwxr-xr-x. 2 root root 6 7月 14 11:22 图片
drwxr-xr-x. 2 root root 6 7月 14 11:22 文档
drwxr-xr-x. 2 root root 6 7月 14 11:22 下载
drwxr-xr-x. 2 root root 6 7月 14 11:22 音乐
drwxr-xr-x. 2 root root 6 7月 14 11:22 桌面
[root@centos7 ~ 20:16:58]# exit
exit
Script done, file is record.log
[root@centos7 ~ 20:17:03]# scriptreplay -t time.log record.log
[root@centos7 ~ 20:16:28]# hello
bash: hello: 未找到命令...
[root@centos7 ~ 20:16:38]# ls -l
总用量 8
-rw-------. 1 root root 1743 7月 14 10:31 anaconda-ks.cfg
-rw-r--r--. 1 root root 1791 7月 14 10:33 initial-setup-ks.cfg
-rw-r--r--. 1 root root 0 7月 14 20:16 record.log
-rw-r--r--. 1 root root 0 7月 14 20:16 time.log
drwxr-xr-x. 2 root root 6 7月 14 11:22 公共
drwxr-xr-x. 2 root root 6 7月 14 11:22 模板
drwxr-xr-x. 2 root root 6 7月 14 11:22 视频
drwxr-xr-x. 2 root root 6 7月 14 11:22 图片
drwxr-xr-x. 2 root root 6 7月 14 11:22 文档
drwxr-xr-x. 2 root root 6 7月 14 11:22 下载
drwxr-xr-x. 2 root root 6 7月 14 11:22 音乐
drwxr-xr-x. 2 root root 6 7月 14 11:22 桌面
[root@centos7 ~ 20:16:58]# exit
七、高频 Bash 快捷键(提速必备)
熟练使用快捷键,可大幅提升命令行操作效率,零基础必记:
-
Ctrl + l:清空终端屏幕
-
Ctrl + a / Home:光标快速跳至命令行开头
-
Ctrl + e / End:光标快速跳至命令行末尾
-
Ctrl + u:删除光标至行首所有内容
-
Ctrl + k:删除光标至行尾所有内容
-
Ctrl + 左右方向键:按单词快速跳转光标
-
Ctrl + r:搜索历史执行命令
-
Ctrl + w:向左删除一个参数/单词
-
Esc + .:调用上一条命令的最后一个参数
-
Ctrl + d:退出当前终端会话
八、总结
Linux 历经数十年迭代,从 Unix 雏形、Minix 教学系统,发展为如今主导全球服务器、云计算领域的开源生态。其核心优势在于开源免费、稳定安全、命令行可高度自动化、模块化可灵活定制。
本文覆盖 Linux 入门全核心知识点:系统发展历史、发行版选型、虚拟机标准化部署、Shell 语法、全套基础命令与实操技巧。熟练掌握以上内容,是深耕运维、网络、云计算领域的核心基础,为后续进阶学习打下坚实根基。
更多推荐
所有评论(0)