linux下的命令用了又忘,没有整理过,在此记录一下,用的未记录的命令会更新哦。
- 查看该路径下所有文件:ls
- 查看该路径下所有文件详情:ll
- 查找关键字进程:
- ps -ef | grep java
- ps -ef | grep nginx
- ps -ef | grep tomcat
- 查找文件:find / -name 文件名
- 查看端口是否被占用:netstat -anp | grep :3306
- 在日志文件中查找关键字内容:cat access.log | grep 关键字
- 查看日志前10条:tail -f 10 ***.log
- 查看更多日志:more ***.log
- 解压:tar -zxvf ***.tar
- 查看当前路径:pwd
- 移动文件:mv 原目录文件 目标目录文件
- 复制文件:cp
- 查看文件内容:cat ***.txt
- 杀掉进程:kill -9 进程号
- 查看安装路径:whereis memcached whereis nginx
- 查看端口占用情况:netstat -a
systemctl就是service和chkconfig这两个命令的整合,在centos7就开始被使用了,systemctl是系统服务管理器命令。
- 检查服务状态:service httpd status systemctl status httpd.service
- 显示所有已启动的服务:chkconfig --list systemctl list-units --type=service
- 启动某服务:service httpd start systemctl start httpd.service
- 停止某服务:service httpd stop systemctl stop httpd.service
- 重启某服务:service httpd restart systemctl restart httpd.service
- 检查服务状态:systemctl status httpd
- 启动某服务:systemctl start httpd
- 停止某服务:systemctl stop httpd
- 重启某服务:systemctl restart httpd
从centos7开始,官方的标准防火墙设置从iptables变更为firewalld
- 启动:systemctl start firewalld
- 关闭:systemctl stop firewalld service iptables stop
- 查看状态:systemctl status firewalld
- 开机自启动防火墙:systemctl enable firewalld
- 禁止开机启动防火墙:systemctl disable firewalld
- 查看已打开的端口:firewall-cmd --list-ports
- 打开端口:firewall-cmd --permanent --zone=public --add-port=8080/tcp
- 其中permanent标识永久生效,public表示作用域,8080/tcp表示端口和类型
- 关闭端口:firewall-cmd --permanent --zone=public --remove-port=8080/tcp

nginx命令
- 启动:nginx
- 重启:nginx -s reload
vi编辑模式下查找关键字
- 进入vi编辑模式:vi nginx.conf
- 命令模式下输入/,底部出现:/
- 输入关键字,回车:listen
- 继续往下查找,输入n:n
查看linux信息
- 查看系统版本:cat /etc/redhat-release
- 查看CPU 型号/主频:cat /proc/cpuinfo | grep 'model name' |uniq
- 查看硬盘 厂商/容量:fdisk -l | grep Disk
- 查看内存 型号/容量:dmidecode -t memory
- 查看机器型号:dmidecode | grep "Product Name"
- 查看磁盘容量:df -h
nohup命令
- nohup ./test.sh > test.log 2>&1 &
- 其中:标准输出与标准错误输出重定向中,2>&1 标识标准错误输出重定向等同于标准输出重定向,即标准错误输出也重定向到文件test.log;& 命令是命令放在后台执行,需要放在命令的最后面。
- 如:nohup java -jar XXX.jar > xxx.log 2>&1 &
常规命令
- 加可执行权限:chmod u+x run.sh
- 查看所有硬盘:fdisk -l
- 挂载U盘:mount /dev/sdb1 /mnt
- 执行脚本:sh run.sh 或./run.sh
- 改系统日期 3月/22日/21年:date -s 03/22/21
- 改系统时间 时/分/秒:date -s 10:26:30
- 查看系统时间:date
- 查看硬件时间:hwclock --show
- 同步系统时间和硬件时间:hwclock --systohc
- 查看目录占用硬盘大小:du -h --max-depth=0
- 查看CPU个数:lscpu或top


本文记录了Linux下的常用命令,包括文件查看、进程查找、端口占用检查等,还介绍了systemctl服务管理命令、防火墙设置、nginx命令、vi编辑查找、系统信息查看、nohup命令及常规命令等,方便后续查阅和更新。
7万+

被折叠的 条评论
为什么被折叠?



