Home Operation and Maintenance Linux Operation and Maintenance Linux 操作必备 150 个命令,速度收藏~

Linux 操作必备 150 个命令,速度收藏~

Aug 02, 2023 pm 05:36 PM
linux linux command


Linux 操作必备 150 个命令,速度收藏~

linux 命令是对 Linux 系统进行管理的命令。对于 Linux 系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件, Linux 系统管理的命令是它正常运行的核心,与之前的 DOS 命令类似。


linux 命令在系统中有两种类型:内置 Shell 命令和 Linux 命令。


命令 功能说明
线上查询及帮助命令 (2 个)
man 查看命令帮助,命令的词典,更复杂的还有 info,但不常用。
help 查看 Linux 内置命令的帮助,比如 cd 命令。
文件和目录操作命令 (18 个)
ls 全拼 list,功能是列出目录的内容及其内容属性信息。
cd 全拼 change directory,功能是从当前工作目录切换到指定的工作目录。
cp 全拼 copy,其功能为复制文件或目录。
find 查找的意思,用于查找目录及目录下的文件。
mkdir 全拼 make directories,其功能是创建目录。
mv 全拼 move,其功能是移动或重命名文件。
pwd 全拼 print working directory,其功能是显示当前工作目录的绝对路径。
rename 用于重命名文件。
rm 全拼 remove,其功能是删除一个或多个文件或目录。
rmdir 全拼 remove empty directories,功能是删除空目录。
touch 创建新的空文件,改变已有文件的时间戳属性。
tree 功能是以树形结构显示目录下的内容。
basename 显示文件名或目录名。
dirname 显示文件或目录路径。
chattr 改变文件的扩展属性。
lsattr 查看文件扩展属性。
file 显示文件的类型。
md5sum 计算和校验文件的 MD5 值。
查看文件及内容处理命令(21 个)
cat 全拼 concatenate,功能是用于连接多个文件并且打印到屏幕输出或重定向到指定文件中。
tac tac 是 cat 的反向拼写,因此命令的功能为反向显示文件内容。
more 分页显示文件内容。
less 分页显示文件内容,more 命令的相反用法。
head 显示文件内容的头部。
tail 显示文件内容的尾部。
cut 将文件的每一行按指定分隔符分割并输出。
split 分割文件为不同的小片段。
paste 按行合并文件内容。
sort 对文件的文本内容排序。
uniq 去除重复行。oldboy
wc 统计文件的行数、单词数或字节数。
iconv 转换文件的编码格式。
dos2unix 将 DOS 格式文件转换成 UNIX 格式。
diff 全拼 difference,比较文件的差异,常用于文本文件。
vimdiff 命令行可视化文件比较工具,常用于文本文件。
rev 反向输出文件内容。
grep/egrep 过滤字符串,三剑客老三。
join 按两个文件的相同字段合并。
tr 替换或删除字符。
vi/vim 命令行文本编辑器。
文件压缩及解压缩命令(4 个)
tar 打包压缩。oldboy
unzip 解压文件。
gzip gzip 压缩工具。
zip 压缩工具。
信息显示命令(11 个)
uname 显示操作系统相关信息的命令。
hostname 显示或者设置当前系统的主机名。
dmesg 显示开机信息,用于诊断系统故障。
uptime 显示系统运行时间及负载。
stat 显示文件或文件系统的状态。
du 计算磁盘空间使用情况。另外,搜索公众号顶级科技后台回复“API接口”,获取一份惊喜礼包。
df 报告文件系统磁盘空间的使用情况。
top 实时显示系统资源使用情况。
free 查看系统内存。
date 显示与设置系统时间。
cal 查看日历等时间信息。
搜索文件命令(4 个)
which 查找二进制命令,按环境变量 PATH 路径查找。
find 从磁盘遍历查找文件或目录。
whereis 查找二进制命令,按环境变量 PATH 路径查找。
locate 从数据库 (/var/lib/mlocate/mlocate.db) 查找命令,使用 updatedb 更新库。
用户管理命令(10 个)
useradd 添加用户。
usermod 修改系统已经存在的用户属性。
userdel 删除用户。
groupadd 添加用户组。
passwd 修改用户密码。
chage 修改用户密码有效期限。
id 查看用户的 uid,gid 及归属的用户组。
su 切换用户身份。
visudo 编辑 / etc/sudoers 文件的专属命令。
sudo 以另外一个用户身份(默认 root 用户)执行事先在 sudoers 文件允许的命令。
基础网络操作命令(11 个)
telnet 使用 TELNET 协议远程登录。
ssh 使用 SSH 加密协议远程登录。
scp 全拼 secure copy,用于不同主机之间复制文件。
wget 命令行下载文件。
ping 测试主机之间网络的连通性。
route 显示和设置 linux 系统的路由表。
ifconfig 查看、配置、启用或禁用网络接口的命令。
ifup 启动网卡。
ifdown 关闭网卡。
netstat 查看网络状态。
ss 查看网络状态。
深入网络操作命令(9 个)
牛逼啊!接私活必备的 N 个开源项目!赶快收藏吧
nmap 网络扫描命令。
lsof 全名 list open files,也就是列举系统中已经被打开的文件。
mail 发送和接收邮件。
mutt 邮件管理命令。
nslookup 交互式查询互联网 DNS 服务器的命令。
dig 查找 DNS 解析过程。
host 查询 DNS 的命令。
traceroute 追踪数据传输路由状况。
tcpdump 命令行的抓包工具。
有关磁盘与文件系统的命令(16 个)
mount 挂载文件系统。
umount 卸载文件系统。
fsck 检查并修复 Linux 文件系统。
dd 转换或复制文件。
dumpe2fs 导出 ext2/ext3/ext4 文件系统信息。
dump ext2/3/4 文件系统备份工具。
fdisk 磁盘分区命令,适用于 2TB 以下磁盘分区。
parted 磁盘分区命令,没有磁盘大小限制,常用于 2TB 以下磁盘分区。
mkfs 格式化创建 Linux 文件系统。
partprobe 更新内核的硬盘分区表信息。
e2fsck 检查 ext2/ext3/ext4 类型文件系统。
mkswap 创建 Linux 交换分区。
swapon 启用交换分区。
swapoff 关闭交换分区。
sync 将内存缓冲区内的数据写入磁盘。
resize2fs 调整 ext2/ext3/ext4 文件系统大小。
系统权限及用户授权相关命令(4 个)
chmod 改变文件或目录权限。
chown 改变文件或目录的属主和属组。
chgrp 更改文件用户组。
umask 显示或设置权限掩码。
查看系统用户登陆信息的命令(7 个)
whoami 显示当前有效的用户名称,相当于执行 id -un 命令。
who 显示目前登录系统的用户信息。
w 显示已经登陆系统的用户列表,并显示用户正在执行的指令。
last 显示登入系统的用户。
lastlog 显示系统中所有用户最近一次登录信息。
users 显示当前登录系统的所有用户的用户列表。
finger 查找并显示用户信息。
内置命令及其它(19 个)
echo 打印变量,或直接输出指定的字符串
printf 将结果格式化输出到标准输出。
rpm 管理 rpm 包的命令。
yum 自动化简单化地管理 rpm 包的命令。
watch 周期性的执行给定的命令,并将命令的输出以全屏方式显示。
alias 设置系统别名。
unalias 取消系统别名。
date 查看或设置系统时间。
clear 清除屏幕,简称清屏。
history 查看命令执行的历史纪录。
eject 弹出光驱。
time 计算命令执行时间。
nc 功能强大的网络工具。
xargs 将标准输入转换成命令行参数。
exec 调用并执行指令的命令。
export 设置或者显示环境变量。
unset 删除变量或函数。
type 用于判断另外一个命令是否是内置命令。
bc 命令行科学计算器
系统管理与性能监视命令 (9 个)
chkconfig 管理 Linux 系统开机启动项。
vmstat 虚拟内存统计。
mpstat 显示各个可用 CPU 的状态统计。
iostat 统计系统 IO。
sar 全面地获取系统的 CPU、运行队列、磁盘 I/O、分页(交换区)、内存、 CPU 中断和网络等性能数据。另外,搜索公众号Java架构师技术后台回复“面试题”,获取一份惊喜礼包。
ipcs 用于报告 Linux 中进程间通信设施的状态,显示的信息包括消息列表、共享内存和信号量的信息。
ipcrm 用来删除一个或更多的消息队列、信号量集或者共享内存标识。
strace 用于诊断、调试 Linux 用户空间跟踪器。我们用它来监控用户空间进程和内核的交互,比如系统调用、信号传递、进程状态变更等。
ltrace 命令会跟踪进程的库函数调用, 它会显现出哪个库函数被调用。
关机 / 重启 / 注销和查看系统信息的命令(6 个)
shutdown 关机。
halt 关机。
poweroff 关闭电源。
logout 退出当前登录的 Shell。
exit 退出当前登录的 Shell。
Ctrl+d 退出当前登录的 Shell 的快捷键。
进程管理相关命令(15 个)
bg 将一个在后台暂停的命令,变成继续执行 (在后台执行)。
fg 将后台中的命令调至前台继续运行。
jobs 查看当前有多少在后台运行的命令。
kill 终止进程。
killall 通过进程名终止进程。
pkill 通过进程名终止进程。
crontab 定时任务命令。
ps 显示进程的快照。
pstree 树形显示进程。
nice/renice 调整程序运行的优先级。
nohup 忽略挂起信号运行指定的命令。
pgrep 查找匹配条件的进程。
runlevel 查看系统当前运行级别。
init 切换运行级别。
service 启动、停止、重新启动和关闭系统服务,还可以显示所有系统服务的当前状态。

The above is the detailed content of Linux 操作必备 150 个命令,速度收藏~. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1545
276
What is the code number of Bitcoin? What style of code is Bitcoin? What is the code number of Bitcoin? What style of code is Bitcoin? Jul 22, 2025 pm 09:51 PM

As a pioneer in the digital world, Bitcoin’s unique code name and underlying technology have always been the focus of people’s attention. Its standard code is BTC, also known as XBT on certain platforms that meet international standards. From a technical point of view, Bitcoin is not a single code style, but a huge and sophisticated open source software project. Its core code is mainly written in C and incorporates cryptography, distributed systems and economics principles, so that anyone can view, review and contribute its code.

How to make PHP container support automatic construction? Continuously integrated CI configuration method of PHP environment How to make PHP container support automatic construction? Continuously integrated CI configuration method of PHP environment Jul 25, 2025 pm 08:54 PM

To enable PHP containers to support automatic construction, the core lies in configuring the continuous integration (CI) process. 1. Use Dockerfile to define the PHP environment, including basic image, extension installation, dependency management and permission settings; 2. Configure CI/CD tools such as GitLabCI, and define the build, test and deployment stages through the .gitlab-ci.yml file to achieve automatic construction, testing and deployment; 3. Integrate test frameworks such as PHPUnit to ensure that tests are automatically run after code changes; 4. Use automated deployment strategies such as Kubernetes to define deployment configuration through the deployment.yaml file; 5. Optimize Dockerfile and adopt multi-stage construction

How to build an independent PHP task container environment. How to configure the container for running PHP timed scripts How to build an independent PHP task container environment. How to configure the container for running PHP timed scripts Jul 25, 2025 pm 07:27 PM

Building an independent PHP task container environment can be implemented through Docker. The specific steps are as follows: 1. Install Docker and DockerCompose as the basis; 2. Create an independent directory to store Dockerfile and crontab files; 3. Write Dockerfile to define the PHPCLI environment and install cron and necessary extensions; 4. Write a crontab file to define timing tasks; 5. Write a docker-compose.yml mount script directory and configure environment variables; 6. Start the container and verify the log. Compared with performing timing tasks in web containers, independent containers have the advantages of resource isolation, pure environment, strong stability, and easy expansion. To ensure logging and error capture

How to Securely Erase a Hard Drive on Linux How to Securely Erase a Hard Drive on Linux Jul 24, 2025 am 12:08 AM

Confirm the target hard disk device name (such as /dev/sda) to avoid accidentally deleting the system disk; 2. Use sudoddif=/dev/zeroof=/dev/sdXbs=1Mstatus=progress to overwrite the zero value in full disk, which is suitable for most scenarios; 3. Use sudoshred-v-n3/dev/sdX for three random data overwrites to ensure that it cannot be restored; 4. Optionally execute sudobadblocks-wsv/dev/sdX for destructive write tests; finally use sudohexdump-C/dev/sdX|head to verify whether it is all zero and complete safe erasing.

Linux vs Windows: Which Operating System is Better for You? Linux vs Windows: Which Operating System is Better for You? Jul 29, 2025 am 03:40 AM

Windowsisbetterforbeginnersduetoeaseofuse,seamlesshardwarecompatibility,andsupportformainstreamsoftwarelikeMicrosoftOfficeandAdobeapps.2.LinuxoutperformsWindowsonolderorlow-resourcehardwarewithfasterboottimes,lowersystemrequirements,andlessbloat.3.Li

How to Schedule Tasks on Linux with Cron and anacron How to Schedule Tasks on Linux with Cron and anacron Aug 01, 2025 am 06:11 AM

cronisusedforpreciseschedulingonalways-onsystems,whileanacronensuresperiodictasksrunonsystemsthataren'tcontinuouslypowered,suchaslaptops;1.Usecronforexacttiming(e.g.,3AMdaily)viacrontab-ewithsyntaxMINHOURDOMMONDOWCOMMAND;2.Useanacronfordaily,weekly,o

What to do after installing linux What to do after installing linux Jul 23, 2025 am 02:57 AM

AfterinstallingLinux,thefirststepsincludeupdatingyoursystem,installingessentialsoftware,settingupbackupandsecuritymeasures,andcustomizingtheinterfacetosuityourpreferences.1)Updateyoursystemusingtheappropriatecommandforyourdistro(e.g.,sudoaptupdate&am

How to install software on Linux using the terminal? How to install software on Linux using the terminal? Aug 02, 2025 pm 12:58 PM

There are three main ways to install software on Linux: 1. Use a package manager, such as apt, dnf or pacman, and then execute the install command after updating the source, such as sudoaptininstallcurl; 2. For .deb or .rpm files, use dpkg or rpm commands to install, and repair dependencies when needed; 3. Use snap or flatpak to install applications across platforms, such as sudosnapinstall software name, which is suitable for users who are pursuing version updates. It is recommended to use the system's own package manager for better compatibility and performance.

See all articles