专业的编程技术博客社区

网站首页 > 博客文章 正文

shell——别名alias——2(shell命名规则)

baijin 2024-10-18 04:04:26 博客文章 7 ℃ 0 评论

永久化别名:

直接在linux命令窗口或shell里设定的命令别名,在终端关闭或者系统重新启动后都会失效。

若要每次登入都能够使用这些命令别名,则可将相应的alias命令存放到bash的初始化文件/etc/bashrc(对所有用户有效)或~/.bashrc 文件(只对当前用户有效)中。

[hadoop1@localhost ~]$ ll /etc/bashrc#用root用户
-rw-r--r-- 1 root root 2886 Sep 18 20:56 /etc/bashrc
[hadoop1@localhost ~]$ cat /etc/bashrc |grep 'alias'
# System wide functions and aliases
alias dt1='date +"%Y-%m-%d %T"'

存放完毕后重新载入初始化文件:

source ~/.bashrc

#不同用户,hadoop1,hadoop

[hadoop1@localhost ~]$ dt1
2022-09-18 21:01:35
[hadoop@localhost ~]$ dt1
2022-09-18 21:01:53

#当前用户可用

[hadoop@localhost ~]$ cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
alias cls='clear'
alias dt='date +"%Y-%m-%d %T"'
[hadoop@localhost ~]$ pwd
/home/hadoop

2022-9-20

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表