Linux Learning log (iii)

Source: Internet
Author: User
Tags define local echo command

Rights Management
   owner,group,other         属主,属组,其他
Permissions:
    read write execute      r   w    x    用户的不拥有某位权限,则使用-占位    r-x:读和执行的权限    r--:只读权限    rw-:读写权限    使用8位数来表示    r:4    w:2    x:1

File:

  r:可以使用内容查看类的命令来显示其相关内容  w: 可以使用编辑器修改其内容  x:可以将其发起一个进程

Directory:

  r:可以使用ls命令查看目录内容的文件信息  w:可以创建、删除文件  x:可以使用ls -l命令来查看目录内容的文件信息,并且可以使用cd命令切换此目录为工作目录:

owner and owner of modified file: Only admin executable, Chown,chgrp

chmod command
操作三类用户的权限:使用8进制形式    chmod OCTAL -MODE file ...            u:属主            g:属组            o:其他            a:所有            =:操作指定类型用户的权限            +/—:操作置顶类型用户的单个权限            参照其他文件的权限为当前文件来赋权                chmod --reference=参照文件名 文件名操作指定类别用户的权限:使用u,g,o,a来赋权,基于=或+/-来进行  参照其他文件的权限当文件赋权限
Umask
 创建文件:666-umask        文件默认决不允许出现执行权限: 创建目录:777-umask root:022 如果用户名和基本组名一致:002,否则为022   
Modify the owner or genus of a file: Chown,chgrp
chown [option] UserName [{:|.} GroupName] file ...           -R : 递归     -- reference
Permissions Application Model:
  1.进程的属主,是否与文件的属主相同,如果相同,进程则以文件属主的权限来访问文件,否则,进程的属主所属的组,是否其中之一与文件的属组相同,如果相同,进程则以文件属组的权限来访问文件;否则,进程则以文件的其他用户的权限来访问文件  2.总结权限管理:chmod chown chgrp umask
Practice

1. Create a new user Openstacl without creating a home directory, switch to this directory using the SU command after creation, and view the values of its command prompt and path and home environment variables

         useradd -M openstack         su -openstack         echo $PATH $HOME

2. Copy the/etc/skel directory to/home/openstack

          cp -r /etc/skel /home/openstack
  1. The main genus groups that change/home/openstack and its internal files are openstack;

        

    4./home/openstack and its internal files, belong to the combination other users do not have any access rights

  2. New System group MySQL, new system user MySQL, belongs to the MySQL group, requires no home directory and shell for/sbin/nologin;

        groupadd -r mysql    
  3. New GID 600 group Doyle, new user Gentoo, request home directory for/users/gentoo, password with user name

          groupadd -g 600 doyle      mkdir /users      useradd -d /users/gentoo gentoo      passwd gentooo
  4. New user CentOS, whose home directory is/users/centos, password with user name

    useradd -d /users/centos centos;passwd centos;
  5. New User www, whose home directory is/users/www, deletes the WWW user but retains its home directory

    useradd -d /users/www www;userdel www
  6. User Gentoo and CentOS are Doyle's additional groups

       usermod -a -G doyle gentoo   usermod -a -G doyle centos
Bash Introduction

Shell: Human-computer interface,
BASH: command interpreter, parser

Bash features VI:
 快捷键     Ctrl+a:跳至命令行首     Ctrl+e:跳至命令行尾     Ctrl+u:删除命令行首至当前光标所在处的内容     Ctrl+k:删除当前光标所在处至命令行尾的内容     Ctrl+l:清屏,相当于clear命令     Ctrl+c:终止或者取消命令     Ctrl+z:将当前命令送至后台(fg调回命令)
Bash feature VII: complement function

Command completion: Search for completion in path

    shell命令:内部,外部         外部:在系统某路经下有一个可执行程序    PATH,一组以冒号分隔的路径

Path completion: Complete under the given heading path, or the current directory if there is no path to the prefix

       使用tab补全
Bash features eight:
 提供编程环境     支持使用变量     支持程序控制

#!/bin/bash is called Shebang

Practice

1. Create a group Newgroup,id number 4000

2. Create a user Doyle with an ID number of 3001 and an additional group of newgroup;
3. Create a directory/tmpj/hellodirxyz
4. Copy the/etc/fstab to the above directory
5. The owner and the owner of the directory and the internal file is Doyle
6. Leave the directory and other users of the internal file without any permissions

Bash features nine: variables in bash

Weakly typed language variables:

   1.不强制区分变量的类型,无论存储何种数据,均已字符格式进行   2.无须事先声明:用到时,直接使用,直接赋值   bash:动态编程语言,是弱类型语言

Types of variables:
Local variable: Valid only for the current shell process, not for its child shell and other shells

    定义变量: [set]Var_Name="Value"    引用变量: ${Var_Name}    撤销变量:unset Var_Name

Local variables: Valid only for a part

    定义变量:local Var_Name="Value"

Environment variable: Valid for its shell process and its child shell:

      定义:export Var_Name="var name"      

Positional variables:

       $1,......$n

Special variables

      $0:脚本名称自身        $?:上一条命令的执行状态            状态用数字表示:0-255            0:表示成功                1-255:失败,1.2.127.255预留        $$         $!        $#        $*

Naming Requirements for variables:

   只能使用数字,字母,和下划线组成   不能以数字开头   不能使用程序中的关键字   见名知义

set with no parameters, showing all variables of the current system
environment variables: Used to define bash's working characteristics to hold the current session's property information
Show all environment variables: export, env, printenv

Bash profile: Persist User Configuration

Profile class: Provides configuration for interactively logged-on users

         /etc/profile 全局         /etc/profile.d/*.sh 全局         ~/.bash_profile 个人配置,仅对当前用户有效  功能:   设定环境变量   运行命令或者脚本

BASHRC class: Non-interactive login user provides configuration

       /etc/bashrc:全局       ~/.bashrc:个人配置 功能:   设定本地变量   定义命令别名

Login Type:

    交互式登录:直接通过终端输入用户信息登陆系统     su - UserName或su -l UserName:    如何读取配置文件    /etc/profile -->/etc/profile.d/*.sh -->~/.bash_profile-->~/.bashrc -->/etc/bashrc    非交互式登录:            su UseName             图形界面下的终端             执行脚本的时候,先设置配置文件        如何读取配置文件        ~/.bashrc -->/etc/bashrc -->/etc/profile.d/*.sh

Notifies the shell to reread system files

     source(.) 重读配置文件
Bash script: process-oriented programming
 顺序执行:默认法则,逐条执行各命令 选择执行:分支,条件判断,符合条件的分支予以执行 循环执行:将同一段代买反复执行有限次,所以,循环必须有退出条件,否则将陷入死循环     
Loop control Statements

For loop

      for var_Name in 列表; do          循环体(正常执行的执行命令)          语句1          语句2          语句3          ...      done

bash-n script File Check script file syntax is incorrect

       while       until
How to generate a list:
    生成数字列表{start..end}、seq[start][stop]      seq 起始数字、步长,结束数字

For: Iterates through each element in a given list by using a variable. Executes the loop body once each time the variable is assigned, until the assignment completes all elements exiting the loop

总结:生成列表方式   1.直接给出列表   2.使用文件名通配的机制生成列表   3.可以使用{}或seq命令生成数字序列   4.使用命令生成  
Commands for text-processing classes WC
   wc[option][file]...     -l:统计行数     -c:统计字节数     -w:统计单词数    
TR converts characters or deletes characters

TR ' Set 1 ' Set 2 '
Tr-d ' Character set fit '

Cut: Slices According to the created delimiter, and displays the slices to be displayed

Cut option Parameters

-d字符:指定分隔符-f数字:指定要显示的字段   单个数字:一个字段   多个离散字段:逗号分隔   多个连续字段:-分隔
Sort: Compare by character

Sort[options] File

-f:忽略大小写-n:对数字进行排序-t:指定分隔符-k 数字:指定分隔后进行比较字段-u:重复的行,只显示一行uniq:移除重复的行-c:统计每一行出现的次数(靠着的行)-d:仅显示出现最少两次的行-u:仅显示不重复的行
Practice

(1) switch to CentOS user, define local variable Firstvar, with value "Test variable"

    su -centos    FirstVar="test variable"

(2) Another terminal, using Gentoo users to view the value of the Firsvar variable, if there is no value, why?

     只对当前shell进程有效,对其子shell以及其他shell都无效

(3) Declare a variable curtime, whose value is the current system

       curTime=`date +%T`

(4) Use the Echo command to display the value of "The current time is:" is followed by the curtime variable

    echo "the current time is: $curTime"

(5) Back to the CentOS user's terminal, copy the/ETC/PAM.D directory to the/tmp directory, and re-command as test;

         cp -r /etc/pam.d/ /tmp/test

(6) Declare the variable filename, whose value is the directory you just copied/tmp/test

      fileName="/tmp/test"

(7) Any other user who modifies the directory and all of its internal files represented by the variable filename does not have any access rights;

        chmod -R o=$fileName

(8) Can centos users modify the owner and owner of the directory represented by the variable filename? If it can, change the Gentoo user and Gentoo group, and if not, use the root user to modify

Scripting exercises

Practice one: Write a script that displays the content type of each file in the/var/log directory by using the file command;
Tip: List production method is/var/log/*

Exercise two: Write a script
1. Create a/tmp/scripttest directory, save directory names with variables '
2. Create a test file in the directory Tfile1-tfile20
3. Create user testuser1 and TestUser2;
4. Replace the Tfile1-ftile10 and the genus Group with the testuser1;
5. Change the Tfile1-tfile20 and the genus Group to TestUser2

Linux Learning log (iii)

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.