Linux 常用命令合集
一、文件与目录操作
ls # 查看当前目录文件
ls -lh # 详细+人类可读大小
cd /path # 进入目录
pwd # 当前路径
mkdir test # 创建目录
mkdir -p a/b # 递归创建
rm file # 删除文件
rm -rf dir # 强制删除目录
cp a b # 复制
cp -r a b # 复制目录
mv a b # 移动/重命名
touch a.txt # 创建空文件
二、查看文件内容
cat a.txt # 查看全文
less a.txt # 分页查看(推荐)
head -n 20 a.txt # 前20行
tail -n 20 a.txt # 后20行
tail -f log.log # 实时看日志
三、搜索与查找
find / -name "*.log" # 按文件名查
grep "error" a.txt # 文本搜索
grep -R "error" /var/log # 递归搜索
which php # 命令路径
whereis nginx # 程序位置
四、文件权限
chmod 755 a.sh # 修改权限
chown root a.txt # 修改属主
ls -l # 查看权限
权限说明:
r=读 w=写 x=执行
755 = rwxr-xr-x
五、压缩与解压
tar -czf a.tar.gz dir # 打包压缩
tar -xzf a.tar.gz # 解压
zip -r a.zip dir
unzip a.zip
六、磁盘与空间
df -h # 磁盘使用情况
du -sh dir # 目录大小
lsblk # 查看磁盘
mount # 挂载信息
七、进程管理
ps aux # 查看进程
top / htop # 实时监控
kill 1234 # 杀进程
kill -9 1234 # 强制杀
pkill nginx # 按名杀
八、网络相关
ip a # 网卡信息
ping baidu.com # 测试网络
netstat -tunlp # 端口占用
ss -lntp # 查看端口
curl url # 请求接口
wget url # 下载文件
九、系统信息
uname -a # 系统信息
free -h # 内存
uptime # 运行时间
whoami # 当前用户
history # 历史命令
十、用户与权限管理
useradd test
passwd test
su test
sudo command
groups
十一、服务管理(systemd)
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl status nginx
systemctl enable nginx
十二、开发常用
git status
git pull
git push
npm install
composer install
php artisan serve
十三、超实用组合命令
ps aux | grep php
netstat -tunlp | grep 80
tail -f log.log | grep error