Linux Knowledge Summary (ii)

Source: Internet
Author: User
Tags egrep

Linux Knowledge Summary (ii) directory: 1. Knowledge summary Figure 2. Review of some of the more ambiguous commands 3. Regular expressions and extended regular expressions I. Knowledge Summary chart

Two. Fuzzy Command review 1.chown
chown  可以改变文件的所属人和所属组
[[email protected] app]$ touch xiaoyufile1[[email protected] app]$ LL./xiaoyufile1-rw-rw-r--. 1 Xiaoyu xiaoyu 0 Jan 23:03/xiaoyufile1[[email protected] app]$ chown liubei xiaoyufile1chown:changing Ownershi P of ' xiaoyufile1 ': Operation not permitted[[email protected] app]$ exitlogout[[email protected] app]# chown Liubei xiaoyufile1[[email protected] app]# LL./xiaoyufile1-rw-rw-r--.  1 liubei xiaoyu 0 Jan 23:03/xiaoyufile1[[email protected] app]# chown Xiaoyu xiaoyufile1[[email protected] app]# LL./xiaoyufile1-rw-rw-r--. 1 Xiaoyu xiaoyu 0 Jan 23:03/xiaoyufile1[[email protected] app]# chown Liubei.liubei Xiaoyufile1[[email pro Tected] app]# LL./xiaoyufile1-rw-rw-r--. 1 liubei liubei 0 Jan 23:03/xiaoyufile1[[email protected] app]# chown Xiaoyu.xiaoyu Xiaoyufile1[[email pro Tected] app]# LL./xiaoyufile1-rw-rw-r--. 1 Xiaoyu xiaoyu 0 Jan 23:03/xiaoyufile1[[email protected] app]# su-xiaoyulast Login: Sat Jan 23:00:59 CST 2018 on pts/0[[email protected] ~]$ cd/app[[email protected] app]$ chown. Liubei Xiaoy Ufile1chown:changing Group of ' xiaoyufile1 ': Operation not permitted
根据以上的命令结果可以得出结论:1.当前用户为文件所属人时,无权更改文件的所属人和所属组2.只有当前用户为root时,才可以更改文件所属人和所属组 3.命令方式为      chown 所属人.所属组 filename    更改文件的所属人和所属组
2.chmod
 The use of chmod numbers I have roughly memorized (chmod xxx file names), but the notation notation is quite strange [[email protected] app]# LL./xiaoyufile1-rw-rw-r--. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 [[email protected] app]# chmod o-w xiaoyufile1 [[email protected ] app]# LL./xiaoyufile1-rw-rw-r--. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 [[email protected] app]# chmod o=rwx xiaoyufile1 [[Email protect ED] app]# LL./xiaoyufile1-rw-rw-rwx. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 [[email protected] app]# chmod g=rwx xiaoyufile1 [[Email protect ED] app]# LL./xiaoyufile1-rw-rwxrwx. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 [[email protected] app]# chmod u=rwx xiaoyufile1 [[Email protect ED] app]# LL./xiaoyufile1-rwxrwxrwx. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 [[email protected] app]# chmod a-w xiaoyufile1 [[email protected ] app]# LL./xiaoyufile1-r-xr-xr-x. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 [[email protected] App]# chmod a-rx xiaoyufile1 [[email protected] app]# LL./xiaoyufile1----------. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 [[email protected] app]# chmod u+rx xiaoyufile1 [[Email protecte D] app]# LL./xiaoyufile1-r-x------. 1 Xiaoyu 0 Jan 23:03/xiaoyufile1 "The results from the above command can be concluded as follows: 1. First usage: chmod u/g/o=xxx filename Changes the permissions of the person/group/other person to XXX 2. the second usage; chmod u/g/o/a-/+ XXX filename will file owner/affiliation Group/other person/everyone plus XXX permissions 3. Disadvantage: Only one permission can be manipulated at a time, the more cumbersome advantages: more accurate
3.ACL Access Control List
ACL权限:     由于系统用户过多,会出现不同用户有着不同的权限需求,所以普通的 文件所属人,文件所属组,其他人这种普通的权限设置方式便不能满足要求。而ACL权限可以给特定的用户以特定的访问权限来实现其要求。     1.ACL设置个人权限


     在设置后,ll命令会显示权限会多一个加号,此时应该调用getfacl 路径名/ 查看权限,会发现此时多了一个user:liubei:rwx权限,原本liubei在文件夹里是没有写入文件的权限的,而在设置之后便可在此文件夹里写入内容     2.ACL设置组权限


            可以在图中看到,liubei,zhangfei都属于shuguo组,在设置了组权限之后,两者均可在文件夹里写入内容。故ACL也可设置组权限3.清空ACL权限

可以看到原本在ll命令下是有+的,在输入命令后+消失了,即取消了ACL权限。

ACL Summary

设置单用户: sefacl -m u:用户名:xxx(权限) 路径设置组:           sefacl -m g:组名:xxx    (权限) 路径取消ACL:        setfacl -b 路径权限优先级:owner > acl user > group 与 acl group 谁的权限多,谁优先  > other
Three. Regular expressions and extended regular expressions

This part doesn't have to be said, it takes a lot of practice

Add user bash, Testbash, basher, SH, nologin (whose shell is/sbin/nologin) to find the/ETC/PASSWD user name with the shell name of the row

cat /etc/passwd | grep "\(^.*\)\>.*\<\1$"

Displays three user root, Mage, Wang's uid, and default shell

cat /etc/passwd | grep -w "^root\|mage\|wang\>"|cut -d":" -f3,7

Find the line at the beginning of the/etc/rc.d/init.d/functions file that follows a word (including an underscore) followed by a parenthesis

cat /etc/rc.d/init.d/functions|grep -w "^[[:alpha:]]*_.*[(][)].*"

Use Egrep to remove its base name in/etc/rc.d/init.d/functions

 echo  "/etc/rc.d/init.d/functions"|egrep -o "\<[[:alpha:]]*$"

Use Egrep to remove the directory name from the path above

echo  "/etc/rc.d/init.d/functions"|egrep -o "^.*/"

Displays lines in the/proc/meminfo file that begin with size S

cat /proc/meminfo |grep -i ^s

Displays lines in the/etc/passwd file that do not end in/bin/bash

cat /etc/passwd | grep -v /bin/bash

Show user RPC default shell program

    cat /etc/passwd |grep "^rpc\b" |cut -d: -f71

Find the two-bit or three-digit number in the/etc/passwd

cat /etc/passwd |grep "\b[0-9]\{2,3\}\b"

A line that displays at least one whitespace character in a CentOS7/etc/grub2.cfg file, followed by a non-whitespace character

    cat /etc/grub2.cfg |egrep "^[[:space:]]+[[:graph:]].*"

Find the line that ends with ' LISTEN ' followed by any number of whitespace characters in the result of the "Netstat-tan" command

netstat -tan |grep "LISTEN[[:space:]]\+$"

Displays the user name and UID for all system users on CentOS7

cat /etc/passwd |cut -d: -f1,3 |grep -v root |grep "\b[[:digit:]]\{1,3\}\b$"

Linux Knowledge Summary (ii)

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.