当前位置 博文首页 > sjn0815的博客:Linux常用命令 & 实用命令万字总结(转载学

    sjn0815的博客:Linux常用命令 & 实用命令万字总结(转载学

    作者:[db:作者] 时间:2021-08-07 10:05

    原文链接
    最高使用频率的命令之一。
    命令格式: ls [OPTION]… [FILE]… 单纯的输入:

    [root@iz2ze76ybn73dvwmdij06zz /]# ls
    bin   dev  home  lib64       media  opt    proc  run   srv  tmp  var
    boot  etc  lib   lost+found  mnt    patch  root  sbin  sys  usr  www
    

    加 option -l 它展示了权限,属主,属组,大小,时间,文件名称

    [root@iz2ze76ybn73dvwmdij06zz /]# ls -l
    总用量 68
    lrwxrwxrwx    1 root root     7 826 22:36 bin -> usr/bin
    dr-xr-xr-x.   5 root root  4096 826 22:39 boot
    drwxr-xr-x   19 root root  2960 411 12:59 dev
    drwxr-xr-x.  81 root root  4096 95 17:09 etc
    drwxr-xr-x.   2 root root  4096 411 12:59 home
    lrwxrwxrwx    1 root root     7 826 22:36 lib -> usr/lib
    lrwxrwxrwx    1 root root     9 826 22:36 lib64 -> usr/lib64
    drwx------.   2 root root 16384 1015 2017 lost+found
    drwxr-xr-x.   2 root root  4096 411 12:59 media
    drwxr-xr-x.   2 root root  4096 411 12:59 mnt
    drwxr-xr-x.   3 root root  4096 826 22:40 opt
    drwxr-xr-x    2 root root  4096 826 23:00 patch
    dr-xr-xr-x  110 root root     0 411 12:59 proc
    dr-xr-x---.  12 root root  4096 911 20:59 root
    drwxr-xr-x   26 root root   760 97 21:50 run
    lrwxrwxrwx    1 root root     8 826 22:36 sbin -> usr/sbin
    drwxr-xr-x.   2 root root  4096 411 12:59 srv
    dr-xr-xr-x   13 root root     0 411 12:59 sys
    drwxrwxrwt.   9 root root  4096 915 03:19 tmp
    drwxr-xr-x.  13 root root  4096 826 22:36 usr
    drwxr-xr-x.  19 root root  4096 826 22:55 var
    drwxr-xr-x    6 root root  4096 826 22:39 www
    

    ls -a (all) linux ‘.’(点)开头的文件默认是隐藏的,-a可以查询所有的文件。

    [root@iz2ze76ybn73dvwmdij06zz /]# ls -a
    .             bin   etc   lib64       mnt    .pearrc  run   sys    usr
    ..            boot  home  lost+found  opt    proc     sbin  .test  var
    .autorelabel  dev   lib   media       patch  root     srv   tmp    www
    

    ls -F 以"/"结尾的方式展示文件夹。
    [root@iz2ze76ybn73dvwmdij06zz /]# ls -F
    bin@ dev/ home/ lib64@ media/ opt/ proc/ run/ srv/ tmp/ var/
    boot/ etc/ lib@ lost+found/ mnt/ patch/ root/ sbin@ sys/ usr/ www/
    复制代码
    ls -r 倒叙展示,默认的顺序是(a,b,c,d)正序这样展示
    [root@iz2ze76ybn73dvwmdij06zz /]# ls -r
    www usr sys sbin root patch mnt lost+found lib etc boot
    var tmp srv run proc opt media lib64 home dev bin
    复制代码
    ls -R ()递归展示子目录
    [root@iz2ze76ybn73dvwmdij06zz test]# ls -R
    .:
    data

    ./data:
    img

    ./data/img:
    car product user

    ./data/img/car:

    ./data/img/product:

    ./data/img/user:
    复制代码
    ls -lS 按照文件大小降序显示
    [root@iz2ze76ybn73dvwmdij06zz /]# ls -lS
    总用量 72
    drwx------. 2 root root 16384 10月 15 2017 lost+found
    dr-xr-xr-x. 5 root root 4096 8月 26 22:39 boot
    drwxr-xr-x. 81 root root 4096 9月 5 17:09 etc
    drwxr-xr-x. 2 root root 4096 4月 11 12:59 home
    drwxr-xr-x. 2 root root 4096 4月 11 12:59 media
    drwxr-xr-x. 2 root root 4096 4月 11 12:59 mnt
    drwxr-xr-x. 3 root root 4096 8月 26 22:40 opt
    drwxr-xr-x 2 root root 4096 8月 26 23:00 patch
    dr-xr-x—. 12 root root 4096 9月 15 22:03 root
    drwxr-xr-x. 2 root root 4096 4月 11 12:59 srv
    drwxr-xr-x 3 root root 4096 9月 15 22:10 test
    drwxrwxrwt. 9 root root 4096 9月 15 03:19 tmp
    drwxr-xr-x. 13 root root 4096 8月 26 22:36 usr
    drwxr-xr-x. 19 root root 4096 8月 26 22:55 var
    drwxr-xr-x 6 root root 4096 8月 26 22:39 www
    drwxr-xr-x 19 root root 2960 4月 11 12:59 dev
    drwxr-xr-x 26 root root 760 9月 7 21:50 run
    lrwxrwxrwx 1 root root 9 8月 26 22:36 lib64 -> usr/lib64
    lrwxrwxrwx 1 root root 8 8月 26 22:36 sbin -> usr/sbin
    lrwxrwxrwx 1 root root 7 8月 26 22:36 bin -> usr/bin
    lrwxrwxrwx 1 root root 7 8月 26 22:36 lib -> usr/lib
    dr-xr-xr-x 110 root root 0 4月 11 12:59 proc
    dr-xr-xr-x 13 root root 0 4月 11 12:59 sys
    复制代码
    ls -g 不输出所有者(属主)信息
    [root@iz2ze76ybn73dvwmdij06zz /]# ls -g
    总用量 72
    lrwxrwxrwx 1 root 7 8月 26 22:36 bin -> usr/bin
    dr-xr-xr-x. 5 root 4096 8月 26 22:39 boot
    -rw-r–r-- 1 root 0 9月 15 22:20 c
    drwxr-xr-x 19 root 2960 4月 11 12:59 dev
    drwxr-xr-x. 81 root 4096 9月 5 17:09 etc
    drwxr-xr-x. 2 root 4096 4月 11 12:59 home
    lrwxrwxrwx 1 root 7 8月 26 22:36 lib -> usr/lib
    lrwxrwxrwx 1 root 9 8月 26 22:36 lib64 -> usr/lib64
    drwx------. 2 root 16384 10月 15 2017 lost+found
    drwxr-xr-x. 2 root 4096 4月 11 12:59 media
    drwxr-xr-x. 2 root 4096 4月 11 12:59 mnt
    drwxr-xr-x. 3 root 4096 8月 26 22:40 opt
    drwxr-xr-x 2 root 4096 8月 26 23:00 patch
    dr-xr-xr-x 110 root 0 4月 11 12:59 proc
    dr-xr-x—. 12 root 4096 9月 15 22:18 root
    drwxr-xr-x 26 root 760 9月 7 21:50 run
    lrwxrwxrwx 1 root 8 8月 26 22:36 sbin -> usr/sbin
    drwxr-xr-x. 2 root 4096 4月 11 12:59 srv
    dr-xr-xr-x 13 root 0 4月 11 12:59 sys
    drwxr-xr-x 3 root 4096 9月 15 22:18 test
    drwxrwxrwt. 9 root 4096 9月 15 03:19 tmp
    drwxr-xr-x. 13 root 4096 8月 26 22:36 usr
    drwxr-xr-x. 19 root 4096 8月 26 22:55 var
    drwxr-xr-x 6 root 4096 8月 26 22:39 www
    复制代码
    ls -lG 隐藏所有组(属组)信息
    [root@iz2ze76ybn73dvwmdij06zz /]# ls -lG
    总用量 72
    lrwxrwxrwx 1 root 7 8月 26 22:36 bin -> usr/bin
    dr-xr-xr-x. 5 root 4096 8月 26 22:39 boot
    -rw-r–r-- 1 root 0 9月 15 22:20 c
    drwxr-xr-x 19 root 2960 4月 11 12:59 dev
    drwxr-xr-x. 81 root 4096 9月 5 17:09 etc
    drwxr-xr-x. 2 root 4096 4月 11 12:59 home
    lrwxrwxrwx 1 root 7 8月 26 22:36 lib -> usr/lib
    lrwxrwxrwx 1 root 9 8月 26 22:36 lib64 -> usr/lib64
    drwx------. 2 root 16384 10月 15 2017 lost+found
    drwxr-xr-x. 2 root 4096 4月 11 12:59 media
    drwxr-xr-x. 2 root 4096 4月 11 12:59 mnt
    drwxr-xr-x. 3 root 4096 8月 26 22:40 opt
    drwxr-xr-x 2 root 4096 8月 26 23:00 patch
    dr-xr-xr-x 110 root 0 4月 11 12:59 proc
    dr-xr-x—. 12 root 4096 9月 15 22:18 root
    drwxr-xr-x 26 root 760 9月 7 21:50 run
    lrwxrwxrwx 1 root 8 8月 26 22:36 sbin -> usr/sbin
    drwxr-xr-x. 2 root 4096 4月 11 12:59 srv
    dr-xr-xr-x 13 root 0 4月 11 12:59 sys
    drwxr-xr-x 3 root 4096 9月 15 22:18 test
    drwxrwxrwt. 9 root 4096 9月 15 03:19 tmp
    drwxr-xr-x. 13 root 4096 8月 26 22:36 usr
    drwxr-xr-x. 19 root 4096 8月 26 22:55 var
    drwxr-xr-x 6 root 4096 8月 26 22:39 www
    10.ls -li 显示文件的索引号
    [root@iz2ze76ybn73dvwmdij06zz /]# ls -li
    复制代码
    ls -li 显示文件的索引号
    [root@iz2ze76ybn73dvwmdij06zz /]# ls -li

    总用量 72
    7628 lrwxrwxrwx 1 root root 7 8月 26 22:36 bin -> usr/bin
    1179650 dr-xr-xr-x. 5 root root 4096 8月 26 22:39 boot
    4923 -rw-r–r-- 1 root root 0 9月 15 22:20 c
    1026 drwxr-xr-x 19 root root 2960 4月 11 12:59 dev
    917505 drwxr-xr-x. 81 root root 4096 9月 5 17:09 etc
    655362 drwxr-xr-x. 2 root root 4096 4月 11 12:59 home
    17 lrwxrwxrwx 1 root root 7 8月 26 22:36 lib -> usr/lib
    13 lrwxrwxrwx 1 root root 9 8月 26 22:36 lib64 -> usr/lib64
    11 drwx------. 2 root root 16384 10月 15 2017 lost+found
    786434 drwxr-xr-x. 2 root root 4096 4月 11 12:59 media
    131074 drwxr-xr-x. 2 root root 4096 4月 11 12:59 mnt
    393219 drwxr-xr-x. 3 root root 4096 8月 26 22:40 opt
    1966081 drwxr-xr-x 2 root root 4096 8月 26 23:00 patch
    1 dr-xr-xr-x 110 root root 0 4月 11 12:59 proc
    131073 dr-xr-x—. 12 root root 4096 9月 15 22:18 root
    218 drwxr-xr-x 26 root root 760 9月 7 21:50 run
    15 lrwxrwxrwx 1 root root 8 8月 26 22:36 sbin -> usr/sbin
    393220 drwxr-xr-x. 2 root root 4096 4月 11 12:59 srv
    1 dr-xr-xr-x 13 root root 0 4月 11 12:59 sys
    2097153 drwxr-xr-x 3 root root 4096 9月 15 22:18 test
    393217 drwxrwxrwt. 9 root root 4096 9月 15 03:19 tmp
    1048578 drwxr-xr-x. 13 root root 4096 8月 26 22:36 usr
    262145 drwxr-xr-x. 19 root root 4096 8月 26 22:55 var
    1441793 drwxr-xr-x 6 root root 4096 8月 26 22:39 www
    复制代码
    ls -lt 按照修改时间排序(倒序)依次创建文件 a b
    [root@iz2ze76ybn73dvwmdij06zz test]# ls -lt
    总用量 0
    -rw-r–r-- 1 root root 0 9月 15 22:18 b
    -rw-r–r-- 1 root root 0 9月 15 22:18 a
    复制代码
    ls -version
    [root@iz2ze76ybn73dvwmdij06zz test]# ls --version
    ls (GNU coreutils) 8.22
    Copyright ? 2013 Free Software Foundation, Inc.
    许可证:GPLv3+:GNU 通用公共许可证第3 版或更新版本http://gnu.org/licenses/gpl.html。
    本软件是自由软件:您可以自由修改和重新发布它。
    在法律范围内没有其他保证。

    由Richard M. Stallman 和David MacKenzie 编写。
    复制代码
    cat
    cat,又是一个相对高频率的命令。比较官方的说法是命令用于链接文件并打印到标准输出设备上。这个文本输出命令可以用来查看文件内容,创建内容等,下面我们介绍几个比较实用的用法。
    命令格式 : cat [选项]… [文件]…
    cat -n 查看并显示行号
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat -n a
    1 this is a txt
    2 hello every body
    3 hello world
    4 hahaha
    复制代码
    cat 创建一个空文件 b
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat >b <<EOF

    EOF
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# ls
    a b
    复制代码
    cat 清空文件内容
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat >a<<EOF
    EOF
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat a
    复制代码
    cat 写入内容(如果原来有内容将被覆盖)
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat >a<<EOF
    today is a good day
    because off work
    hahaha
    EOF
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat a
    today is a good day
    because off work
    hahaha
    复制代码
    cat 同时显示多个文件内容( b中写出happy)
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat a > b
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat b
    today is a good day
    because off work
    hahaha
    复制代码
    追加内容 可以看到用了连个>以后内容是追加的
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat a >> b
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat b
    today is a good day
    because off work
    hahaha
    today is a good day
    because off work
    hahaha
    复制代码
    cat --help (如想学习更多,可以自己动手尝试)
    [root@iz2ze76ybn73dvwmdij06zz linuxdemo]# cat --help
    用法:cat [选项]… [文件]…
    将[文件]或标准输入组合输出到标准输出。

    -A, --show-all 等于-vET
    -b, --number-nonblank 对非空输出行编号
    -e 等于-vE
    -E, --show-ends 在每行结束处显示"$"
    -n, --number 对输出的所有行编号
    -s, --squeeze-blank 不输出多行空行
    -t 与-vT 等价
    -T, --show-tabs 将跳格字符显示为^I
    -u (被忽略)
    -v, --show-nonprinting 使用^ 和M- 引用,除了LFD和 TAB 之外
    –help 显示此帮助信息并退出
    –version 显示版本信息并退出

    如果没有指定文件,或者文件为"-",则从标准输入读取。

    示例:
    cat f - g 先输出f 的内容,然后输出标准输入的内容,最后输出g 的内容。
    cat 将标准输入的内容复制到标准输出。

    GNU coreutils online help: http://www.gnu.org/software/coreutils/
    请向http://translationproject.org/team/zh_CN.html 报告cat 的翻译错误
    要获取完整文档,请运行:info coreutils ‘cat invocation’
    复制代码
    用户权限
    大家都知道linux是一个多任务,多用户的操作系统。多个用户可以在同一时间操作系统执行不同的任务,一个用户也可以多个人登陆操作。一般来说root的权限最大,我们经常使用的数据库一般会用一个mysql的用户,网页相关的我们可能用一个www的账号,大家都是知道删除跑路的故事,因此有一些操作权限是要交给一些专人管理的。为了系统的学习,我觉得有必要了解一下它的基本知识。
    linux角色分类
    超级用户:root (user id --UID) 0 最高的管理权限。
    普通用户:
    系统用户 UID:1-999(rhel7 centos7) 1-499(rhel6)

    本地用户 UID:1000+(rhel7 centos7)  500+(rhel6)
    

    复制代码
    UID:用户身份标示,唯一标示。
    linux组分类
    组:
    组分类:
    根据账号的功能分类:

           超级用户组: root GID:0
           普通用户组 : 
                               系统用户组: GID 1---999
                                本地用户组: GID 1000+
    

    复制代码
    linux用户和组的关系
    一个用户属于一个组,也可以属于多个组,多个用户可以在一个组,可以在多个组。
    linux用户和组的相关配置文件
    1./etc/passwd:用户 and 属性信息。
    2./etc/group: 组 and 属性信息。
    3./etc/shadow: 用户密码 and 属性信息。
    4./etc/gshadow:组密码 and 属性信息。
    5./etc/default/useradd: 设置添加用户规则文件。
    6./etc/login.defs:设置用户账号限制。
    linux用户信息文件
    用户管理中最重要的一个文件,这个文件是对所有用户开放的,每一行存一个用户的信息,每个属性之间用冒号分割。
    cat /etc/passwd
    root?0:0:root:/root:/bin/zsh
    bin?1:1:bin:/bin:/sbin/nologin
    daemon?2:2:daemon:/sbin:/sbin/nologin
    adm?3:4:adm:/var/adm:/sbin/nologin
    lp?4:7:lp:/var/spool/lpd:/sbin/nologin
    复制代码
    举例:
    root?0:0:root:/root:/bin/zsh
    1.登陆用户名:root
    2.用户密码占位符:x
    3.用户UID:0
    4.用户组GID:0
    5.对用户账户的描述:root
    6.用户家目录位置:/root
    7.用户默认的shell:/bin/zsh (默认是/bin/bash)
    linux密码信息文件
    该文件只有root用户有读权限,每一行存一个用户的记录,每个属性用冒号分割。
    cat /etc/shadow
    root: 6 6 6LxE7qiaZ$ZZXf/aCO1Zqs1oOS9WDutUk9rFOq4MOoSG9IeXq2f5sduGrgfYvzOWHZmJZFGC.0Of1DjCna0M.oQZTY8r00/.:17769:0:99999:7:::
    bin::17110:0:99999:7:::
    daemon:
    :17110:0:99999:7:::
    复制代码
    举例:
    bin:*:17110:0:99999:7:::
    1.登录用户名: bin
    2.加密的密码: * 号代表密码被锁定
    3.最近更改密码的日期: 17110代表到1970-1-1密码不可改的天数
    4.密码修改期限: 99999 代表永远不用改,如果是其他数字则表示从1970-1-1内的多少天必须修改密码。
    5.更改密码最大有效天数: 代表密码保持有效的最大天数。
    6.密码过期警告:密码到正式失效前有多少天(-1,永远不提示)
    7.密码过期后多少天禁用用户:可登陆,单不能操作。
    8.用户被禁用日期:多少天后账号过期,不能登陆。
    9.保留参数
    linux组信息文件
    用户组的组信息存放在这,一行存一个组记录,属性用冒号分割。
    ? ~ cat /etc/group
    root?0:
    bin?1:
    daemon?2:
    sys?3:
    adm?4:
    tty?5:
    disk?6:
    lp?7:
    mem?8:
    kmem?9:
    复制代码
    举例:
    root?0:
    1.组名:root
    2.组密码占位符: x
    3.组GID: 0
    安装包管理基础
    相信大部分人应该和我一样,最开始都是用 windows上手的,那在windows平台的安装包就再熟悉不过了,比如.exe,是不是太常见了,一般在windows安装过mysql的,相信.msi也是见过的。大多数的服务器都是linux的,因此我们来学习一下linux的安装包基础知识。不同发行版的系统用的工具也是不相同的。目前大多数的公司服务器是基于centos,因此后续会以centos为例比较多。
    基于redhat
    yum
    zypper
    rpm
    基于centos
    yum
    rpm
    rpm
    全称: Redhat Package Manager
    下载网址: http://rpmfind.net

    先来看下包的命名格式,以 rpm-5.4.10-10.i586.rpm 为例。
    rpm : 软件包名
    5 : 主版本号
    4 : 次版本号
    10 : 修订号
    i586 : cpu架构平台
    rpm : 包后缀
    yum
    解决软件包安装的依赖关系问题,自动下载软件包,基于c/s架构。
    repo文件是yum源的配置文件,改文件定义软件仓库的信息。
    为什么说它是c/s架构,原来rpm软件的头(header)里会记录改软件的依赖信息,因此可以对头内容进行分析,就可以知道其相关的依赖,并将这些信息记录下来。那么服务端是提供这些rpm的软件包,然后分析包的依赖关系,将记录存在服务器某目录上。客户端在安装软件时下载其记录依赖关系文件并分析,最后一次性下载。
    进程管理基础
    一般来说程序分为两类,一种是系统程序,一种是应用程序。一个运行了程序,就可以说是一个进程了,进程是占用内存空间的,而当你杀掉进城时,资源也会随之释放。
    进程的类型
    用户进程:用户自己的程序,用户可以控制他的开启和关闭。
    交互进程: 与用户进行交互操作的进程。
    批处理进程: 是一个进程集合,按顺序启动其他进程。
    守护进程: 一直运行的进程.crond。
    进程的属性
    进程ID : (pid) 唯一的数字标示,区分不同的进程。
    进程有父进程和子进程。
    启动进程的用户ID(uid)和用户的属组。
    进程的三种状态:

    运行 – R
    休眠 – S
    僵尸 – Z

    进程的优先级: 取值范围(-20,19) ,数值越小优先级越大,默认为0。
    进程链接的终端。
    进程占用资源情况。
    父子进程的关系
    父子进程的关系,父亲管理儿子。父进程终止时子进程一定终止,而子进程终止时父进程不一定终止。
    进程管理工具
    ps: 查看进程。
    top: 可以查看进程的动态信息。
    kill: 杀进程。
    pstree: 查看进程树。
    pgrep: 搜进程。
    lsof: 查看进程打开的文件。
    复制代码
    进程管理实践
    ps
    静态的显示当前进程的信息 。
    命令: ps
    语法: ps 参数
    常用参数:
    a 显示所有用户的进程
    r 显示运行中的进程
    l 长格式输出
    u 按用户名和启动时间的顺序来显示进程
    f 用树形格式来显示进程
    x 显示没有控制终端的进程
    复制代码
    操作:
    BSD格式来显示进程
    ? ~ ps aux
    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    root 1 0.0 0.0 43364 3596 ? Ss 11月03 0:01 /usr/lib/syst
    root 2 0.0 0.0 0 0 ? S 11月03 0:00 [kthreadd]
    root 3 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/0]
    root 5 0.0 0.0 0 0 ? S< 11月03 0:00 [kworker/0:0H
    root 7 0.0 0.0 0 0 ? S 11月03 0:00 [migration/0]
    root 8 0.0 0.0 0 0 ? S 11月03 0:00 [rcu_bh]
    root 9 0.0 0.0 0 0 ? S 11月03 0:05 [rcu_sched]
    root 10 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/0]
    root 11 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/1]
    root 12 0.0 0.0 0 0 ? S 11月03 0:00 [migration/1]
    root 13 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/1]
    root 15 0.0 0.0 0 0 ? S< 11月03 0:00 [kworker/1:0H
    复制代码
    标准格式显示进程unix风格
    ~ ps -ef
    UID PID PPID C STIME TTY TIME CMD
    root 1 0 0 11月03 ? 00:00:01 /usr/lib/systemd/systemd --syste
    root 2 0 0 11月03 ? 00:00:00 [kthreadd]
    root 3 2 0 11月03 ? 00:00:00 [ksoftirqd/0]
    root 5 2 0 11月03 ? 00:00:00 [kworker/0:0H]
    root 7 2 0 11月03 ? 00:00:00 [migration/0]
    root 8 2 0 11月03 ? 00:00:00 [rcu_bh]
    root 9 2 0 11月03 ? 00:00:05 [rcu_sched]
    root 10 2 0 11月03 ? 00:00:00 [watchdog/0]
    root 11 2 0 11月03 ? 00:00:00 [watchdog/1]
    root 12 2 0 11月03 ? 00:00:00 [migration/1]
    root 13 2 0 11月03 ? 00:00:00 [ksoftirqd/1]
    root 15 2 0 11月03 ? 00:00:00 [kworker/1:0H]
    root 17 2 0 11月03 ? 00:00:00 [kdevtmpfs]
    root 18 2 0 11月03 ? 00:00:00 [netns]
    root 19 2 0 11月03 ? 00:00:00 [khungtaskd]
    root 20 2 0 11月03 ? 00:00:00 [writeback]
    root 21 2 0 11月03 ? 00:00:00 [kintegrityd]
    复制代码
    属性详解:
    USER: 进程的属主
    PID: 进程的ID
    %CPU: 进程占cpu百分比
    %MEM: 进程占内存的百分比
    VSZ: 进程占用虚拟内存大小
    RSS: 固定内存使用数量
    STAT 进程状态
    R 正在运行可中在队列中可过行的;
    S 处于休眠状态;

    T 停止或被追踪;

    Z 僵尸进程;

    N 优先级较低的进程

    L 有些页被锁进内存;

    s 进程的领导者(在它之下有子进程)
    复制代码
    复制代码复制代码
    START 启动进程的时间;
    TIME 进程消耗CPU的时间;
    COMMAND 命令的名称和参数;
    按照指定属性排序:
    按照cpu从小到大排序。
    ? ~ ps aux --sort %cpu
    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    root 1 0.0 0.0 43364 3596 ? Ss 11月03 0:01 /usr/lib/syst
    root 2 0.0 0.0 0 0 ? S 11月03 0:00 [kthreadd]
    root 3 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/0]
    root 5 0.0 0.0 0 0 ? S< 11月03 0:00 [kworker/0:0H
    root 7 0.0 0.0 0 0 ? S 11月03 0:00 [migration/0]
    root 8 0.0 0.0 0 0 ? S 11月03 0:00 [rcu_bh]
    root 9 0.0 0.0 0 0 ? S 11月03 0:05 [rcu_sched]
    root 10 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/0]
    root 11 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/1]
    复制代码
    按照cpu从大到小排序。
    ? ~ ps aux --sort -%cpu
    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    root 21342 0.3 0.4 137184 17112 ? Ssl 03:24 1:16 /usr/local/aegi
    root 1 0.0 0.0 43364 3596 ? Ss 11月03 0:01 /usr/lib/syst
    root 2 0.0 0.0 0 0 ? S 11月03 0:00 [kthreadd]
    root 3 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/0]
    root 5 0.0 0.0 0 0 ? S< 11月03 0:00 [kworker/0:0H
    root 7 0.0 0.0 0 0 ? S 11月03 0:00 [migration/0]
    root 8 0.0 0.0 0 0 ? S 11月03 0:00 [rcu_bh]
    root 9 0.0 0.0 0 0 ? S 11月03 0:05 [rcu_sched]
    root 10 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/0]
    root 11 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/1]
    root 12 0.0 0.0 0 0 ? S 11月03 0:00 [migration/1]
    root 13 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/1]
    复制代码
    top
    与ps相反的是top命令可以查看进程的动态信息。
    命令: top
    语法: top 参数
    常用参数:
    操作:
    ? ~ top
    top - 11:38:42 up 13:15, 2 users, load average: 0.01, 0.03, 0.05