How to use the alias named ll in Centos 7

How to use the alias named ll in Centos 7

Overview

  我们知道在Centos7中,ll这个命令是命令‘ls -l --color=auto’的别名,很多玩过Ubuntu的人应该知道,在Ubuntu中,ll代表'ls -la --color=auto',那么我们有没有办法将Centos7中的ll也改成与Ubuntu一样的呢,答案肯定是可以的。接下来,我们就来完成以下工作。

  首先,我们来看看Centos7中alias都有哪些:

[root@node00 ~]# alias
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@node00 ~]# 

我们可以看到,有很多别名,其中也包括了ll别名。

  接下来,我们来查找一下,ll这个别名定义在了什么地方。考虑到Linux中的配置文件都是放在/etc/目录下的,我们将会在目录/etc及其子目录下寻找。查找条件是什么呢,我们知道alias定义的时候,肯定是会包含关键字aliasll的,这样以来,我们就可以借助如下的命名查找定义:

[root@node00 ~]# grep -rn 'alias' /etc/ |grep ll
/etc/postfix/main.cf:648:# newaliases_path: The full pathname of the Postfix newaliases command.
/etc/postfix/virtual:26:#        o      To   implement  virtual  alias  domains  where  all
/etc/postfix/virtual:41:#        Normally, the virtual(5) alias table  is  specified  as  a
/etc/postfix/virtual:147:#        alias domain,  all  recipient  addresses  are  aliased  to
/etc/modprobe.d/dccp-blacklist.conf:2:# from automatically loading related modules using their aliases
/etc/profile.d/colorls.csh:13:alias ll 'ls -l'
/etc/profile.d/colorls.csh:66:alias ll 'ls -l --color=auto'
/etc/profile.d/vim.sh:6:  alias vi >/dev/null 2>&1 || alias vi=vim
/etc/profile.d/colorgrep.sh:5:alias grep='grep --color=auto' 2>/dev/null
/etc/profile.d/colorgrep.sh:6:alias egrep='egrep --color=auto' 2>/dev/null
/etc/profile.d/colorgrep.sh:7:alias fgrep='fgrep --color=auto' 2>/dev/null
/etc/profile.d/colorls.sh:9:  alias ll='ls -l' 2>/dev/null
/etc/profile.d/colorls.sh:10:  alias l.='ls -d .*' 2>/dev/null
/etc/profile.d/colorls.sh:55:alias ll='ls -l --color=auto' 2>/dev/null
/etc/profile.d/colorls.sh:56:alias l.='ls -d .* --color=auto' 2>/dev/null
/etc/profile.d/colorls.sh:57:alias ls='ls --color=auto' 2>/dev/null
/etc/bash_completion.d/docker.sh:4553:			COMPREPLY=( $( compgen -W "--alias --disable --disable-content-trust=false --grant-all-permissions --help" -- "$cur" ) )
/etc/sysconfig/network-scripts/network-functions:338:            cmd = install[alias];
/etc/sysconfig/network-scripts/ifup-aliases:10:# addrs will be updated on existing aliases, and new aliases will be setup.
[root@node00 ~]# 

  到此,我们已经找到了别名ll定义的位置在文件/etc/profile.d/colorls.sh第9行。我们来查看一下该文件的内容:

[root@node00 profile.d]# cat colorls.sh 
# color-ls initialization

# Skip all for noninteractive shells.
[ ! -t 0 ] && return

#when USER_LS_COLORS defined do not override user LS_COLORS, but use them.
if [ -z "$USER_LS_COLORS" ]; then

  alias ll='ls -l' 2>/dev/null
  alias l.='ls -d .*' 2>/dev/null

  INCLUDE=
  COLORS=

  for colors in "$HOME/.dir_colors.$TERM" "$HOME/.dircolors.$TERM" \
      "$HOME/.dir_colors" "$HOME/.dircolors"; do
    [ -e "$colors" ] && COLORS="$colors" && \
    INCLUDE="`/usr/bin/cat "$COLORS" | /usr/bin/grep '^INCLUDE' | /usr/bin/cut -d ' ' -f2-`" && \
    break
  done

  [ -z "$COLORS" ] && [ -e "/etc/DIR_COLORS.$TERM" ] && \
  COLORS="/etc/DIR_COLORS.$TERM"

  [ -z "$COLORS" ] && [ -e "/etc/DIR_COLORS.256color" ] && \
  [ "x`/usr/bin/tty -s && /usr/bin/tput colors 2>/dev/null`" = "x256" ] && \
  COLORS="/etc/DIR_COLORS.256color"

  [ -z "$COLORS" ] && [ -e "/etc/DIR_COLORS" ] && \
  COLORS="/etc/DIR_COLORS"

  # Existence of $COLORS already checked above.
  [ -n "$COLORS" ] || return

  if [ -e "$INCLUDE" ];
  then
    TMP="`/usr/bin/mktemp .colorlsXXX -q --tmpdir=/tmp`"
    [ -z "$TMP" ] && return

    /usr/bin/cat "$INCLUDE" >> $TMP
    /usr/bin/grep -v '^INCLUDE' "$COLORS" >> $TMP

    eval "`/usr/bin/dircolors --sh $TMP 2>/dev/null`"
    /usr/bin/rm -f $TMP
  else
    eval "`/usr/bin/dircolors --sh $COLORS 2>/dev/null`"
  fi

  [ -z "$LS_COLORS" ] && return
  /usr/bin/grep -qi "^COLOR.*none" $COLORS >/dev/null 2>/dev/null && return
fi

unset TMP COLORS INCLUDE

alias ll='ls -l --color=auto' 2>/dev/null
alias l.='ls -d .* --color=auto' 2>/dev/null
alias ls='ls --color=auto' 2>/dev/null
[root@node00 profile.d]# 

  这个时候,我们只需要修改该文件即可。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qwfys200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值