• linux 功能性命令合集(持续更新)


    目录

    一、文件类

            ①:设置vim查看文件编码格式

            ②:文件乱码

            ③:后台运行py文件

            ④:查找文件

    二、端口服务类

            ①:查看进程

            ②、查看网络服务(端口服务)

            ③、杀掉进程

            ④、查看linux资源占用情况

    三、权限类

            ①:查看文件权限

            ②:修改文件权限

    四、查看服务器硬件情况

            ①:cpu情况

            ②:linux分区情况查看

            ③:linux内存情况


    一、文件类

            ①:设置vim查看文件编码格式

    1. # 查看文件编码
    2. file --mime-encoding filename
    3. # 设置vim打开编码选择
    4. echo 'set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936' >> /etc/vimrc

            ②:文件乱码

    1. # 查看乱码文件编码格式
    2. set fileencoding
    3. # 进入乱码文件输入
    4. set fileencoding = utf-8

            ③:后台运行py文件

    1. # linux后台运行py文件 一般用于服务启动之类的需要长期监测的脚本
    2. nohup python xxxxx.py -u nohup.out &

            ④:查找文件

    1. # whereis,find,which
    2. # whereis只能用于查找二进制文件、源代码文件和man手册页。
    3. # find 可以指定目前下或根目录查找
    4. # which 查找在系统变量中的命令位置
    5. (base) [root@finance01 usr]# find -name python
    6. ./bin/python
    7. ./share/gcc-4.8.2/python
    8. ./include/boost/parameter/aux_/python
    9. ./include/boost/mpi/python
    10. ./include/boost/python
    11. ./local/jmeter/jmeter/lib/jython-standalone-2.7.1/com/ziclix/python
    12. ./local/jmeter/jmeter/lib/jython-standalone-2.7.1/org/python
    13. (base) [root@finance01 usr]# whereis python
    14. python: /usr/bin/python2.7 /usr/bin/python /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /root/anaconda3/bin/python /root/anaconda3/bin/python3.8 /root/anaconda3/bin/python3.8-config /usr/share/man/man1/python.1.gz
    15. (base) [root@finance01 usr]# which python
    16. /root/anaconda3/bin/python

    二、端口服务类

            ①:查看进程

    1. # 查看特定进程更改关键字(Python)
    2. ps -ef | grep python

            ②、查看网络服务(端口服务)

    1. # 查看端口服务及tcp/pid等信息
    2. netstat -nltp

            ③、杀掉进程

    1. # 通常配合 netstat -nltp 使用
    2. # 指定名字
    3. kill - 9 $(pidof google-chrome)

            ④、查看linux资源占用情况

    1. # 查看linux资源使用使用情况
    2. top
    3. # 输出如下: (这里可以看到cpu的使用率,可以定位因超高cpu使用率导致程序无响应问题)
    4. top - 11:48:49 up 67 days, 18:14, 2 users, load average: 0.05, 0.04, 0.07
    5. Tasks: 691 total, 1 running, 690 sleeping, 0 stopped, 0 zombie
    6. %Cpu(s): 0.3 us, 0.0 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
    7. KiB Mem : 13162375+total, 30176480 free, 54814288 used, 46632984 buff/cache
    8. KiB Swap: 4194300 total, 3508208 free, 686092 used. 76014976 avail Mem
    9. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    10. 16452 mysql 20 0 13.856g 8.205g 8580 S 14.6 6.5 18849:26 mysqld
    11. 3851 root 20 0 50.795g 0.017t 2864 S 1.0 14.2 1903:48 java
    12. 1961 root 20 0 2929344 44620 9076 S 0.7 0.0 451:07.88 docker-containe
    13. 2010 root 20 0 1001336 263344 1308 S 0.7 0.2 43:19.63 redis-server
    14. 13920 root 20 0 35.411g 1.400g 14856 S 0.7 1.1 863:14.99 java
    15. 27714 root 20 0 148916 2732 1460 R 0.7 0.0 0:00.05 top
    16. 28581 root 20 0 45.287g 3.514g 15396 S 0.7 2.8 524:07.69 java
    17. 1582 root 20 0 3570552 54976 15652 S 0.3 0.0 213:47.16 dockerd
    18. 15438 root 20 0 30.154g 1.650g 14240 S 0.3 1.3 284:43.05 java
    19. 1 root 20 0 54432 7624 2520 S 0.0 0.0 8:25.35 systemd
    20. 2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
    21. 3 root 20 0 0 0 0 S 0.0 0.0 0:01.33 ksoftirqd/0
    22. 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
    23. 8 root rt 0 0 0 0 S 0.0 0.0 0:01.61 migration/0
    24. 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh

    三、权限类

            ①:查看文件权限

                    r 对应权限数字为 4,w对应权限数字为 2,x 对应权限数字为 1

    1. # ll 查看当前目录下所有文件及文件夹信息
    2. (base) [root@finance01 usr]# ll
    3. 总用量 2218496
    4. dr-xr-xr-x. 2 mongodb mongodb 20480 1011 12:43 bin
    5. drwxr-xr-x. 2 root root 10 812 2015 etc
    6. drwxr-xr-x. 2 root root 10 812 2015 games
    7. drwxr-xr-x. 48 root root 8192 520 12:57 include
    8. dr-xr-xr-x. 28 mongodb mongodb 4096 1011 12:43 lib
    9. dr-xr-xr-x. 45 mongodb mongodb 36864 1011 12:43 lib64
    10. drwxr-xr-x. 19 root root 4096 1011 12:43 libexec
    11. drwxr-xr-x. 23 root root 4096 1028 14:04 local
    12. drwxr-xr-x. 3 root root 63 42 2021 redis
    13. dr-xr-xr-x. 2 mongodb mongodb 12288 81 10:45 sbin
    14. drwxr-xr-x. 97 root root 4096 1011 12:43 share
    15. drwxr-xr-x. 4 root root 44 39 2021 src
    16. lrwxrwxrwx. 1 root root 10 39 2021 tmp -> ../var/tmp
    17. 文件调用权限分为三级 : 文件所有者(Owner)、用户组(Group)、其它用户(Other Users)。
    18. dr-xr-xr-x
    19. d : 文件夹的标志
    20. r-x : 5 对应文件所有者
    21. r-x :5 用户组
    22. r-x : 5 其它用户

            ②:修改文件权限

                    创建一个a.txt文件,查看权限,再赋新的权限对比。

    1. # chmod 用于赋予文件权限
    2. (base) [root@finance01 usr]# touch a.txt
    3. (base) [root@finance01 usr]# ll
    4. 总用量 2218496
    5. -rw-r--r-- 1 root root 0 113 17:31 a.txt
    6. dr-xr-xr-x. 2 mongodb mongodb 20480 1011 12:43 bin
    7. drwxr-xr-x. 2 root root 10 812 2015 etc
    8. drwxr-xr-x. 2 root root 10 812 2015 games
    9. drwxr-xr-x. 48 root root 8192 520 12:57 include
    10. dr-xr-xr-x. 28 mongodb mongodb 4096 1011 12:43 lib
    11. dr-xr-xr-x. 45 mongodb mongodb 36864 1011 12:43 lib64
    12. drwxr-xr-x. 19 root root 4096 1011 12:43 libexec
    13. drwxr-xr-x. 23 root root 4096 1028 14:04 local
    14. drwxr-xr-x. 3 root root 63 42 2021 redis
    15. dr-xr-xr-x. 2 mongodb mongodb 12288 81 10:45 sbin
    16. drwxr-xr-x. 97 root root 4096 1011 12:43 share
    17. drwxr-xr-x. 4 root root 44 39 2021 src
    18. lrwxrwxrwx. 1 root root 10 39 2021 tmp -> ../var/tmp
    19. (base) [root@finance01 usr]# chmod 777 a.txt
    20. (base) [root@finance01 usr]# ll
    21. 总用量 2218496
    22. -rwxrwxrwx 1 root root 0 113 17:31 a.txt
    23. dr-xr-xr-x. 2 mongodb mongodb 20480 1011 12:43 bin
    24. drwxr-xr-x. 2 root root 10 812 2015 etc
    25. drwxr-xr-x. 2 root root 10 812 2015 games
    26. drwxr-xr-x. 48 root root 8192 520 12:57 include
    27. dr-xr-xr-x. 28 mongodb mongodb 4096 1011 12:43 lib
    28. dr-xr-xr-x. 45 mongodb mongodb 36864 1011 12:43 lib64
    29. drwxr-xr-x. 19 root root 4096 1011 12:43 libexec
    30. drwxr-xr-x. 23 root root 4096 1028 14:04 local
    31. drwxr-xr-x. 3 root root 63 42 2021 redis
    32. dr-xr-xr-x. 2 mongodb mongodb 12288 81 10:45 sbin
    33. drwxr-xr-x. 97 root root 4096 1011 12:43 share
    34. drwxr-xr-x. 4 root root 44 39 2021 src
    35. lrwxrwxrwx. 1 root root 10 39 2021 tmp -> ../var/tmp

    四、查看服务器硬件情况

            ①:cpu情况

    1. # cpu情况查看
    2. lscpu
    3. # 输出如下: (可以看到cpu的核数、型号、及每个核的最大线程数等情况)
    4. (base) [root@finance01 ~]# lscpu
    5. Architecture: x86_64
    6. CPU op-mode(s): 32-bit, 64-bit
    7. Byte Order: Little Endian
    8. CPU(s): 64
    9. On-line CPU(s) list: 0-63
    10. Thread(s) per core: 2
    11. Core(s) per socket: 16
    12. 座: 2
    13. NUMA 节点: 2
    14. 厂商 ID: GenuineIntel
    15. CPU 系列: 6
    16. 型号: 79
    17. 型号名称: Intel(R) Xeon(R) CPU E5-2683 v4 @ 2.10GHz
    18. 步进: 1
    19. CPU MHz: 1199.953
    20. BogoMIPS: 4200.07
    21. 虚拟化: VT-x
    22. L1d 缓存: 32K
    23. L1i 缓存: 32K
    24. L2 缓存: 256K
    25. L3 缓存: 40960K
    26. NUMA 节点0 CPU: 0-15,32-47
    27. NUMA 节点1 CPU: 16-31,48-63

            ②:linux分区情况查看

    1. df -h
    2. # 输出如下: (不加-h默认输出的容量单位为byte)
    3. (base) [root@finance01 ~]# df -h
    4. 文件系统 容量 已用 可用 已用% 挂载点
    5. devtmpfs 63G 0 63G 0% /dev
    6. tmpfs 63G 0 63G 0% /dev/shm
    7. tmpfs 63G 74M 63G 1% /run
    8. tmpfs 63G 0 63G 0% /sys/fs/cgroup
    9. /dev/mapper/centos-root 11T 2.5T 8.6T 23% /
    10. /dev/sda2 497M 107M 391M 22% /boot
    11. tmpfs 13G 0 13G 0% /run/user/0

            ③:linux内存情况

    1. # 内存情况查看
    2. free -h
    3. # 输出 (不加-h也是以单位为字节来输出的)
    4. (base) [root@finance01 ~]# free -h
    5. total used free shared buff/cache available
    6. Mem: 125G 52G 28G 73M 44G 72G
    7. Swap: 4.0G 670M 3.3G

  • 相关阅读:
    【无标题】
    【TAPD】实践:TAPD 项目管理配置
    Java标识符指什么呢?
    几个神器来拯救自己奇丑无比的python代码
    解释一下用于WebRTC的SRTP的实时传输协议
    shin-monitor源码分析
    工业蒸汽量预测(速通三)
    2021.06 编程题 36【Python二级题目解析】
    第二部分:Module(也称为Package)
    【大数据入门核心技术-Hadoop】(四)Hadoop基础概念之YARN
  • 原文地址:https://blog.csdn.net/zkkkkkkkkkkkkk/article/details/127527897