Linux操作系统高阶命令详解指南

图片[1]-Linux操作系统高阶命令详解指南-不念博客
Linux操作系统高阶命令

xargs

xargs可以将标准输入当做后一个请求的参数,比如下面的命令,将find的结果,逐一作为file命令的参数。

#  find /etc -name *.conf -type f -print | xargs file
/etc/sudo-ldap.conf:                                       UTF-8 Unicode text
/etc/security/pam_env.conf:                                ASCII text
/etc/security/namespace.conf:                              ASCII text
/etc/security/limits.conf:                                 ASCII text
/etc/security/group.conf:                                  ASCII text

我们可以将所有图片打包到压缩包里面,如下:

find /home/tony -name "*.jpg" -type f | xargs tar -cxvf 

nohup

这个命令运维经常使用,比如需要执行一个长任务,虽然可以通过 & 放到后台执行,但如果shell 退出后,程序就执行就结束了,为了让脚本能够一直执行,就需要通过nohup让程序忽略关闭的信号,从而保持一直执行的状态。

nohup mysqldump -uroot -pxxxx —all-databases > ./alldatabases.sql &

找出内存占用最高的进程

我们通常是可以通过top命令查看系统中,资源消耗最多的进程。其实,我们还可以通过ps命令。

# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10
   PID   PPID CMD                         %MEM %CPU
 78452      1 /usr/local/bin/python3 chec  2.2  0.3
 63056      1 ./titanagent -d              0.9  2.2
 34072      1 /usr/local/bin/python3 dele  0.3 31.8
 97619      1 /usr/local/bin/python3 chec  0.2  0.6
 12272  12246 -bash                        0.2  0.0
126007  12246 -bash                        0.2  0.0
110554 126007 -bash                        0.2  0.0
 61900  61897 -bash                        0.2  0.0
115858  56729 -bash                        0.2  0.0

查看网络状态

如果网络压力比较大情况下,我们需要查看一下当前的网络连接情况。

#  netstat -nat | awk '{print $6}' | sort | uniq -c | sort -rn
    506 TIME_WAIT
     38 ESTABLISHED
     16 LISTEN
      1 Foreign
      1 established)

可以看到处于不同状态 TCP 连接的情况。

查看某个端口最多的链接

# netstat -anlp | grep 80| grep tcp | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n10
    142 10.180.32.25
    140 10.180.32.26
     68 0.0.0.0
      8 10.180.32.27
      6 10.180.32.28
      3 10.153.253.38
      2 10.150.32.43
      2 10.150.32.250
      2 10.150.32.23
      2 10.153.253.54

查看哪个机器连接最多

如果不关心端口,查看哪台机器连接的最多。

ss -t | awk '(NR>1) {print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -rn | head -10
     16 127.0.0.1
      8 10.238.168.96
      1 10.229.36.59

查看那个进程消耗最多的文件句柄

当发现系统的文件数超了的时候,需要查看打开的文件句柄,这个文件句柄主要是打开的文件或者网络连接。

# find /proc -maxdepth 1 -type d -name '[0-9]*' -exec bash -c "ls {}/fd/ | wc -l | tr '\n' ' '" \; -printf "fds (PID = %P) \n" |  sort -rn | head -15
3365 fds (PID = 57412)
387 fds (PID = 3643365)
111 fds (PID = 56903)
54 fds (PID = 29351)
52 fds (PID = 57258)
48 fds (PID = 1)
27 fds (PID = 3947358)
27 fds (PID = 10768)
26 fds (PID = 56947)
24 fds (PID = 3643285)
© 版权声明
THE END
喜欢就支持一下吧
点赞83赞赏 分享
评论 抢沙发
头像
欢迎光临不念博客,留下您的想法和建议,祝您有愉快的一天~
提交
头像

昵称

取消
昵称代码图片

    暂无评论内容