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] ~]#

时间: 2024-10-06 04:54:21

linux-facl,whoami,who,w,last,lastlog,basename,mail,hostname,$random,case语句的相关文章

linux基础篇-19,w who whoami last lastb lastlog basename

w who whoami last lastb lastlog basename sleep hostname mail ################################################ who whoami last:显示/var/log/wtmp文件,显示用户登录历史及系统重启历史 lastb:/var/log/btmp文件,显示用户错误尝试登录 lastlog:从未登录过的用户 ########################################

linux 笔记--facl,case语句及磁盘文件系统

facl:filesystem access control list 利用文件扩展保存额外的访问控制权限 一般权限的访问次序:owner--group--other 若有额外权限的访问次序:owner--facl.user--group--facl.group--other 设定额外权限:setfacl   查看额外权限:getfacl -m 设定 -x 取消 -m u:UID:权限 设定额外用户权限 -m g:GID:权限 设定额外组权限 -x u:UID 取消 -m dg:GID 对目录及

2016-5-15 linux基础学习——case语句

文件系统访问列表FACL:利用文件扩展保存控制权限    权限应用次序:ower->group->other              ower->facl中user->group->facl中group->othersetfacl    -m:设定        u:UID:perm 设定属主        g:GID:perm 设定属组            eg:setfacl -m u:hadoop:rw 给hadoop用户设定读写权限    -x:取消    

linux下Bash编程case语句及编写脚本(八)

1.case语句,格式如下: case 变量 in 值1) 语句1 ... ;;  每分支语句以分号结束 值2) 语句2 ... ;; *)    其他,相当于if语句else 语句3 ... ;; esac   整条case语句结束 2.编写一个任意添加与删除用户的脚本,要求如下: 2.1:如果脚本选项是-a或--add:,将添加用户; 如果选项是-d或--del,将删除用户, 如果是-h或--help显示帮助信息,如果是-v或--verbose显示执行过程,否则不显示执行过程 2.2:脚本选

linux基础16-bash编程(case语句及脚本选项 )

(1) case语句:选择结构 case SWITCH in value1) statement ... ;; //双分号结尾. value2) statement ... ;; *) statement ... ;; esac //esac结尾. (2) shift参数说明: 执行shift命令后,位置变量($1-$9)中的命令行参数会依次向左传递. 例: #!/bin/bash # DEBUG=0 ADD=0 DEL=0 for I in `seq 0 $#`; do //解释:seqs 1

Linux -- who whoami

(一) whoami  是一个相当简单的命令 (二) `who': Print who is currently logged in============================================ `who' prints information about users who are currently logged on.Synopsis: `who' [OPTION] [FILE] [am i] If given no non-option arguments, `

Linux Directory commands: mkdir, rmdir, tree dirname,basename

Linux命令之目录管理类命令:mkdir, rmdir, tree, dirname, basename mkdir命令:创建目录/新建目录 语法:mkdir [OPTION] /PATH/TO/SOMEWHERE 常见参数选项: -p:创建父目录//递归创建 -V:显示创建信息 示例: 如何/tmp/下创建目录:x_m, x_n, y_m, y_n # mkdir /tmp/{x_,y_}{m,n} rmdir命令:删除目录 语法:rmdir /PATH/TO/SOMEWHERE 常见的参数

linux的whoami, who指令

whoami 功能说明: 显示用户名称 语法: whoami 补充说明:显示自身的用户名称,本指令相当于执行  id -un 指令 whoami 与 who am i的区别 who这个命令重点在用来查看当前有那些用户登录到了本台机器上 who -m的作用和who am i的作用是一样的 who am i显示的是实际用户的用户名,即用户登陆的时候的用户ID.此命令相当于who -m whoami显示的是有效用户ID ,是当前操作用户的用户名 命令实践: [[email protected]~]$

Linux FACL(文件访问控制列表)

文件有三种权限 属主权限   属组权限  其他权限 现在有这样一个场景,用户 A 想把文件共享给不是同组内用户 B ,而又不想修改其他权限,这时候 FACL 就起作用了 FACL可以给文件添加一个拓展权限,此时只需要在文件拓展权限列表中加入用户  B 并给予权限即可 FACL用法: 获得文件FACL getfacl 文件名 $ getfacl facl.txt # file: facl.txt # owner: eko # group: eko user::rw- user:tom:rwx //