ls
📁
文件管理
列出目录内容
ls [选项] [目录]
ls -lals -lh /homels -R /var/log
cp
📁
文件管理
复制文件或目录
cp [选项] 源文件 目标文件
cp file1.txt file2.txtcp -r dir1 dir2cp -v *.txt /backup/
mv
📁
文件管理
移动或重命名文件
mv [选项] 源文件 目标文件
mv old.txt new.txtmv file.txt /home/user/mv -i *.log /logs/
rm
📁
文件管理
删除文件或目录
rm [选项] 文件
rm file.txtrm -rf /tmp/test/rm -i *.bak
touch
📁
文件管理
创建空文件或更新时间戳
touch [选项] 文件
touch newfile.txttouch -t 202401011200 file.txttouch -d '2024-01-01' file.txt
cat
📁
文件管理
查看文件内容
cat [选项] 文件
cat file.txtcat -n file.txtcat file1.txt file2.txt > merged.txt
head
📁
文件管理
显示文件开头
head [选项] 文件
head file.txthead -n 20 file.txthead -c 100 file.txt
tail
📁
文件管理
显示文件末尾
tail [选项] 文件
tail file.txttail -f /var/log/syslogtail -n 50 file.txt
cd
📂
目录操作
切换目录
cd [目录]
cd /home/usercd ..cd -
pwd
📂
目录操作
显示当前目录
pwd [选项]
pwdpwd -P
mkdir
📂
目录操作
创建目录
mkdir [选项] 目录名
mkdir newdirmkdir -p /a/b/cmkdir -m 755 mydir
rmdir
📂
目录操作
删除空目录
rmdir [选项] 目录名
rmdir emptydirrmdir -p a/b/c
grep
📝
文本处理
文本搜索
grep [选项] 模式 文件
grep 'error' log.txtgrep -rn 'TODO' ./src/grep -i 'warning' *.log
sed
📝
文本处理
流编辑器
sed [选项] '命令' 文件
sed 's/old/new/g' file.txtsed -i 's/foo/bar/g' file.txtsed -n '1,10p' file.txt
awk
📝
文本处理
文本分析工具
awk [选项] '模式 {动作}' 文件
awk '{print $1}' file.txtawk -F: '{print $1,$3}' /etc/passwdawk 'NR>1 {sum+=$2} END {print sum}' data.txt
sort
📝
文本处理
文本排序
sort [选项] 文件
sort file.txtsort -n numbers.txtsort -t: -k3 -n /etc/passwd
uniq
📝
文本处理
去除重复行
uniq [选项] 文件
sort file.txt | uniquniq -c file.txtsort file.txt | uniq -d
wc
📝
文本处理
字数统计
wc [选项] 文件
wc file.txtwc -l file.txtcat file.txt | wc -w
uname
🖥️
系统管理
显示系统信息
uname [选项]
uname -auname -runame -m
uptime
🖥️
系统管理
系统运行时间
uptime [选项]
uptimeuptime -puptime -s
date
🖥️
系统管理
显示或设置日期
date [选项] [+格式]
datedate '+%Y-%m-%d %H:%M:%S'date -d 'yesterday'
hostname
🖥️
系统管理
显示或设置主机名
hostname [选项] [名称]
hostnamehostname -Ihostname -f
shutdown
🖥️
系统管理
关机或重启
shutdown [选项] 时间 [消息]
shutdown -h nowshutdown -r +5shutdown -c
reboot
🖥️
系统管理
重启系统
reboot [选项]
rebootreboot -f
ping
🌐
网络工具
测试网络连接
ping [选项] 主机
ping google.comping -c 5 192.168.1.1ping -i 0.5 localhost
curl
🌐
网络工具
HTTP请求工具
curl [选项] URL
curl https://api.example.comcurl -X POST -d '{"key":"value"}' urlcurl -O https://example.com/file.zip
wget
🌐
网络工具
下载文件
wget [选项] URL
wget https://example.com/file.zipwget -c https://example.com/large.isowget -r -l2 https://example.com/
netstat
🌐
网络工具
网络状态统计
netstat [选项]
netstat -tulnnetstat -anpnetstat -r
ss
🌐
网络工具
套接字统计
ss [选项]
ss -tulnss -sss -tp
ifconfig
🌐
网络工具
配置网络接口
ifconfig [接口] [选项]
ifconfigifconfig eth0ifconfig eth0 192.168.1.100
ip
🌐
网络工具
IP配置工具
ip [选项] 对象 命令
ip addr showip route showip link set eth0 up
ps
⚙️
进程管理
显示进程状态
ps [选项]
ps auxps -efps aux --sort=-%mem
top
⚙️
进程管理
实时进程监控
top [选项]
toptop -d 1top -u root
htop
⚙️
进程管理
交互式进程查看器
htop [选项]
htophtop -u roothtop -t
kill
⚙️
进程管理
终止进程
kill [选项] 进程ID
kill 1234kill -9 1234kill -l
killall
⚙️
进程管理
按名称终止进程
killall [选项] 进程名
killall firefoxkillall -9 nginxkillall -i java
nohup
⚙️
进程管理
后台运行命令
nohup 命令 [参数] &
nohup ./script.sh &nohup python app.py > output.log 2>&1 &
useradd
👤
用户管理
添加用户
useradd [选项] 用户名
useradd newuseruseradd -m -s /bin/bash johnuseradd -G sudo,docker admin
userdel
👤
用户管理
删除用户
userdel [选项] 用户名
userdel olduseruserdel -r olduser
passwd
👤
用户管理
修改密码
passwd [选项] [用户名]
passwdpasswd johnpasswd -l username
su
👤
用户管理
切换用户
su [选项] [用户名]
su rootsu - adminsu -c 'ls /root' root
sudo
👤
用户管理
以管理员执行
sudo [选项] 命令
sudo apt updatesudo -isudo -u www-data ls
who
👤
用户管理
显示登录用户
who [选项]
whowho -awho -H
whoami
👤
用户管理
显示当前用户
whoami
whoami
chmod
🔐
权限管理
修改文件权限
chmod [选项] 模式 文件
chmod 755 script.shchmod -R 644 /var/www/chmod u+x file.sh
chown
🔐
权限管理
修改文件所有者
chown [选项] 用户[:组] 文件
chown root file.txtchown -R user:group /var/www/chown www-data:www-data index.html
chgrp
🔐
权限管理
修改文件所属组
chgrp [选项] 组 文件
chgrp admin file.txtchgrp -R www-data /var/www/
df
💾
磁盘管理
磁盘空间使用
df [选项] [文件系统]
df -hdf -Thdf -hi
du
💾
磁盘管理
目录空间使用
du [选项] [文件/目录]
du -sh /home/du -h --max-depth=1du -ah | sort -rh | head -20
fdisk
💾
磁盘管理
磁盘分区工具
fdisk [选项] 设备
fdisk -lfdisk /dev/sda
mount
💾
磁盘管理
挂载文件系统
mount [选项] 设备 挂载点
mount /dev/sdb1 /mnt/usbmount -t ntfs /dev/sdc1 /mnt/winmount -o loop disk.iso /mnt/iso
umount
💾
磁盘管理
卸载文件系统
umount [选项] 设备/挂载点
umount /mnt/usbumount -l /dev/sdb1
tar
🗜️
压缩解压
归档工具
tar [选项] 归档文件 [文件...]
tar -cvf archive.tar files/tar -xvf archive.tartar -czvf archive.tar.gz files/
gzip
🗜️
压缩解压
gzip压缩
gzip [选项] 文件
gzip file.txtgzip -d file.txt.gzgzip -kv file.txt
gunzip
🗜️
压缩解压
gzip解压
gunzip [选项] 文件.gz
gunzip file.txt.gzgunzip -k file.txt.gz
zip
🗜️
压缩解压
zip压缩
zip [选项] 压缩包.zip 文件...
zip archive.zip files/*zip -r archive.zip directory/zip -e secure.zip secret.txt
unzip
🗜️
压缩解压
zip解压
unzip [选项] 压缩包.zip
unzip archive.zipunzip -d /dest/ archive.zipunzip -l archive.zip
find
🔍
搜索查找
查找文件
find [路径] [表达式]
find / -name '*.log'find . -type f -size +100Mfind /home -mtime -7
locate
🔍
搜索查找
快速定位文件
locate [选项] 模式
locate nginx.conflocate -i readmelocate -c '*.log'
which
🔍
搜索查找
查找命令路径
which [选项] 命令
which pythonwhich -a java
whereis
🔍
搜索查找
查找程序位置
whereis [选项] 命令
whereis nginxwhereis -b python