LINUX常用命令记录

1、判断端口是否开放

查到结果存在监听,则说明端口号已经开放

[root@zxone ~]# netstat -an | grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN 

2、判断防火墙是否开启运行

[root@zxone ~]# service  iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.
[root@zxone ~]# firewall-cmd --list-all  #查看防火墙开启端口列表

 3、查找进程并杀死进程

[root@zxone target]# ps aux|grep demo
root     28538  0.0  0.0 112808   964 pts/0    R+   10:28   0:00 grep --color=auto demo
[root@zxone target]# kill -28538
-bash: kill: 28538: invalid signal specification

4、删除文件夹(包含非空文件夹)

可以直接使用RM,但需要添加两个参数-RF,即RM-RF目录名

-R 是向下递归。不管有多少级别的目录,请同时删除它们

-F 是直接删除,不带任何提示

[root@zxone ruoyi_project]# ll
total 12
drwxr-xr-x 3 root    root    4096 Aug 14 00:51 home
-rw-r--r-- 1 jenkins jenkins  301 Aug 10 20:32 start.sh
-rw-r--r-- 1 jenkins jenkins  198 Aug 10 20:32 stop.sh
[root@zxone ruoyi_project]# ll
total 12
drwxr-xr-x 3 root    root    4096 Aug 14 00:51 home
-rw-r--r-- 1 jenkins jenkins  301 Aug 10 20:32 start.sh
-rw-r--r-- 1 jenkins jenkins  198 Aug 10 20:32 stop.sh
[root@zxone ruoyi_project]# rm -rf home/          #删除home文件夹,home文件夹是非空的
[root@zxone ruoyi_project]# ll
total 8
-rw-r--r-- 1 jenkins jenkins 301 Aug 10 20:32 start.sh
-rw-r--r-- 1 jenkins jenkins 198 Aug 10 20:32 stop.sh

5、解压压缩文件

解压文件:elasticsearch-7.7.0-no-jdk-linux-x86_64.tar.gz

解压完成会多了一个文件夹:elasticsearch-7.7.0

tar -xvf /tmp/etc.tar            //打开tar打包文件

tar -zxvf /tmp/etc.tar.gz               //解压以gzip压缩的文件

tar -jxvf /tmp/etc.tar.bz2              //解压以bzip2压缩的文件

tar -Zxvf /tmp/etc.tar.Z                //解压以compress压缩的文件

[root@zxone elk]# tar -zxvf elasticsearch-7.7.0-no-jdk-linux-x86_64.tar.gz 

 

6、查看CPU和内存占用情况

1.CPU占用最多的前10个进程: 

ps auxw|head -1;ps auxw|sort -rn -k3|head -10 


2.内存消耗最多的前10个进程 

ps auxw|head -1;ps auxw|sort -rn -k4|head -10 


3.虚拟内存使用最多的前10个进程 

ps auxw|head -1;ps auxw|sort -rn -k5|head -10

ps auxw

u:以用户为主的格式来显示程序状况

x:显示所有程序,不以终端机来区分 

w:采用宽阔的格式来显示程序状况

ps auxw|head -1

输出表头

sort -rn -k5

-n是按照数字大小排序,-r是以相反顺序,-k是指定需要排序的栏位

 7、查询linux内核

[root@zxone ~]# uname -r
3.10.0-1127.18.2.el7.x86_64

[root@zxone ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

原文地址:https://www.cnblogs.com/zxone/p/13500722.html