Linux commands: W, who, WhoAmI, last, Lastb, Lastlog, basename, mail, hostname

Source: Internet
Author: User

Several common small commands for viewing logged-in users:


1, W : Displays the currently logged on user and what they are doing

[Email protected] usr]# W

10:02:06 up 2 days, 2:06, 1 user, Load average:0.00, 0.00, 0.00

USER TTY from [email protected] IDLE jcpu PCPU

Root pts/0 10.109.134.247 Mon09 0.00s 0.40s 0.15s W


2, WhoAmI display the current login system valid user name

[Email protected] usr]# WhoAmI

Root


3. Who shows which users are currently logged in

Who-h display the current user at the same time the header information

Who-r Display current system RunLevel

[Email protected] usr]# Who-r

Run Level 3 2016-10-24 07:55


[email protected] usr]# who

Root pts/0 2016-10-24 09:01 (10.109.134.247)

Who-h

[Email protected] usr]# who-h

Name Line time Note- h shows the current user displaying header information at the same time

Root pts/0 2016-10-24 09:01 (10.109.134.247)

User name terminal type logon time telnet display login IP

Terminal type:

Console: Consoles

Pty: Physical Terminal (VGA) General Pty Terminal Connection only one

tty#: Virtual Terminal ("the") Local connection for virtual machines

ttys#: Serial terminal #表示第几个串行终端连接

pts/#: Pseudo terminal #表示第几个伪终端登录


4, L a ST: display/var/log/wtmp file showing user login history and System restart history

- N #: Show information about recent # times

5, Lastb: /var/log/btmp file that displays user error login attempts

-N #: Displays information about recent # times

6, Lastlog: Displays the last successful login information for each user;

- u USERNAME: Display recent login information for a specific user

7. basename displays the filename of the path

Basename/etc/service

[Email protected] usr]# Basename/etc/service

Service

$: script path and name when executing script      

8, mail: View the current user's mail pieces

Mail-s Specifying message headers

Cat/etc/fstab | Mail-s "Hello,root" root

Send the/etc/fstab file content as the message body to the root user.

[Email protected] usr]# Cat/etc/fstab | Mail-s "Hello,root" root

[[Email protected] usr]# mail

Heirloom Mail Version 12.4 7/29/08. Type? For help.

"/var/spool/mail/root": 1 message 1 new

>n 1 root Wed Oct 14:14 35/1681 "Hello,root"

& 1 1 indicates the message number, enter to view the contents of message 1

Message 1:

From [email protected] Wed Oct 26 14:14:46 2016

Return-path: <[email protected]>

X-original-to:root

TS 0 0

TMPFS/DEV/SHM TMPFS Defaults 0 0

Devpts/dev/pts devpts gid=5,mode=620 0 0

Sysfs/sys Sysfs Defaults 0 0

PROC/PROC proc Defaults 0 0


&q Enter Q to exit the mail system

Held 1 Message In/var/spool/mail/root


9, hostname: Display host name

Hostname Donggen indicates that the host name of the current host is changed to Donggen

[Email protected] usr]# hostname

Xuelinux

[Email protected] usr]# hostname Donggen

[Email protected] usr]# hostname

Donggen


If the host name of the current host is not www.magedu.com, change it to www.magedu.com

If the host name of the current host is localhost, change it to www.magedu.com

If the host name of the current host is empty, or (none), or localhost, change it to Linux

[-Z ' hostname '] | | [' hostname ' = = ' (none) '-o ' hostname ' = = ' localhost '] && hostname Linux

10. Sleep # hibernate # seconds


11. Generate Random Number command echo "random"

$RANDOM: 0-32768 Random numbers in this range

[Email protected] ~]# echo "$RANDOM"

4742

[Email protected] ~]# echo "$RANDOM"

19762

[Email protected] ~]# echo "$RANDOM"

12593

Random number generator: Entropy pool (random number of storage pools, random numbers inside may be emptied)

/dev/random:

/dev/urandom:

Command instance:

1, check the current system, Donggen users are logged in:

W.H.O. | grep "Donggen"

[email protected] usr]# who | grep "Donggen"

Donggen pts/1 2016-10-26 11:34 (10.109.134.247)


2, write a script, using random to generate 10 random numbers, and find the maximum and minimum value

#!/bin/bash

#program

# Take a random 10-digit maximum and minimum value

#history Donggen 2016-10-26-20:55

Declare-i max=0

Declare-i min=0


For I in {1..10}; Do

Myrandom= $RANDOM

[$I-eq 1] && min= $MYRANDOM

If [$I-le 9]; Then

Echo-n "$MYRANDOM,"

Else

echo "$MYRANDOM"

Fi

[$MYRANDOM-gt $MAX] && max= $MYRANDOM

[$MYRANDOM-lt $MIN] && min= $MYRANDOM

Done

echo "$MAX, $MIN"

This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1866101

Linux commands: W, who, WhoAmI, last, Lastb, Lastlog, basename, mail, hostname

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.