Linux - alias

alias 用于设置命令别名

// 错误实例
shuai@ubuntu:~$ alias myls = "ls -l" // 不能有空格
bash: alias: myls: not found
bash: alias: =: not found
bash: alias: ls -l: not found

shuai@ubuntu:~$ alias myls="ls -l" // 正确创建别名

shuai@ubuntu:~$ alias // 显示系统所有别名
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias myls='ls -l' // 可以看到自己的别名已经加进来了

shuai@ubuntu:~$ myls // 调用自己的别名指令
total 60
-rw-r--r-- 1 shuai shuai   33 Apr 26 22:20 a.txt
-rw-r--r-- 1 shuai shuai   38 Apr 26 21:17 b.txt
-rw-r--r-- 1 shuai shuai   11 Apr 26 21:13 c.txt
drwxr-xr-x 2 shuai shuai 4096 Apr 26 15:27 Desktop
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Documents
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Downloads
-rw-r--r-- 1 shuai shuai 8980 Apr 19 17:37 examples.desktop
-rw-r--r-- 1 shuai shuai   26 Apr 26 21:48 manage.py
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Music
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Pictures
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Public
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Templates
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Videos

shuai@ubuntu:~$ ls -l // 别名指令对应的指令
total 60
-rw-r--r-- 1 shuai shuai   33 Apr 26 22:20 a.txt
-rw-r--r-- 1 shuai shuai   38 Apr 26 21:17 b.txt
-rw-r--r-- 1 shuai shuai   11 Apr 26 21:13 c.txt
drwxr-xr-x 2 shuai shuai 4096 Apr 26 15:27 Desktop
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Documents
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Downloads
-rw-r--r-- 1 shuai shuai 8980 Apr 19 17:37 examples.desktop
-rw-r--r-- 1 shuai shuai   26 Apr 26 21:48 manage.py
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Music
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Pictures
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Public
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Templates
drwxr-xr-x 2 shuai shuai 4096 Apr 19 18:03 Videos

shuai@ubuntu:~$ unalias myls // 删除别名
shuai@ubuntu:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 相信有不少朋友有不错的Linux基础,肯定比我这个半桶水强很多,我就不献丑一些最基础的基本操作了。但是,你碰到过以...
    CoderMageFox阅读 3,751评论 0 4
  • Linux用户经常会使用到Shell,也经常会和控制台打交道。但是这种CLI界面很难被已经习惯使用MS Wind...
    Brise阅读 10,620评论 0 1
  • Linux用户经常会使用到Shell,也经常会和控制台打交道。但是这种CLI界面很难被已经习惯使用MS Windo...
    静等凌风阅读 3,222评论 0 0
  • “陪练”……这个字眼令霍亦泽相当的愤怒,先是当了她一把报复尹雨琪的工具,现在又成了她的陪练,该死的女人,她以为她是...
    MissGirls组合Anne阅读 2,507评论 0 5
  • 在日常前端开发中,渐变应该是小伙伴常用的属性之一了。但是,你真的把渐变用透了吗?渐变除了可以用于颜色过渡之外,还有...
    小菜燕阅读 4,206评论 7 12

友情链接更多精彩内容