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 内核诞生1991Linus 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 解释器。配图说明Shell 工作原理流程图可视化展示「用户输入命令→Shell解析→内核执行→结果输出」的完整链路清晰看懂Shell、用户、系统内核三者的交互关系。2. 命令提示符权限区分$ 提示符普通用户fangbing权限受限仅可操作自有权限内容# 提示符root 超级管理员拥有系统最高权限可修改所有系统配置3. 命令行三要素标准语法Linux 命令以空格分隔固定由三部分组成语法严谨命令首位必选指定需要执行的操作程序选项可选修饰命令执行效果短选项-、长选项--参数可选命令的操作目标文件、目录、路径、用户等按下回车键Shell 即刻解析并执行命令。同时支持多命令并行执行使用分号 ;分隔多条命令。Linux命令行三要素实操演示图以ls -l /home命令为例:[fangbingcentos7 ~ 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命令全套实操效果图[fangbingcentos7 ~ 19:44:43]$ date 2026年 07月 14日 星期二 19:45:20 CST [fangbingcentos7 ~ 19:45:20]$ date -u 2026年 07月 14日 星期二 11:45:30 UTC [fangbingcentos7 ~ 19:45:30]$ date -d -1 day 2026年 07月 13日 星期一 19:45:45 CST [fangbingcentos7 ~ 19:45:45]$ date -d 100 day 2026年 10月 22日 星期四 19:46:00 CST [fangbingcentos7 ~ 19:46:00]$ date -d -1 year 3 month 10 days 2025年 10月 24日 星期五 19:46:46 CST [fangbingcentos7 ~ 19:46:46]$ date %Y-%m-%d 2026-07-14 [fangbingcentos7 ~ 19:47:16]$ date %Y/%m/%d2. passwd 用户密码管理命令用于修改、锁定、清空用户密码区分普通用户与 root 管理员权限passwd # 普通用户修改自身密码 passwd 用户名 # root修改指定用户密码 passwd -d 用户名 # 清空用户密码免密登录 passwd -l 用户名 # 锁定用户禁止登录 passwd -u 用户名 # 解锁锁定用户passwd密码管理实操图分别展示普通用户改密、root管理员改密、锁定/解锁用户、清空密码的实操界面区分不同权限的操作差异。#普通用户修改密码 [fangbingcentos7 ~ 19:49:03]$ passwd 更改用户 fangbing 的密码 。 为 fangbing 更改 STRESS 密码。 当前UNIX 密码 新的 密码 重新输入新的 密码 passwd所有的身份验证令牌已经成功更新。 [fangbingcentos7 ~ 19:49:21]$ #root用户修改指定用户密码 [fangbingcentos7 ~ 19:49:21]$ su -l root 密码 上一次登录二 7月 14 14:55:07 CST 2026:0 上 [rootcentos7 ~ 19:50:36]# passwd fangbing 更改用户 fangbing 的密码 。 新的 密码 重新输入新的 密码 抱歉密码不匹配。 新的 密码 无效的密码 密码少于 8 个字符 重新输入新的 密码 passwd所有的身份验证令牌已经成功更新。 #清除用户密码 [rootcentos7 ~ 19:51:19]# passwd -d fangbing 清除用户的密码 fangbing。 passwd: 操作成功 #锁定用户密码用户无法登录 [rootcentos7 ~ 19:53:00]# passwd -l fangbing 锁定用户 fangbing 的密码 。 passwd: 操作成功 #解锁用户密码用户可以再登录 [rootcentos7 ~ 19:56:50]# passwd -u fangbing 解锁用户 fangbing 的密码。 passwd: 操作成功3. 文件类型判定file 命令精准识别文件、目录、二进制程序、文本文件类型file /etc/yum # 判定为目录文件 file /etc/fstab # 判定为ASCII文本文件 file /bin/file # 判定为64位可执行二进制程序file文件类型判定效果图演示目录、文本文件、二进制程序三种不同文件的识别结果帮助读者快速区分Linux各类文件类型。[rootcentos7 ~ 19:56:58]# file /etc/yum /etc/yum: directory [rootcentos7 ~ 19:57:49]# file /etc/fstab /etc/fstab: ASCII text [rootcentos7 ~ 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, stripped4. 文件查看命令cat / head / tail / lesscat一次性读取并输出文件全部内容适合小文件核心参数-A等价于 -vET显示所有隐藏字符行尾标注$、Tab 键标注^Ihead查看文件头部内容默认前10行head -n 4查看前4行tail查看文件尾部内容默认后10行tail -n 4查看末尾4行tail -n 4从第4行查看至末尾less交互式分页查看大文件支持上下翻页、/搜索、n/N 切换搜索结果、q 退出文件查看命令实操对比图cat实操效果图[rootcentos7 ~ 19:58:32]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [rootcentos7 ~ 19:59:50]# cat -A /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4$ ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6$ [rootcentos7 ~ 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 UUID4c79dc77-5f9e-4863-8050-88869f1ef0ba /boot xfs defaults 0 0 /dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swaphead实操效果图#默认显示前面10行 [rootcentos7 ~ 20:00:37]# head /etc/profile # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # Its NOT a good idea to change this file unless you know what you # are doing. Its 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行 [rootcentos7 ~ 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/bashrctail 实操效果图#默认显示后面10行 [rootcentos7 ~ 20:02:15]# tail /etc/profile if [ ${-#*i} ! $- ]; then . $i else . $i /dev/null fi fi done unset i unset -f pathmunge #显示最后4行 [rootcentos7 ~ 20:05:02]# tail -n 4 /etc/profile done unset i unset -f pathmunge5. 文件统计wc 命令统计文件行数、单词数、字节数常用于日志统计wc -l 文件名 # 统计文件行数 wc -w 文件名 # 统计文件单词数 wc -c 文件名 # 统计文件字节数wc文件统计命令效果图以/etc/hosts、/etc/fstab文件为例展示单文件、多文件的行数、单词数、字节数统计结果直观看懂统计规则。[rootcentos7 ~ 20:05:17]# wc -l /etc/hosts 2 /etc/hosts [rootcentos7 ~ 20:07:15]# wc -w /etc/hosts 10 /etc/hosts [rootcentos7 ~ 20:07:25]# wc -c /etc/hosts 158 /etc/hosts [rootcentos7 ~ 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的不同效果帮助读者掌握高效操作技巧。[rootcentos7 ~ 20:08:19]# pastabtab passwd paste pasuspender [rootcentos7 ~ 20:10:59]# passtab #自动显示为 [rootcentos7 ~ 20:10:59]# passwd #补全选项 [rootcentos7 ~ 20:10:59]#passwd --dtab #自动显示为 [rootcentos7 ~ 20:12:11]# passwd --delete #补全参数 [rootcentos7 ~ 20:12:11]# passwd --delete fan #自动显示为 [rootcentos7 ~ 20:12:11]# passwd --delete fangbing7. history 历史命令管理查看、调用、清空历史执行命令大幅提升操作效率history # 查看全部历史命令 history -c # 清空所有历史命令history历史命令操作效果图展示查看历史命令、清空历史执行命令的实操界面。#显示执行的历史命令 [rootcentos7 ~ 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 #清空历史命令 [rootcentos7 ~ 20:14:40]# history -c [rootcentos7 ~ 20:15:29]# history 1 2026-07-14 20:15:39 history8. script 终端操作录制全程录制终端所有操作与输出适合实验复盘、作业留存、教学演示script -ttime.log record.log # 录制操作时间日志 exit # 结束录制 scriptreplay -t time.log record.log # 动态回放操作全过程script终端录制实操图演示开启录制、执行操作、结束录制、回放录制文件的完整流程展示生成的日志文件与回放效果。[rootcentos7 ~ 20:15:39]# script -ttime.log record.log Script started, file is record.log [rootcentos7 ~ 20:16:28]# hello bash: hello: 未找到命令... [rootcentos7 ~ 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 桌面 [rootcentos7 ~ 20:16:58]# exit exit Script done, file is record.log [rootcentos7 ~ 20:17:03]# scriptreplay -t time.log record.log [rootcentos7 ~ 20:16:28]# hello bash: hello: 未找到命令... [rootcentos7 ~ 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 桌面 [rootcentos7 ~ 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 语法、全套基础命令与实操技巧。熟练掌握以上内容是深耕运维、网络、云计算领域的核心基础为后续进阶学习打下坚实根基。