You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mall-admin/mall_hou/document/reference/linux.md

149 lines
3.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Linux常用命令
## 系统服务管理
### systemctl
- 启动服务systemctl start httpd.service
- 关闭服务systemctl stop httpd.service
- 重启服务不管是否在运行systemctl restart httpd.service
- 重新载入配置不中断服务systemctl reload httpd.service
- 查看运行状态systemctl status httpd.service
- 设置开机启动systemctl enable httpd.service
- 禁止开机启动systemctl disable httpd.service
- 查看系统安装的服务systemctl list-units --type=service
## 文件管理
### ls
列出/home目录下的子目录ls -l /home
列出当前文件夹下所有文件夹及文件大小ls -lht
### pwd
显示当前工作目录
### cd
切换目录: cd /usr/local
### date
以指定格式显示日期date '+date:%x time:%X'
### passwd
修改root密码passwd root
### su
普通用户切换到超级用户su -
### clear
清除屏幕信息
### man
查看ls命令的帮助信息man ls
### who
- 查看当前运行级别who -r
- 显示用的登录详情who -buT
### free
以MB显示内存使用状态free -m
### ps
查看系统所有进程ps -ef
查看运行的java进程 ps -ef | grep java
### top
查看系统当前活跃进程信息
### mkdir
创建目录
### more
分页查看
每10行显示一屏查看more -c -10
### cat
查看config文件cat -Ab config
### rm
- 删除文件rm a.txt
- 删除文件夹: rm -rf a/
### touch
创建一个文件touch a.txt
### cp
将目录a的文件拷贝到目录b: cp -r /home/a /home/b
### mv
移动或覆盖文件mv a.txt b.txt
## 压缩与解压
### tar
- 打包文件夹到单独的文件tar -cvf /opt/etc.tar /etc
- 压缩文件夹到压缩文件gziptar -zcvf /opt/etc.tar.gz /etc
- 压缩文件夹到压缩文件bzip2tar -jcvf /opt/etc.tar.bz2 /etc
- 查阅压缩包中内容gziptar -ztvf /opt/etc.tar.gz /etc
- 解压文件到当前目录gziptar -zxvf /opt/etc.tar.gz
## 磁盘和网络管理
### df
查看磁盘占用情况df -hT
### ifconfig
查看当前网络接口状态
### netstat
- 查看路由信息netstat -rn
- 查看所有有效TCP连接netstat -an
- 查看系统中启动的监听服务netstat -tulnp
- 查看处于连接状态的系统资源信息netstat -atunp
### wget
从网络上下载软件
## 软件的安装与管理
### rpm
- 安装软件包rpm -ivh nginx-1.12.2-2.el7.x86_64.rpm
- 模糊搜索软件包rpm -qa | grep nginx
- 精确查找软件包rpm -qa nginx
- 查询软件包的安装路径rpm -ql nginx-1.12.2-2.el7.x86_64
- 查看软件包的概要信息rpm -qi nginx-1.12.2-2.el7.x86_64
- 验证软件包内容和安装文件是否一致rpm -V nginx-1.12.2-2.el7.x86_64
- 更新软件包rpm -Uvh nginx-1.12.2-2.el7.x86_64
- 删除软件包rpm -e nginx-1.12.2-2.el7.x86_64
### yum
- 安装软件包: yum install nginx
- 检查可以更新的软件包yum check-update
- 更新指定的软件包yum update nginx
- 在资源库中查找软件包信息yum info nginx*
- 列出已经安装的所有软件包yum info installed
- 列出软件包名称yum list redis*
- 模糊搜索软件包yum search redis
## 网络安全
### iptables
- 开启防火墙systemctl start iptables.service
- 关闭防火墙systemctl stop iptables.service
- 查看防火墙状态systemctl status iptables.service
- 设置开机启动systemctl enable iptables.service
- 禁用开机启动systemctl disable iptables.service
- 查看filter表的链信息iptables -L -n
- 查看NAT表的链信息iptables -t nat -L -n
- 清除防火墙所有规则iptables -F;iptables -X;iptables -Z;
- 添加过滤规则开发80端口iptables -I INPUT -p tcp --dport 80 -j ACCEPT
- 查找规则所做行号iptables -L INPUT --line-numbers -n
- 根据行号删除过滤规则iptables -D INPUT 1