常用linux命令

来源:互联网 发布:win10允许网络连接 编辑:程序博客网 时间:2024/06/06 01:05

1,查看磁盘

      df -h

2,查看内存大小

      free 

      free [-m|g]按MB,GB显示内存

       vmstat

3,查看cpu

     cat /proc/cpuinfo

    只看cpu数量 grep "model name" /proc/cpuinfo | wc -l

4,查看系统内存

    cat /proc/meminfo 

5,查看每个进程的情况

  cat /proc/5346/status   5347是pid

6,查看负载

   w

   uptime

7,查看系统整体状态

   top

   最后一些输出信息的解释:

   load average: 0.090.050.01  

   三个数分别代表不同时间段的系统平均负载(一分钟、五 分钟、以及十五分钟),它们的数字当然是越小越好。“有多少核心即为有多少负荷”法则: 在多核处理中,你的系统均值不应该高于处理器核心的总数量

    进程使用的内存可以用top,有3个列 VIRT RES SHR, 标示了进程使用的内存情况, VIRT标识这个进程可以使用的内存总大小, 包括这个进程真实使用的内存, 映射过的文件, 和别的进程共享的内存等. RES标识这个这个进程真实占用内存的大小. SHR标识可以和别的进程共享的内存和库大小.

8,性能监视sar命令

     sar -u输出显示CPU信息。-u选项是sar的默认选项。该输出以百分比显示CPU的使用情况


CPU

CPU编号

%user

在用户模式中运行进程所花的时间

%nice

运行正常进程所花的时间

%system

在内核模式(系统)中运行进程所花的时间

%iowait

没有进程在该CPU上执行时,处理器等待I/O完成的时间

%idle

没有进程在该CPU上执行的时间


    sar 5 10      sar以5秒钟间隔取得10个样本

    sar -u -p ALL 5 5  分cup显示

    sar -n { DEV | EDEV | NFS | NFSD | SOCK | ALL }

    sar 提供六种不同的语法选项来显示网络信息。-n选项使用6个不同的开关:DEV | EDEV | NFS | NFSD | SOCK | ALL 。DEV显示网络接口信息,EDEV显示关于网络错误的统计数据,NFS统计活动的NFS客户端的信息,NFSD统计NFS服务器的信息,SOCK显示套接字信息,ALL显示所有5个开关。它们可以单独或者一起使用。

    sar -n DEV 各参数含义

IFACE

LAN接口

rxpck/s

每秒钟接收的数据包

txpck/s

每秒钟发送的数据包

rxbyt/s

每秒钟接收的字节数

txbyt/s

每秒钟发送的字节数

rxcmp/s

每秒钟接收的压缩数据包

txcmp/s

每秒钟发送的压缩数据包

rxmcst/s

每秒钟接收的多播数据包

9,查看命令历史(含时间戳)

export HISTTIMEFORMAT='%F %T ';history| more

10,查看文件夹和文件大小

     du -h --max-depth=0  dm 查看dm目录大小

     du -h --max-depth=1 dm 查看dm目录大小,以及dm各文件文件夹的大小

      du -h --max-depth=0  查看当前文件夹大小  

11,查找当前文件夹下所有.mp3文件,并强制删除: find ./ -name "*.mp3" | xargs rm -rf

12,后台运行程序(启动进程)

nohup /usr/local/bin/python /var/log/httpd/PythonCode/3G/3g.py >> nohup-3g.out &

13,ps命令常用参数


[plain] view plaincopyprint?
  1. ps -def  

-d Select all processes except session leaders.

[plain] view plaincopyprint?
  1. Every process group is in a unique session. (When the process is created, it becomes a member of the session of its parent.) By convention, the session ID of a session equals the process ID of the first member of the session, called the session leader. A process finds the ID of its session using the system call getsid().  
  2.   
  3. Every session may have a controlling tty, that then also is called the controlling tty of each of its member processes. A file descriptor for the controlling tty is obtained by opening /dev/tty. (And when that fails, there was no controlling tty.) Given a file descriptor for the controlling tty, one may obtain the SID using tcgetsid(fd).  
  4.   
  5. A session is often set up by a login process. The terminal on which one is logged in then becomes the controlling tty of the session. All processes that are descendants of the login process will in general be members of the session.  

进程是按照进程组管理的,进程组又属于session。关系如下:

每个session拥有一个或者多个进程组,每个进程组拥有一个或多个进程。第一个属于某个session的进程id就是这个session的 leader, session id就用它的进程id。

和进程相关的id有几种,

进程id, 父进程id, 进程组id 和 session id.

参考:http://unix.stackexchange.com/questions/18166/what-are-session-leaders-in-ps


-e 参数等同于 -A,

[plain] view plaincopyprint?
  1. -e     Select all processes.  Identical to -A.  


-f 参数 显示完整格式
[plain] view plaincopyprint?
  1. -f     Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns.  It also causes the command arguments to be  
  2.               printed.  When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added.  See the c option, the format keyword args, and the  
  3.               format keyword comm.  

不过还有个常用的方式:

ps axu

不同于ps -def 用标准风格,这是BSD风格(不用-作为引导参数), BSD风格会在另一篇博客中介绍。

-a 参数

[plain] view plaincopyprint?
  1. -a     Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.  
-x 参数 和tty有关,tty会在另一篇文章中解释

[plain] view plaincopyprint?
  1. x      Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when  
  2.               the ps personality setting is BSD-like.  The set of processes selected in this manner is in addition to the set of processes selected by other means.  An  
  3.               alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the  
  4.               a option.  
-u 参数

[plain] view plaincopyprint?
  1. -u userlist  
  2.               Select by effective user ID (EUID) or name.  This selects the processes whose effective user name or ID is in userlist.  
  3.   
  4.               The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)).  Identical to U and --user.  



还有一种,通过直接输入命令查找,用-C参数,比如

[plain] view plaincopyprint?
  1. $ UNIX95= ps -C nginx  
  2.   PID TTY          TIME CMD  
  3.  1258 ?        00:00:00 nginx  
  4.  1259 ?        00:00:00 nginx  
  5. CHN\shu6889@sloop2:~$ ps aux | grep nginx  
  6. root      1258  0.0  0.0  31188  1028 ?        Ss   09:24   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf  
  7. root      1259  0.0  0.0  47312  2708 ?        S    09:24   0:00 nginx: worker process                     
  8. 70780027  4336  0.0  0.0  13652   976 pts/1    S+   10:40   0:00 grep --color=auto nginx  

要注意,前面需要输入UNIX95=




0 0
原创粉丝点击