shell脚本,alias别名命令用法。

复制代码
[root@localhost ~]# alias
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# alias cp
alias cp='cp -i'
[root@localhost ~]# alias cls='clear'
[root@localhost ~]# 
[root@localhost ~]# alias cls
alias cls='clear'
[root@localhost ~]# alias
alias cls='clear'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[root@localhost ~]# cls     #清屏了
这时增加临时别名,一重启就没有了。
如果要长久有效,需要在配置文件增加一下
如果在 .bashrc文件增加一条,或是在/etc/profile。我下面这种方法是在.bashrc文件下加的。
[root@localhost ~]# cls
bash: cls: 未找到命令...
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# vi  .bashrc 
[root@localhost ~]# cat .bashrc 
#  .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cp='cp -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

echo "hellow"
alias cls='clear'
[root@localhost ~]# 

[root@localhost ~]# alias cls   已经添加到配置文件了,为啥查看出现未找到,是因为没加载文件,加载文件有两种方式,一种是source .bashrc 另一种是 . .bashrc 
-bash: alias: cls: 未找到
[root@localhost ~]# source .bashrc         
hellow
[root@localhost ~]# alias cls
alias cls='clear'
[root@localhost ~]# 
[root@localhost ~]# alias
alias cls='clear'
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 ~]# unalias -a        临时清空所有别名
[root@localhost ~]# alias 
[root@localhost ~]# . .bashrc     一加载或是重启系统,所有别名就又存在了
hellow
[root@localhost ~]# alias
alias cls='clear'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[root@localhost ~]# 

[root@localhost ~]# cat .bashrc 
#  .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cp='cp -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

echo "hellow"
alias cls='clear'
[root@localhost ~]# unalias cls   #unalias cls 删除指定别名为cls='clear'。
[root@localhost ~]# alias cls
-bash: alias: cls: 未找到
[root@localhost ~]# 
复制代码

 

posted on   王月波  阅读(12331)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示