linux下常用命令

linux下的命令用了又忘,没有整理过,在此记录一下,用的未记录的命令会更新哦。

  1. 查看该路径下所有文件:ls
  2. 查看该路径下所有文件详情:ll
  3. 查找关键字进程:
  4.          ps -ef | grep java
  5.          ps -ef | grep nginx
  6.          ps -ef | grep tomcat
  7. 查找文件:find / -name 文件名
  8. 查看端口是否被占用:netstat -anp | grep :3306  
  9. 在日志文件中查找关键字内容:cat access.log | grep 关键字  
  10. 查看日志前10条:tail -f 10 ***.log
  11. 查看更多日志:more ***.log
  12. 解压:tar -zxvf ***.tar
  13. 查看当前路径:pwd
  14. 移动文件:mv 原目录文件 目标目录文件
  15. 复制文件:cp
  16. 查看文件内容:cat ***.txt
  17. 杀掉进程:kill -9 进程号
  18. 查看安装路径:whereis memcached whereis nginx
  19. 查看端口占用情况:netstat -a

systemctl就是service和chkconfig这两个命令的整合,在centos7就开始被使用了,systemctl是系统服务管理器命令。

  1. 检查服务状态:service httpd status  systemctl status httpd.service
  2. 显示所有已启动的服务:chkconfig --list    systemctl list-units --type=service
  3. 启动某服务:service httpd start    systemctl start httpd.service
  4. 停止某服务:service httpd stop    systemctl stop httpd.service
  5. 重启某服务:service httpd restart    systemctl restart httpd.service
  6. 检查服务状态:systemctl status httpd
  7. 启动某服务:systemctl start httpd
  8. 停止某服务:systemctl stop httpd
  9. 重启某服务:systemctl restart httpd

从centos7开始,官方的标准防火墙设置从iptables变更为firewalld

  1. 启动:systemctl start firewalld
  2. 关闭:systemctl stop firewalld  service iptables stop
  3. 查看状态:systemctl status firewalld
  4. 开机自启动防火墙:systemctl enable firewalld
  5. 禁止开机启动防火墙:systemctl disable firewalld
  6. 查看已打开的端口:firewall-cmd --list-ports
  7. 打开端口:firewall-cmd --permanent --zone=public --add-port=8080/tcp
  8. 其中permanent标识永久生效,public表示作用域,8080/tcp表示端口和类型
  9. 关闭端口:firewall-cmd --permanent --zone=public --remove-port=8080/tcp

     

nginx命令

  1. 启动:nginx
  2. 重启:nginx -s reload

vi编辑模式下查找关键字

  1. 进入vi编辑模式:vi nginx.conf
  2. 命令模式下输入/,底部出现:/
  3. 输入关键字,回车:listen
  4. 继续往下查找,输入n:n

查看linux信息

  1. 查看系统版本:cat /etc/redhat-release
  2. 查看CPU 型号/主频:cat /proc/cpuinfo | grep 'model name' |uniq
  3. 查看硬盘 厂商/容量:fdisk -l | grep Disk
  4. 查看内存 型号/容量:dmidecode -t memory
  5. 查看机器型号:dmidecode | grep "Product Name"
  6. 查看磁盘容量:df -h

nohup命令

  1. nohup ./test.sh > test.log 2>&1 &
  2. 其中:标准输出与标准错误输出重定向中,2>&1 标识标准错误输出重定向等同于标准输出重定向,即标准错误输出也重定向到文件test.log;& 命令是命令放在后台执行,需要放在命令的最后面。
  3. 如:nohup java -jar XXX.jar > xxx.log 2>&1 &

常规命令

  1. 加可执行权限:chmod u+x run.sh
  2. 查看所有硬盘:fdisk -l 
  3. 挂载U盘:mount /dev/sdb1  /mnt
  4. 执行脚本:sh run.sh 或./run.sh
  5. 改系统日期 3月/22日/21年:date -s 03/22/21
  6. 改系统时间 时/分/秒:date -s 10:26:30
  7. 查看系统时间:date
  8. 查看硬件时间:hwclock --show
  9. 同步系统时间和硬件时间:hwclock --systohc
  10. 查看目录占用硬盘大小:du -h --max-depth=0
  11. 查看CPU个数:lscpu或top

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值