linux修改命令别名的方式

文章目录


一、临时修改

  • 以ls -a命令为例:
bash 复制代码
[root@mysql ~]# alias la='ls -a'
[root@mysql ~]# la
.   1.sh           .bash_logout   .bashrc  .cshrc    .mysql_history  .tcshrc
..  .bash_history  .bash_profile  .cache   .history  .ssh

二、永久修改

bash 复制代码
[root@mysql ~]# echo "alias le='ls -la'" >> /etc/bashrc
[root@mysql ~]# source /etc/bashrc
[root@mysql ~]# le
total 52
dr-xr-x---.  4 root root 4096 Sep 26 11:12 .
dr-xr-xr-x. 20 root root 4096 Sep 23 16:27 ..
-rwxrwxrwx   1 root root  240 Sep 26 11:12 1.sh
-rw-------   1 root root 5072 Sep 26 17:09 .bash_history
-rw-r--r--.  1 root root   18 Oct 29  2019 .bash_logout
-rw-r--r--.  1 root root  176 Oct 29  2019 .bash_profile
-rw-r--r--.  1 root root  176 Oct 29  2019 .bashrc
drwx------   3 root root 4096 May 18  2020 .cache
-rw-r--r--.  1 root root  100 Oct 29  2019 .cshrc
-rw-------   1 root root    0 May 18  2020 .history
-rw-------   1 root root 2113 Sep 23 20:50 .mysql_history
drwx------   2 root root 4096 Sep 23 09:56 .ssh
-rw-r--r--.  1 root root  129 Oct 29  2019 .tcshrc

三、针对特定用户永久修改

bash 复制代码
[root@mysql ~]# useradd -m pt
[root@mysql ~]# su - pt
[pt@mysql ~]$ echo "alias la='ls -la'" >> ~/.bashrc
[pt@mysql ~]$ source ~/.bashrc
[pt@mysql ~]$ la
total 24
drwx------  2 pt   pt   4096 Sep 26 17:04 .
drwxr-xr-x. 3 root root 4096 Sep 26 17:03 ..
-rw-------  1 pt   pt    141 Sep 26 17:07 .bash_history
-rwxr-xr-x. 1 pt   pt     75 Jan 10  2020 .bash_logout
-rwxr-xr-x. 1 pt   pt     71 Mar 19  2020 .bash_profile
-rwxr-xr-x. 1 pt   pt    156 Sep 26 17:06 .bashrc
相关推荐
cui__OaO12 分钟前
Linux驱动--驱动编译
linux·运维·服务器
SunnyRivers35 分钟前
深入理解Linux后台命令
linux·后台运行·重定向·nohub
刘叨叨趣味运维38 分钟前
快速掌握Linux启动过程:像看接力赛一样简单
linux
Q16849645151 小时前
红帽Linux-进程、ssh、网络、软件包、文件系统
linux·运维·网络
ℳ₯㎕ddzོꦿ࿐1 小时前
Docker 环境下 Paperless-ngx 中文增强版部署实战
运维·docker·容器
wdfk_prog1 小时前
[Linux]学习笔记系列 -- [drivers][base]cpu
linux·笔记·学习
zhaoyun9271 小时前
ubuntu linux 安装net8 net9 net 10方法
linux·ubuntu
大母猴啃编程1 小时前
线程同步与互斥
linux
zwtahql2 小时前
ubuntu远程ssh连接
linux·ubuntu·ssh
南烟斋..2 小时前
嵌入式系统(51单片机)核心外设详解:UART通信与DS18B20温度采集
linux·运维·网络