linux获取用户信息

linux/unix提供众多命令获取用户信息。

  1. who 显示当前主机登录用户
    [code]
    $ who
    root pts/0 Jul 31 11:46 (cma20n01)
    vfy_xp pts/1 Aug 7 00:02 (10.28.32.140)
    vfy_xp pts/2 Aug 7 00:04 (10.28.32.140)
    nwp pts/3 Aug 1 13:50 (10.28.32.58)
    vfy_xp pts/4 Aug 7 00:49 (10.28.32.140)
    root pts/5 Aug 2 14:18 (cma19n03)
    nwp pts/6 Aug 5 03:08 (10.28.32.26)
    nwp pts/7 Aug 6 06:58 (10.28.32.58)
    nwp pts/8 Jul 31 12:56 (10.28.32.58)
    nwp_xp pts/9 Jul 31 15:48 (10.28.32.23)
    zhaobin pts/10 Aug 7 00:07 (10.28.32.140)
    nwp pts/11 Aug 5 03:16 (10.28.32.26)
    nwp_qu pts/12 Jul 31 17:12 (10.28.32.23)
    wangdp pts/13 Aug 8 05:52 (10.28.32.175)
    nwp_qu pts/14 Aug 9 06:34 (10.28.32.175)
    luhj pts/15 Aug 9 05:37 (10.28.32.143)
    zhaobin pts/17 Aug 7 00:09 (10.28.32.140)
    nwp pts/18 Aug 5 08:18 (10.28.32.26)
    nwp pts/19 Aug 5 03:19 (10.28.32.23)
    zhaobin pts/20 Aug 7 00:09 (10.28.32.140:0.0)
    nwp_qu pts/21 Aug 1 13:28 (10.28.32.23)
    wangdp pts/22 Aug 8 05:52 (10.28.32.175)
    vfy_xp pts/23 Aug 7 00:49 (10.28.32.140:0.0)
    nwp pts/25 Aug 8 17:58 (10.28.32.23)
    zhaobin pts/26 Aug 8 02:21 (10.28.32.140)
    vfy_xp pts/27 Aug 8 06:56 (10.28.32.78)
    nwp pts/28 Aug 1 13:29 (10.28.32.23)
    nwp pts/29 Aug 4 15:37 (10.28.32.23)
    [/code]
  2. w 比who更详细
    [code]
    $ w
    06:49AM up 8 days, 20:15, 52 users, load average: 0.08, 0.19, 0.24
    User tty login@ idle JCPU PCPU what
    root pts/0 31Jul13 8days 0 0 ssh
    vfy_xp pts/1 Wed12AM 2days 0 0 -ksh
    vfy_xp pts/2 Wed12AM 2days 0 0 -ksh
    nwp pts/3 01Aug13 2:09 1:11 0 cdp
    vfy_xp pts/4 Wed12AM 2days 93:38 6:27 /usr/dt/bin/dtterm
    root pts/5 Fri02PM 7days 17 0 -ksh
    nwp pts/6 Mon03AM 2days 13:35 0 -ksh
    nwp pts/7 Tue06AM 2:43 4 0 -ksh
    nwp pts/8 31Jul13 2:09 3:00 58 xcdp
    nwp_xp pts/9 31Jul13 12:56 23 0 -ksh
    zhaobin pts/10 Wed12AM 2days 0 0 -ksh
    nwp pts/11 Mon03AM 5:30 15:53 0 -ksh
    nwp_qu pts/12 31Jul13 4:29 3:34 1:00 cdp
    wangdp pts/13 Thu05AM 5:24 0 0 vim
    nwp_qu pts/14 06:34AM 0 0 0 w
    luhj pts/15 05:37AM 0 2:15 0 -ksh
    zhaobin pts/17 Wed12AM 2days 25 25 /usr/dt/bin/dtterm
    [/code]
  3. whoami 显示本账户在系统中的用户名
    [code]
    $ whoami
    nwp_qu
    [/code]
  4. who am i 显示当前用户的登录信息
    [code]
    $ who am i
    nwp_qu pts/14 Aug 9 06:34 (10.28.32.175)
    [/code]
  5. logname 显示本账户登录的用户名
  6. last 显示登录记录
    [code]
    $ last
    nwp pts/34 10.28.32.175 Aug 09 06:41 – 06:47 (00:05)
    nwp_qu pts/24 10.28.32.175 Aug 09 06:40 – 06:47 (00:06)
    vfy_xp ftp 10.28.32.152 Aug 09 06:37 – 06:42 (00:04)
    nwp_qu pts/14 10.28.32.175 Aug 09 06:34 still logged in
    luhj pts/15 10.28.32.143 Aug 09 05:37 – 06:50 (01:12)
    root rsh5505698 cmaems Aug 09 05:02 – 05:02 (00:00)
    nwp_xp pts/68 10.28.32.23 Aug 02 07:25 still logged in
    [/code]
  7. tty 显示当前终端名
    [code]
    $ tty
    /dev/pts/14
    [/code]