首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

【Linux】一步一步学Linux——alias命令(205)

  • 23-11-18 13:21
  • 4229
  • 14159
blog.csdn.net

00. 目录

文章目录

    • 00. 目录
    • 01. 命令概述
    • 02. 命令格式
    • 03. 常用选项
    • 04. 参考示例
    • 05. 总结
    • 06. 附录

01. 命令概述

alias命令用来设置指令的别名。我们可以使用该命令可以将一些较长的命令进行简化。使用alias时,用户必须使用单引号 ‘ ‘ 将原来的命令引起来,防止特殊字符导致错误。

alias命令的作用只局限于该次登入的操作。若要每次登入都能够使用这些命令别名,则可将相应的alias命令存放到bash的初始化文件 /etc/bashrc中。

02. 命令格式

用法:alias [-p] [名称[=值] ... ]
  • 1

03. 常用选项

-p	以可重用的格式打印所有的已定义的别名
  • 1

04. 参考示例

4.1 查看命令别名

[deng@localhost ~]$ alias 
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 vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

4.2 打印所有的已定义的别名

[deng@localhost ~]$ alias  -p
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 vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

4.3 设置命令别名

[deng@localhost ~]$ alias lx='ls -lh'
[deng@localhost ~]$ lx
总用量 55M
drwxrwxr-x   7 deng deng   61 1月  22 2019 bak
drwxrwxr-x   8 deng deng   73 3月  28 11:14 bj34
drwxr-xr-x   4 deng deng 4.0K 8月  16 11:10 instantclient_11_2
-rwxrwxr-x   1 deng deng  55M 1月  22 2019 oracle_client_11gR2.tar.gz
drwxrwxr-x   3 deng deng   18 1月  22 2019 oradiag_deng
drwxrwxr-x  10 deng deng  163 9月   1 16:05 projects
-rwxrwxr-x   1 deng deng 2.1K 6月  30 15:14 scott_data.sql
drwxrwxr-x   6 deng deng   50 9月   1 09:38 share
drwxrwxr-x   8 deng deng   73 3月  10 09:16 sz12
-rwxrwxr-x   1 deng deng  599 8月  27 09:56 test.c
-rwxrwxr-x   1 deng deng 1.7K 8月   3 15:05 test.cpp
-rwxrwxr-x   1 deng deng  199 9月   1 19:50 test.sh
-rw-rw-r--   1 deng deng   13 9月   1 19:22 txt
drwxr-xr-x.  2 deng deng    6 11月  8 2018 公共
drwxr-xr-x.  2 deng deng    6 11月  8 2018 模板
drwxr-xr-x.  2 deng deng    6 11月  8 2018 视频
drwxr-xr-x.  2 deng deng    6 11月  8 2018 图片
drwxr-xr-x.  2 deng deng    6 11月  8 2018 文档
drwxr-xr-x.  2 deng deng    6 11月  8 2018 下载
drwxr-xr-x.  2 deng deng    6 11月  8 2018 音乐
drwxr-xr-x.  2 deng deng    6 7月  25 22:10 桌面
[deng@localhost ~]$ 
  • 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

注意:命令中选项必须使用引号

4.4 设置命令别名

[deng@localhost ~]$ alias lxx=ls
[deng@localhost ~]$ lxx
bak                         oradiag_deng    sz12      txt   图片  桌面
bj34                        projects        test.c    公共  文档
instantclient_11_2          scott_data.sql  test.cpp  模板  下载
oracle_client_11gR2.tar.gz  share           test.sh   视频  音乐
[deng@localhost ~]$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

05. 总结

在这里插入图片描述

06. 附录

参考:【Linux】一步一步学Linux系列教程汇总

注:本文转载自blog.csdn.net的沧海一笑-dj的文章"https://blog.csdn.net/dengjin20104042056/article/details/100187796"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top