Fundamentals 31 min read

Master Essential Linux Commands: A Complete Beginner’s Guide

This comprehensive guide introduces Linux developers to the most frequently used shell commands, explains the difference between built‑in and external utilities, demonstrates command syntax, options, and practical examples for file manipulation, navigation, searching, process management, and system information, empowering readers to become proficient with the Linux command line.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Essential Linux Commands: A Complete Beginner’s Guide

Linux基本命令

linux平台开发者常用命令,掌握这些基本命令后基本可以熟练使用linux了.

简单认识shell

Shell的最简单定义:命令行解释器(command Interpreter)主要包含:

将使用者的命令翻译给核心(kernel)处理。同时,将核心的处理结果翻译给使用者

保护操作系统 -- 防止用户执行非法指令

执行命令会创建子进程进行执行

我们平常的命令主要是通过shell来和linux内核交互, shell帮我们解释命令给kernel -- shell是一个程序/命令 :/usr/bin/bash ,即bash.

我们链接上服务器时会自动关联上shell程序 -- bash也是一个可执行程序,使用C语言写的

认识命令的基本格式:

# 命令 -[命令选项] ...

内建命令与外部命令

linux命令分为两种.分别是 内建命令 和 外部命令

内建命令: shell内建命令是指bash(或其它版本)工具中集成的命令.

外部命令: 外部命令是安装外部软件所带的命令

其中内建命令要比外部命令有比较高的执行效率。外部命令执行时往往需要fork出(产生出)一个子进程,而内建命令一般不用。

查看命令的类型-type

# type: type [-afptP] 命令

builtin – 内部指令

file – 文件

function – 函数

keyword – 关键字

alias – 别名

unfound – 没有找到

查看命令的使用方法-help

对于内建命令 一般语法为: # help 内建命令 一般是 Linux 命令自带的帮助信息,并不是所有命令都自带这个选项。

而对于外部命令ls,我们想查看命令 ls 的用法:ls --help

# ls --help

mkdir

# mkdir 目录名  //创建目录(linux)/文件夹(win)
# mkdir -p d1/d2/d3/...   //递归创建多个目录

pwd

# pwd  //显式当前目录的绝对路径

touch

创建空文件与修改时间戳

# touch 文件名.后缀          //创建普通文件
# touch 已存在文件           //更新Atime、Ctime

echo

输出字符串或提取后的变量值

# echo "字符串" > 文件 //清空文件再写入

认识路径

# .  //当前路径
# .. //上级路径
# /root/test // linux下的路径
# C:\Users\26390\Desktop // windows路径

ls

显示目录中文件及其属性信息

# ls -l //以list的形式显示更多属性
# ls -t //按时间先后排序
# ls -rt //按时间逆序排序
# ls -ul //以uid形式显示属性
# ls -ld / //只显示路径,不显示内容
# ll -h //human readable

cd

change directory

# cd ~ //进入/home目录
# cd - //回到上一次访问的目录

热键/linux热键

热键:高频被使用的按键,linux中一个热键就是tab键

# 双击tab键 -> 命令自动补齐

tree

把指定目录以树的形式组织并输出到终端的命令,通常需要手动安装。

# tree . //显示当前目录树形结构
# yum install -y tree //安装tree(Ubuntu使用 apt-get)

nano

文本编辑器nano

# nano 文件 //打开文件进行编辑

cat

在终端设备上显示文件内容

# cat 文件 //打印文件内容

gcc

c语言编译器,用于编译c代码

# gcc source.c //编译生成a.out可执行文件
# ./a.out //执行可执行文件

stat

获取文件的属性信息

# stat 文件 //获取文件属性信息

rm

# rm 文件 //删除文件或空目录
# rm -f 文件 //强制删除,不提示
# rm -r 目录 //递归删除目录及其内容
# rm -rf 目录 //强制递归删除

rmdir

# rmdir 目录 //删除空目录

基本认识--创建目录权限

普通用户只能在 /home/自己/... 内创建文件,root可以在任意位置创建。

linux有多少条指令

在阿里云轻量应用级大约有1265条左右。

man

打开C/C++/系统调用等语法手册

# yum install -y man-pages //安装man手册
# man 命令 //查看命令手册

sudo

授权普通用户执行管理员命令

# sudo 命令 //命令提权

cp

拷贝 copy

# cp 文件 目录 //拷贝文件到目录
# cp -r 目录 目录 //递归拷贝目录

mv

移动或重命名文件/目录

# mv 源 目标 //移动或重命名
# mv 旧文件名 新文件名 //仅重命名

wc

统计字节数、单词数、行数

# wc -l 文件 //统计行数
# wc -c 文件 //统计字节数

重定向 > 与 >>

> 为输出重定向(覆盖),>> 为追加重定向

# echo "内容" > 文件 //覆盖写入
# echo "内容" >> 文件 //追加写入

输入重定向 <

< 将文件内容作为标准输入

# cat < 文件 //从文件读取

more 与 less

分页显示文本文件内容

# more 文件 //只能向下翻页
# less 文件 //上下翻页,支持搜索

head 与 tail

显示文件开头或结尾的内容

# head 文件 //默认前10行
# head -n5 文件 //前5行
# tail 文件 //默认后10行
# tail -n3 文件 //后3行

管道 |

将前一条命令的输出作为后一条命令的输入,实现批处理

# cat 文件 | wc -l //统计文件行数

date

显示或设置系统日期与时间

# date //显示当前时间
# date +"%Y-%m-%d_%H:%M:%S" //自定义格式
# date +%s //输出时间戳

cal

显示日历

# cal //当前月份日历
# cal 2023 //显示全年日历
# cal -3 //显示前后月份

find

根据路径和条件搜索指定文件

# find 路径 -name 文件名 //搜索文件

which

快速查找命令所在路径

# which 命令

whereis

显示命令、源代码、手册等的路径位置信息

# whereis 命令

alias

设置命令别名

# alias 别名='命令+选项'

grep

文本/行过滤工具

# grep '关键字' 文件 //过滤包含关键字的行
# grep -v '关键字' 文件 //过滤掉包含关键字的行
# grep -i '关键字' 文件 //忽略大小写
# grep -E 'pattern1|pattern2' 文件 //正则或

top

Linux任务管理器,实时显示系统运行状态

# top //显示进程、CPU、内存等信息

zip 与 unzip

打包并压缩 / 解压 zip 文件

# zip 包名.zip 文件或目录 //打包
# zip -r 包名.zip 目录 //递归打包
# unzip 包名.zip //解压
# unzip 包名.zip -d 目标目录 //指定目录解压

tar

压缩和解压缩文件,常用 tar、tar.gz、tar.bz2 等格式

# tar -czf archive.tgz 文件或目录 //创建 gzip 压缩包
# tar -xzf archive.tgz //解压 gzip 包
# tar -ztvf archive.tgz //查看内容而不解压

bc

数字计算器,支持高精度浮点运算

# bc //进入交互式计算器
# echo "1+2*3/2" | bc //管道计算,结果为4

uname

显示系统内核信息

# uname -a //显示所有信息
# uname -r //显示内核版本

exit

退出终端

# exit //退出终端
# Ctrl+D //等效于 exit

history

显示与管理历史命令记录

# history //显示最近命令
# history > 文件 //保存到文件
# !编号 //执行指定编号的命令
# !! //执行上一条命令

reboot 与 shutdown

重启或关闭系统

# reboot //重启系统
# shutdown -h now //立即关机
# shutdown -r +5 //5分钟后重启

快捷键

Ctrl+S: 暂停终端回显

Ctrl+Q: 恢复回显

Ctrl+C: 中断当前前台进程

Ctrl+D: 发送 EOF,退出终端

Ctrl+R: 反向搜索历史命令

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Shellcommand-lineBashterminal
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.