Linux操作系统(命令定义/用户组管理)

一,文件传输scp sftp xftp rz sz

scp      linux主机之间的文件传输 

sftp      linux主机之间的文件传输

 xftp   window 和linux主机之间的文件传输

rz 将      windows主机文件发送到linux主机(xshell7需要下载包)

sz 将  linux主机的文件发送到window主机     (xshell7需要下载包)

 二,bash shell 特性

1.变量

        变量环境变量(全局变量) 自定义变量 (局部变量)

        变量名=值 --自定义变量        作用域范围 ( 仅在当前运行终端生效)

        export 变量名=值 --环境变量 作用域范围 (当前运行终端生效,子shell下生效)

        echo $变量名

//局部变量
[root@a ~]# i=1
[root@a ~]# echo $i
1
[root@a ~]# export j=1
[root@a ~]# echo $j
1

        set 显示所有变量

        unset 取消变量

2.内置命令 外置命令

        查看命令类型 type

        特点: 内置命令执行效率高于外置命令 time cd time passwd

//查看命令位置
[root@a ~]# type cd
cd is a shell builtin
[root@a ~]# type passwd
passwd is hashed (/usr/bin/passwd)
//查看命令的运行时间
[root@a ~]# time cd

real	0m0.000s
user	0m0.000s
sys	0m0.000s
[root@a ~]# time passwd
Changing password for user root.
New password: 
BAD PASSWORD: The password fails the dictionary check - it does not contain enough DIFFERENT characters
Retype new password: 
Sorry, passwords do not match.

passwd: Failed preliminary check by password service

real	0m13.808s
user	0m0.014s
sys	0m0.035s

        alias 命令别名(临时生效) 

        alias     别名='命令本身'      alias chaxun=''/usr/sbin/ip"

                                                定义chaxun为:使用这个位置的命令

[root@a ~]# alias chuangjian=touch   //定义chuangjian为touch的属性
[root@a ~]# chuangjian daibi         //创建一个叫daibi的文件
[root@a ~]# ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Public
bashrc           Downloads  Music                 shabi
daibi            file1      new_file.txt          Templates
Desktop          file.txt   Pictures              Videos

//定义chaxun为ip
[root@a ~]# which ip a
/usr/sbin/ip
/usr/bin/which: no a in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@a ~]# chaxun="/usr/sbin/ip"
[root@a ~]# $chaxun a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:32:58:80 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.128/24 brd 192.168.220.255 scope global dynamic ens160
       valid_lft 1390sec preferred_lft 1390sec
    inet6 fe80::89bd:edbb:24b2:ed65/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:8a:57:f6 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:8a:57:f6 brd ff:ff:ff:ff:ff:ff

        unalias 取消别名

[root@a ~]# unalias chuangjian
[root@a ~]# chuangjian nihao
bash: chuangjian: command not found...

        永久生效的别名

         将命令追加写入指定文件

         在根目录下:

                /etc/bashrc 对系统用户都生效永久别名

                使用 source /etc/bashrc 或者 exit 或者 bash进行刷新

        在~目录下      

                  ~/.bashrc 仅对当前用户生效永久别名(~代表所有的家目录下的bashrc) 

                 使用source /etc/bashrc 或者 exit 或者 bash进行刷新

//在这个[root@a ~]# vim ~/.bashrc操作下
alias hello='echo hello,everybody>>file.txt'
alias shuaxin='echo 当前时间为`date`>new_file.txt'
此时可以查看
[root@a ~]# source /root/bashrc          //刷新root下的bach
[root@a ~]# hello  
[root@a ~]# cat file.txt
hello,everybody
[root@a ~]# hello|cat file.txt
hello,everybody
[root@a ~]# hello|cat file.txt
hello,everybody
hello,everybody
[root@a ~]# hello|cat file.txt
hello,everybody
hello,everybody
hello,everybody

3.history 命令历史

        history -w 将缓存区的历史保存在历史文件

         -C 清空所有命令历史

         -d 删除指定的命令历史 history -d 11

         ~/.bash_history

         !2 匹配第二条命令历史执行该命名

         !-2 匹配倒数第二条命令历史执行该命名

         !! 匹配上一次执行的命令

[root@a ~]# history -c
[root@a ~]# history -w
[root@a ~]# history 
    1  history -w
    2  history 
[root@a ~]# !!
history 
    1  history -w
    2  history 
[root@a ~]# ehco shabi
bash: ehco: command not found...
Similar command is: 'echo'
[root@a ~]# echo shabi
shabi
[root@a ~]# !!
echo shabi
shabi
[root@a ~]# !-3
history 
    1  history -w
    2  history 
    3  ehco shabi
    4  echo shabi
    5  history 
[root@a ~]# history 
    1  history -w
    2  history 
    3  ehco shabi
    4  echo shabi
    5  history 
[root@a ~]# 

4.hash 命令缓存(!!!如果定义了变量,hash是无法表示的)

         hash 显示所有命令缓存

         hash -t cat 查看指定命令的缓存(cat)

         hash -p /usr/bin/touch chuangjian 手动添加缓存,并定义别名

         hash -d 命令名称 hash -d chuangjian 删除指定命令缓存

         hash -r 清空所有命令缓存

[root@a ~]# hash
hits	command
   3	/usr/sbin/groupadd
  10	/usr/bin/sort
   5	/usr/bin/rm
  11	/usr/bin/cat
  13	/usr/bin/vim
   3	/usr/bin/touch
   6	/usr/sbin/useradd
   2	/usr/bin/whereis
   1	/usr/bin/mkdir
   2	/usr/bin/passwd
   5	/usr/bin/cut
  11	/usr/bin/ls
   8	/usr/sbin/usermod

5.通配符

        [] [1apd] [1-9] [^] [!] * ? { } touch file{1..10}

6.引号的特点

        `` ' ' " "

7.帮助使用方式

        内置命令 help cd man cd

        外置命令 passwd --help man passwd

        man 手册第一个章节 所有用户可以执行的命令帮助信息

                 第五章节 配置文件的帮助信息 man 5 passwd

                 第八章节 管理员可以执行的命令帮助信息

三,用户组管理

AAA认证(认证,授权,审计)

用户类别

用户:密码占位符:UID用户id:GID组id:描述信息(注释字段):家目录:shell(可交互shell(可登录)/不可交互shell(不可登录))

zxx : x : 1005 : 1008 : 技术组附加用户 : /home/zxx : /bin/bash

管理员:uid=0

一般用户:

         系统用户: 1-999 禁止用户验证登录

                 系统管理用户 1-200

                 系统普通用户 201-99

         普通用户: 1000-65535 1000-60000 可以验证登录

useradd 用户名

-u指定用户的uid 
-g指定用户的基本组
-d更改用户家目录
-s更改shell
useradd会创造   /etc/passwd    /etc/group    /etc/shadow    /etc/gshadow   /home/USERDIR   /var/spoo/mail/USERFILE

[root@a ~]# useradd nihao
[root@a ~]# userdel nihao
[root@a ~]# useradd nihao
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
[root@a ~]# userdel -r nihao

usermod:用户修改
-u指定用户的uid 
-g指定用户的基本组
-d更改用户家目录
-s更改shell
-l修改用户名
-c设置注释字段
-G更改用户的组信息(组名:密码:组id:组用户)

管理组:gid=0
一般组:
    基本组/默认组:用户默认的组(主要)
    附加组:用户默认组织外的组(次要)

groupadd创建组

-g

groupmod 修改组

-g更改组信息

-n

groupdel 组删除

可以删除所有附加组,组里可以有用户

不能删除主组(基本组)--主组需要通过删除用户来删除(确认主组下面没有其他用户)

Guess you like

Origin blog.csdn.net/qq_44685426/article/details/121503117