zoukankan      html  css  js  c++  java
  • ENGINEER 004:Linux命令字的来源、alias别名设置

    配置用户环境

    1、自定义命令

    1Linux命令字的来源

    如何指定命令字?

    ---指令名:函数>别名>内部命令>外部命令

    ---可执行程序的路径

    什么是别名?

    ---在用户环境中,为一个复杂的、需要经常使用的命令行所起的短名称

    ---可用来替换普通命令,更加方便

    2alias别名设置

    查看已设置的别名

    --- alias [别名名称]

    定义新的别名

    --- alias  别名名称 =‘实际执行的命令行’

    取消已设置的别名

    --- unalias [别名名称]

    永久性别名的设置:在真机上设置

    [root@xiaoredhat~]# vim /root/.bashrc

    当年,有写错的,导致真机启动不了了。

    属于root家目录下,查看别名设置的命令。

    2、用户初始化文件

    1)用户个性化配置文件

    影响指定用户的bash解释环境

    -~/.bashrc,每次开启bash终端时生效    //只针对root有效

    [root@server0~]#vim ~student/.bashrc

    ... ...

    alias ld='ls-lhd --color=auto'   //仅对student用户有效

    [student@server0~]$ alias ld

    alias ld='ls -lhd --color=auto'

    [root@localhost ~]# vim /etc/hostname

    Server0.example.com

    [root@localhost ~]# exit

    [root@localhost ~]# s

    在虚拟机上写入,而非真机。注意啦!

    [root@server0~] # vim /root/.bashrc

    Vim的技巧:

    想把一行复制粘贴,esc(回到命令模式)--->把光标定义在一行,复制yy--->粘贴p

    alias hello =’echo hello’

    [root@server0~] # vim /home/student/.bashrc

    写入:

    alias hi=’echo hi’

    [root@server0~] # vim /etc/bashrc  #shell脚本写的,之后学到会看懂。

    写入:

    alias haha=’echo xixi’    //第一行,挑个空白地方。

    三个都写完了。

    root能够执行的别名有哪几个?

    hello、haha可以。直觉上觉得可以,但是执行的时候,三个都不可以。

    注意:每次都需要开启bash环境,终端时生效。 就是在打开终端。退出原先终端后,再重新打开终端。

    [root@server0~] #  exit

    [root@xiaoredhat ~]# s   //重新远程,再打开终端。

     hello、haha可以,hi不可以。

    [root@server0~]# su -student

    [student@server0~] $ hello   //hello不行。

    [student@server0~] $ hi       //hi可以。

    [student@server0~] $ haha    //haha可以。

    [root@server0~] # vim /root/.bashrc                    hello     影响root文件,指定用户的bash解释环境

    alias hello =’echo hello’

    [root@server0~] # vim /home/student/.bashrc     hi        影响student文件,指定用户的bash解释环境,hi是写到home下的,所以不可以。

    alias hi=’echo hi’

    [root@server0~] # vim /etc/bashrc                        haha     影响全局配置文件,所有用户的bash解释环境

    alias haha=’echo xixi’

    (2)全局环境配置

    影响所有用户的bash解释环境

    - /etc/bashrc,每次开启bash 终端时生效   //影响所有用户的

    [root@server0 ~]# hello   #成功
    hello
    [root@server0 ~]# hi     #失败    
    bash: hi: 未找到命令...
    [root@server0 ~]# haha    #成功
    xixi
    [root@server0 ~]# su - student
    [student@server0 ~]$ hello  #失败 
    bash: hello: command not found...
    [student@server0 ~]$ hi    #成功
    hi
    [student@server0 ~]$ haha   #成功
    xixi

    看一看真机的,etc/bashrc最后几行写了些什么?

    [root@xiaoredhat ~]# vim /etc/bashrc

    echo Taren1 | passwd --stdin root &> /dev/null     //为root设置密码。

    /usr/sbin/hwclock -w

    在每次开机进入系统之前,重置密码Taren1。开机的时候改无数次密码,最终重启还是Taren1.

    教学环境是怎么做到的。密码是统一的。

    [root@xiaoredhat ~]# ls /etc/passwd

    /etc/passwd

    案例2  自定义用户环境   #设置一个别名

    为系统server0和desktop0创建自定义命令

    (1)自定义命令的名称为qstat

    (2)此自定义命令将执行以下操作:

        /bin/ps -Ao pid,tt,user,fname,rsz     //迷惑性,不用管

      (3)此自定义命令对系统中的所有用户都有效    //全局的

    [root@server0 ~]# vim /etc/bashrc

    alias qstat=' /bin/ps -Ao pid,tt,user,fname,rsz'

    不用去思考命令是干什么的。只要把给出的命令原原本本的复制粘贴就好了。

    写到/etc/bashrc文件当中

    ---------------------------------------------------------------------------------------

  • 相关阅读:
    事件
    dom对象
    逻辑运算和作用域的问题
    json
    数组
    字符串
    函数
    js的数据类型和全局方法
    js
    10.16 js内容
  • 原文地址:https://www.cnblogs.com/sneg/p/10901407.html
Copyright © 2011-2022 走看看