linux常用命令

1、查询:

find、locate、which、whereis

  

find:
  搜索当前目录:find .

  搜索某个目录下的所有子目录和文件:find /opt
  搜索某个目录下的某个文件:find /home -name "lisi.txt"
  不区分大小写:find /root -iname binaries 
  按照所有者索引: find /root -user root
  查找文件大小為25k:find . -size 25k


find [搜索范围] [搜索条件]
   搜索文件
   避免大范围搜索,会非常消耗系统资源
   find是在系统中搜索符合条件的文件名。如果需要匹配,使用通配符匹配,通配符是完全匹配
 

Linux中的通配符:

  *  匹配任意内容

  ?  匹配任意一个字符

  []  匹配任意一个中括号内的字符




whereis
  只能用于文件名的搜索:whereis elasticsearch

which
  查询绝对路径,环境变量PATH保存的路径:which elasticsearch

locate
  查询的是数据库,所以需要及时更新才能搜索出最新的数据:locate elasticsearch
  即时更新数据库:locate -u


 

2、关于防火墙的开启以及关闭

关闭防火墙:systemctl stop firewalld.service
开启防火墙:systemctl start firewalld.service
关闭开机自启动:systemctl disable firewalld.service
开启开机自启动:systemctl enable firewalld.service


查看开放端口:

  开放的端口位于/etc/sysconfig/iptables中

  查看时通过 more /etc/sysconfig/iptables 命令查看 

  或者通过 iptables -nL

 

 如果想开放端口(如:8889)


  (1)通过vi /etc/sysconfig/iptables 进入编辑增添一条-A INPUT -p tcp -m tcp --dport 8889 -j ACCEPT 即可

  (2)执行 /etc/init.d/iptables restart 命令将iptables服务重启

 (3)保存 /etc/rc.d/init.d/iptables save
 

 

3、有关服务

查询系统上运行了哪些服务:ps -ef
查询指定服务:ps -ef | grep mysql
查询服务状态:service mysql status
查询所有服务的状态:service -status -all(返回结果的意义:- 未运行 + 正在运行 ?未知状态)
重启该服务:sudo service mysql restart
开启该服务:sudo service mysql start
关闭该服务:sudo service mysql stop

 4、有关文件

将文件夹复制到指定文件夹下:cp -r /root/csm /root/tempDir
将文件夹下所有的内容复制到指定文件夹下:cp -r /root/csm/* /root/tempDir

移动相似:mv /root/csm /root/tempDir
     mv /root/csm/* /root/tempDir

 

5、

linux查看端口常用命令
netstat命令参数:

  -t : 指明显示TCP端口

  -u : 指明显示UDP端口

  -l : 仅显示监听套接字(所谓套接字就是使应用程序能够读写与收发通讯协议(protocol)与资料的程序)

  -p : 显示进程标识符和程序名称,每一个套接字/端口都属于一个程序。

  -n : 不进行DNS轮询,显示IP(可以加速操作)

即可显示当前服务器上所有端口及进程服务,于grep结合可查看某个具体端口及服务情况··

netstat -ntlp   //查看当前所有tcp端口·
netstat -ntulp |grep 80   //查看所有80端口使用情况·
netstat -an | grep 3306   //查看所有3306端口使用情况·

查看一台服务器上面哪些服务及端口 netstat -lanp
查看一个服务有几个端口。比如要查看mysqld ps
-ef |grep mysqld
查看某一端口的连接数量,比如3306端口 netstat
-pnt |grep :3306 |wc
查看某一端口的连接客户端IP 比如3306端口 netstat
-anp |grep 3306 netstat -an 查看网络端口 lsof -i :port,使用lsof -i :port就能看见所指定端口运行的程序,同时还有当前连接。

 

posted @ 2019-12-06 10:31  忧伤还是快乐EL  阅读(127)  评论(0编辑  收藏  举报