Linux 常用命令可分为以下几类,以下是分类整理和示例说明:
ls
ls -l
(详细信息)ls -a
(显示隐藏文件)cd
cd ~
(返回家目录)cd ..
(返回上级目录)pwd
mkdir
mkdir -p dir1/dir2
(递归创建)rm
rm -r dir
(递归删除目录)rm -f file
(强制删除)cp
cp -r dir1 dir2
(递归复制目录)mv
mv old.txt new.txt
(重命名)mv file /path/
(移动文件)touch
cat
cat file1 file2 > combined
(合并文件)less
/ more
less
支持上下滚动)head
/ tail
tail -f logfile
(实时追踪日志)find
find /path -name "*.txt"
(按名称搜索)grep
grep "keyword" file
grep -r "pattern" /dir
(递归搜索)chmod
chmod 755 file
(数字模式)chmod u+x script.sh
(符号模式)chown
chown user:group file
sudo
sudo apt update
uname
uname -a
(全部信息)df
df -h
(人类可读格式)du
du -sh /dir
(汇总大小)top
/ htop
free
free -h
ps
ps aux | grep nginx
kill
kill -9 PID
(强制终止)ping
ping example.com
ifconfig
/ ip addr
ip addr
更现代)netstat
netstat -tulnp
(监听端口)ssh
ssh user@host
scp
scp file user@host:/path
wget
/ curl
wget https://example.com/file
curl -O URL
tar
tar -czvf archive.tar.gz dir
(压缩)tar -xzvf archive.tar.gz
(解压)gzip
/ gunzip
.gz
文件zip
/ unzip
useradd
/ userdel
useradd -m username
(创建家目录)passwd
passwd username
su
su - username
(加载环境变量)Debian/Ubuntu (APT)
sudo apt update
(更新源)sudo apt install package
sudo apt remove package
RHEL/CentOS (YUM/DNF)
sudo yum install package
sudo dnf remove package
alias
alias ll='ls -alF'
history
!n
(执行历史记录第 n 条命令)crontab
crontab -e
(编辑任务)ln
ln -s /path/file link
(软链接)man command
(如 man ls
)查看命令手册。|
(如 ps aux | grep python
)。rm -rf
)。掌握这些命令后,Linux 日常操作和故障排查效率会大幅提升!