linux-facl,whoami,who,w,last,lastlog,basename,mail,hostname,$random,case语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux-facl,whoami,who,w,last,lastlog,basename,mail,hostname,$random,case语句相关的知识,希望对你有一定的参考价值。
文件系统访问列表:
FACL:Filesystem Access Control List
利用文件扩展保存额外的访问控制权限
owner>group>other
Owern>facl,user>group>facl,group>other
setfacl
-m: 设定
u:UID:perm
g:GID:perm
-x:取消
u:UID
g:GID
[[email protected] ~]# getfacl /tmp/
getfacl: Removing leading ‘/‘ from absolute path names
# file: tmp/
# owner: root
# group: root
# flags: --t
user::rwx
group::rwx
other::rwx
[[email protected] backup]# setfacl -m u:hadoop:rw inittab
[[email protected] backup]# getfacl inittab
# file: inittab
# owner: root
# group: root
user::rw-
user:hadoop:rw-
group::r--
mask::rw-
other::r--
[[email protected] backup]# setfacl -m g:hive:rw inittab
[[email protected] backup]# getfacl inittab
# file: inittab
# owner: root
# group: root
user::rw-
user:hadoop:rw-
group::r--
group:hive:rw-
mask::rw-
other::r--
[[email protected] backup]# setfacl -m u:hive:rwx inittab
[[email protected] backup]# getfacl inittab
# file: inittab
# owner: root
# group: root
user::rw-
user:hadoop:rw-
user:hive:rwx
group::r--
group:hive:rw-
mask::rwx
other::r--
[[email protected] backup]# setfacl -x g:hive inittab
[[email protected] backup]# getfacl inittab
# file: inittab
# owner: root
# group: root
user::rw-
user:hadoop:rw-
group::r--
mask::rw-
other::r--
[[email protected] backup]#
whoami:显示当前登录用户
[[email protected] backup]# whoami
root
[[email protected] backup]#
终端(terminal,或者叫物理终端):
是一种设备,不是一个程序,一般说的就是能提供命令行用户界面的设备,典型的是屏幕和键盘,或其他的一些物理终端。
虚拟终端:
屏幕和键盘只是一个终端,可能不够用,又不想增加设备投入,就产生了虚拟终端。
gnome-terminal,urxvt,mlterm,xterm等等:
是一个程序,职责是模拟终端设备,和虚拟终端的区别表面上在于它以 GUI 形式的窗口出现,内部则是程序结构和系统控制结构有所不同,但本质上差不多。
控制台(console):
显示系统消息的终端就叫控制台,Linux 默认所有虚拟终端都是控制台,都能显示系统消息。
但有时专指CLI下的模拟终端设备的一个程序,和gnome-terminal,urxvt,mlterm,xterm等相同,只是CLI和GUI界面的区别。一般console有6个,tty1-6,CTRL+ALT+fn切换。还没听说过怎么换console
who:显示登陆终端
[[email protected] backup]# who -H
NAME LINE TIME COMMENT
rhel tty1 2017-02-17 17:40 (:0)
rhel pts/0 2017-02-17 17:40 (192.168.1.18)
rhel pts/1 2017-02-17 17:42 (192.168.1.18)
[[email protected] backup]#
w:显示用户登录信息,比who更详细
[[email protected] backup]# w
18:46:50 up 1:07, 3 users, load average: 0.03, 0.02, 0.00
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
rhel tty1 :0 17:40 1:07m 1.71s 0.16s pam: gdm-password
rhel pts/0 192.168.1.18 17:40 0.00s 0.21s 0.17s sshd: rhel [priv]
rhel pts/1 192.168.1.18 17:42 22.00s 0.02s 0.15s sshd: rhel [priv]
last:显示历史登陆信息
[[email protected] backup]# last
rhel pts/1 192.168.1.18 Fri Feb 17 17:42 still logged in
rhel pts/0 192.168.1.18 Fri Feb 17 17:40 still logged in
rhel tty1 :0 Fri Feb 17 17:40 still logged in
reboot system boot 2.6.32-504.el6.x Fri Feb 17 17:39 - 18:48 (01:08)
rhel pts/2 192.168.1.18 Sat Nov 19 22:13 - crash (89+19:26)
rhel pts/1 192.168.1.18 Sat Nov 19 21:31 - 00:13 (02:42)
rhel pts/0 192.168.1.18 Sat Nov 19 18:17 - 23:30 (05:12)
rhel tty2 Sat Nov 19 17:54 - crash (89+23:45)
rhel tty1 :0 Sat Nov 19 17:54 - crash (89+23:45)
reboot system boot 2.6.32-504.el6.x Sat Nov 19 17:54 - 18:48 (90+00:53)
rhel tty6 Thu Jun 25 22:04 - crash (512+20:49)
rhel pts/1 10.4.10.236 Thu Jun 25 21:21 - 21:21 (00:00)
rhel pts/1 10.4.10.236 Thu Jun 25 21:20 - 21:20 (00:00)
[[email protected] backup]# last -n 3
rhel pts/1 192.168.1.18 Fri Feb 17 17:42 still logged in
rhel pts/0 192.168.1.18 Fri Feb 17 17:40 still logged in
rhel tty1 :0 Fri Feb 17 17:40 still logged in
wtmp begins Sun Jun 21 02:26:29 2015
[[email protected] backup]#
lastlog:显示所有用户最近一次成功登陆的信息
[[email protected] backup]# lastlog -u hadoop
Username Port From Latest
hadoop **Never logged in**
[[email protected] backup]#
[[email protected] backup]# lastlog
Username Port From Latest
root pts/1 10.4.10.226 Thu Jun 25 14:24:23 -0700 2015
bin **Never logged in**
daemon **Never logged in**
adm **Never logged in**
lp **Never logged in**
sync **Never logged in**
shutdown **Never logged in**
halt **Never logged in**
[[email protected] backup]# basename /etc/abc/me
me
[[email protected] backup]#
[[email protected] backup]# cat /etc/fstab | mail -s "how are you?" root
[[email protected] backup]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 root Fri Feb 17 19:04 32/1406 "how are you?"
& 1
Message 1:
From [email protected] Fri Feb 17 19:04:58 2017
Return-Path: <[email protected]>
X-Original-To: root
Delivered-To: [email protected]
Date: Fri, 17 Feb 2017 19:04:58 -0800
To: [email protected]
Subject: how are you?
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R
#
# /etc/fstab
# Created by anaconda on Sun Jun 21 02:15:00 2015
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=57d85756-7680-4c7c-9125-6ad67dae2c45 / ext4 defaults 1 1
UUID=2622a4b4-ddc9-47a3-aa2b-f06bc9bec085 /boot ext4 defaults 1 2
UUID=33d94759-fa01-4c4f-b4ac-bf3a1fe5e84f swap swap defaults 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
Held 1 message in /var/spool/mail/root
[[email protected] backup]#
[[email protected] backup]#
[[email protected] backup]# mail -s "how are you?" root < /etc/fstab
[[email protected] backup]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/root": 4 messages 1 new
1 root Fri Feb 17 19:04 33/1417 "how are you?"
2 root Fri Feb 17 19:06 33/1417 "how are you?"
3 root Fri Feb 17 19:06 33/1417 "how are you?"
>N 4 root Fri Feb 17 19:06 32/1406 "how are you?"
& 4
Message 4:
From [email protected] Fri Feb 17 19:06:45 2017
Return-Path: <[email protected]>
X-Original-To: root
Delivered-To: [email protected]
Date: Fri, 17 Feb 2017 19:06:45 -0800
To: [email protected]
Subject: how are you?
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R
#
# /etc/fstab
# Created by anaconda on Sun Jun 21 02:15:00 2015
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=57d85756-7680-4c7c-9125-6ad67dae2c45 / ext4 defaults 1 1
UUID=2622a4b4-ddc9-47a3-aa2b-f06bc9bec085 /boot ext4 defaults 1 2
UUID=33d94759-fa01-4c4f-b4ac-bf3a1fe5e84f swap swap defaults 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
Held 4 messages in /var/spool/mail/root
[[email protected] backup]#
[[email protected] backup]# hostname cxiong
[[email protected] backup]# hostname
cxiong
[[email protected] backup]# echo $HOSTNAME
localhost
[[email protected] backup]#
生成随机数
RANDOM: 0-32768
随机数生成器:熵池
/dev/random:如果熵池为空,则会阻塞进程
/dev/urandom:如果熵池为空,则不会阻塞进程
[[email protected] ~]# !bash
bash random.sh
1:12418
2:11349
3:26745
4:11226
5:8126
6:5194
7:3741
8:8878
9:13050
10:10280
the max random is:26745
the min random is:3741
[[email protected] ~]# cat random.sh
#!/bin/bash
declare -i max=0
declare -i min=0
for i in {1..10};do
tmp=`echo "$RANDOM"`
echo "$i:$tmp"
if [ $i -eq 1 ];then
min=$tmp
max=$tmp
else
if [ $tmp -gt $max ];then
max=$tmp
elif [ $tmp -lt $min ];then
min=$tmp
fi
fi
done
echo "the max random is:$max"
echo "the min random is:$min"
[[email protected] ~]#
case语句:选择结构
case SWITCH in (SWITCH为值)
value1)
statement
...
;; (语句以双分号结尾)
value2)
statement
...
;;
*)
statement
...
;;
esac (esac结尾)
[[email protected] ~]# cat case.sh
#!/bin/bash
case $1 in
[0-9] )
echo "digit";;
[a-Z] )
echo "zimu";;
*)
echo "else";;
esac
[[email protected] ~]#
以上是关于linux-facl,whoami,who,w,last,lastlog,basename,mail,hostname,$random,case语句的主要内容,如果未能解决你的问题,请参考以下文章