several commands of W
WhoAmI View current logged on user
W.H.O.
[[email protected] ~]# who shows which users are currently logged on to the system
User name Login Terminal Logon Hours
Root Tty1 2016-06-06 17:57
Root pts/0 2016-06-06 18:01 (192.168.50.1)
Terminal type:
Pty: Physical terminal.
Console: Control console. (VGA card)
TTY: virtual terminal (VGA card)
TTYs: serial terminal
pts/#: Pseudo terminal
Who–r Display the current run level
Who–h Display Head
[Email protected] ~]# Who-r
Run Level 3 2016-06-06 17:39
[Email protected] ~]# who-h
name Line Time Notes
Root Tty1 2016-06-06 17:57
Root pts/0 2016-06-06 18:01 (192.168.50.1)
View admin user has no login
[[email protected] ~]# who |grep admin
[[email protected] ~]# who |grep admin
[[email protected] ~]# echo $?
1
write a script. See If the admin user is logged in every 5 seconds. If you sign in, you are logged in, and you exit the script.
Sleep # delay for a few seconds
#!/bin/bash
#
For I in {1..100000000};d o
Sleep 5
Who |grep admin &>/dev/null
If [$?-eq 0];then
echo "Admin Denglu"
Exit 0
Fi
Done
W
[[Email protected]~]# w is similar to WHO, command more detailed than who
19:24:56 up 1:45, 3 users, Load average:0.00, 0.00, 0.00
USER TTY from [email protected] IDLE jcpu PCPU
Root tty1-17:57 1:25m 0.05s 0.05s-bash
Root pts/0 192.168.50.1 18:01 0.00s 0.24s 0.00s W
Admin pts/1 192.168.50.1 19:21 3:10 0.01s 0.01s–bash
&nbsP
Last show logged in information
[[email protected] ~]# last display /var/log/wtmp file, showing the user's login history and system restart history
Admin PTS/1 192.168.50.1 Mon June 6 19:21 still logged in
Admin PTS/1 192.168.50.1 Mon June 6 19:19-19:21 (00:01)
Root pts/0 192.168.50.1 Mon June 6 18:01 still logged in
Root Tty1 Monjun 6 17:57 still logged in
Reboot system boot 2.6.32-504.el6.i monjun 6 17:39-19:27 (01:47)
Last–n 3 shows only the last three times
Lastb display /var/log/btmp file , user Error login attempt
[Email protected] ~]# LASTB
Chenlon tty1 Mon June 6 17:57-17:57 (00:00)
Btmp begins Mon June 6 17:57:27 2016
Last–n 3 shows only the last three times
Lastlog Displays the most recent successful login information for each user of the current system
-uusername: Displays the most recent login information for the specified user
[Email protected] ~]# lastlog-u root
User name Port from Last Login Time
Root pts/0 192.168.50.1 6 months 6 18:01:31 +0800 2016
basename Get the file name under the path
[Email protected] ~]# BASENAME/ETC/PASSWD
passwd
BaseName $ Show the name of the script itself
$ A script path and name when executing a script
Mail messages. The message is stored in the Mbox directory in the user's home directory
D means delete message
R means reply message
-S message subject
[Email protected] ~]$ cat/etc/passwd |mail–s "How is it?" Root sends the cat 's message to root as the email content
[[Email protected] ~]# mail
Heirloom Mail Version 12.4 7/29/08. Type? For help.
"/var/spool/mail/root": 2messages 2 new
>n 1 [email protected] Monjun 6 19:49 48/2099
N [email protected] Mon June 6 19:49 47/2014 "How is it?"
Enter numbers directly See mail
Hostname Display the host name of the current host can also change the real-time hostname, $HOSTNAME
Write a script if the current hostname is not Zhongguo, change to Zhongguo
if the current hostname is localhost , change to Zhongguo
#!/bin/bash
#
[' hostname '! = Zhongguo]&&hostname Zhongguo
[' hostname ' = localhost]&&hostname Zhongguo
if the current host name is empty, or if the (none) , or you can change it to Zhongguo for localhost
[[Email protected] ~]# [-Z ' hostname '] | | [' hostname ' = = ' (none) '] | | [' hostname ' = = ' localhost '] && Hostnamezhongguo
Generate random numbers
random:0-32768
Random number generator:
/dev/random
/dev/urandom
generate a random number and get the maximum value from it
#!/bin/bash
#
For I in {1..10};d o
echo $RANDOM >>/tmp/sort.txt
Done
Cat/tmp/sort.txt | Sort-n |TAIL-1
Or take the maximum number and the minimum number
#!/bin/bash
#
Declare-i max=0
Declare-i min=0
For I in {1..10};d o
g= $RANDOM
[$I-eq 1] && min= $G
if[$I-le 9];then
Echo-n "$G,"
Else
echo "$G"
Fi
[$G-gt $MAX] && max= $G
[$G-lt $MIN] && min= $G
Done
echo "$MAX, $MIN"
This article from "Linux operation and Maintenance" blog, declined reprint!
Several commands of W