NO6 alias-unalias命令,递归创建目录,如何取消覆盖提示

·如果需要更新补丁则执行:
·yum update
·yum install lrzsz telnet tree nmap nc -y
·alias #查看系统现有的别名。
        一、设置别名eg:alias rm='echo this comand dose not allow to use.'
        二、别名的作用:
            1 通过给危险命令加一些保护参数,防止人为误操作。
            2 把很多复杂的字符串或命令变成一个简单的字符串或命令。
        三、定义别名永久生效:
            /etc/profile 全局生效
            ~/.bashrc   当前用户生效 (eg:只要rm别名还在~/.bashrc文件夹里,通过source ~/.bashrc可以找回来。)
·unalias #取消某一个,已经设置好的别名。

 

 


·问题九:请用一条命令完成创建目录/oldboy/test,即创建/oldboy目录及/oldboy/test目录。
·解答:
mkdir -p /oldboy/test  #递归创建目录,一般第一级目录不存在时使用-p。否则报错。
tree /oldboy/  #查看目录树结果。
[root@localhost ~]# pwd
/root
[root@localhost ~]# mkdir -p /oldboy/test 
[root@localhost ~]# tree /oldboy/
bash: tree: command not found...   (没安装tree软件包,用yum install tree -y安装。)
[root@localhost ~]# cd /oldboy
[root@localhost oldboy]# ls       (其实已经创建好了)
test
[root@localhost oldboy]# tree /oldboy/ 
/oldboy/
└── test

1 directory, 0 files
·其他的方法:mkdir /oldboy /oldboy/test
·如果tree命令不存在,可以使用yum install tree -y安装。

 

·问题十:已知/tmp目录下已经存在了test.txt文件,如何执行命令才能把mnt/test.txt拷贝到/tmp下覆盖掉/tmp/test.txt,而让linux系统不提示是否覆盖(root权限下)?
·解答:
[root@localhost oldboy]# touch /tmp/test.txt
[root@localhost oldboy]# touch /mnt/test.txt
[root@localhost oldboy]# cp /mnt/test.txt /tmp/
cp: overwrite ‘/tmp/test.txt’? y^H^C
要让它不提示:(\ #反斜杠屏蔽别名功能)
方法一:[root@localhost oldboy]# \cp /mnt/test.txt /tmp/
方法二:[root@localhost oldboy]# /bin/cp /mnt/test.txt /tmp/

·简要解释
此题的思路就是屏蔽掉系统默认的对应命令别名,默认执行cp的操作时调用了别名的。所以会提示是否覆盖。
系统为了保护文件,防止误操作,就给一些命令自动加一个参数来起到保护作用:
[root@localhost oldboy]# alias  (alias #别名功能)这就是查看系统当前设定的别名。
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
方法三:取消别名功能,不推荐使用
        提示:命令行处理别名仅在当时生效,重启系统后就失效了。
[root@localhost oldboy]# unalias cp (删除cp这个命令的别名)
[root@localhost oldboy]# alias     (再查)就没有cp那一项了。
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

此时不加/bin或者\,cp命令也不会再提示了:
[root@localhost oldboy]# cp /mnt/test.txt /tmp/
[root@localhost oldboy]# cp /mnt/test.txt /tmp/

 


·unalias #取消某一个,已经设置好的别名。
·alias #查看系统现有的别名。
 、设置别名eg:
  [root@localhost oldboy]#alias rm='echo this comand dose not allow to use.' (设置rm命令不在能使用)
  [root@localhost oldboy]#alias|grep rm
  alias rm='echo this comand dose not allow to use.'
  [root@localhost oldboy]#rm
  this comand dose not allow to use.
  [root@localhost oldboy]#alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
  [root@localhost oldboy]#net (以后敲net就行了,直接出现网卡信息)
  、别名的作用:
  1 通过给危险命令加一些保护参数,防止人为误操作。
  2 把很多复杂的字符串或命令变成一个简单的字符串或命令。、
  三、定义别名永久生效:
  /etc/profile 全局生效
  ~/.bashrc   当前用户生效
  ·只要别名还存在~/.bashrc里,可通过source命令把删除的别名找回来。
  [root@localhost oldboy]# cat ~/.bashrc
        # .bashrc

        # User specific aliases and functions

        alias rm='rm -i'
        alias cp='cp -i'
        alias mv='mv -i'

        # Source global definitions
        if [ -f /etc/bashrc ]; then
                . /etc/bashrc
        fi
        [root@localhost oldboy]# source ~/.bashrc
        [root@localhost oldboy]# alias
        alias cp='cp -i'
        alias egrep='egrep --color=auto'
        alias fgrep='fgrep --color=auto'
        alias grep='grep --color=auto'
        alias l.='ls -d .* --color=auto'
        alias ll='ls -l --color=auto'
        alias ls='ls --color=auto'
        alias mv='mv -i'   (如果前面删除rm命令的别名,只要rm别名还在~/.bashrc文件夹里,通过source ~/.bashrc可以找回来。)
        alias rm='rm -i'
        alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
      
  如何取消alias的命令:


     

 

posted @ 2018-04-24 16:15  Sinsen柳  阅读(272)  评论(0编辑  收藏  举报