当前位置: 代码迷 >> 综合 >> How to use the alias named ll in Centos 7
  详细解决方案

How to use the alias named ll in Centos 7

热度:86   发布时间:2023-12-15 00:06:23.0

How to use the alias named ll in Centos 7

  • Overview

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" ]; thenalias ll='ls -l' 2>/dev/nullalias l.='ls -d .*' 2>/dev/nullINCLUDE=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-`" && \breakdone[ -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" ] || returnif [ -e "$INCLUDE" ];thenTMP="`/usr/bin/mktemp .colorlsXXX -q --tmpdir=/tmp`"[ -z "$TMP" ] && return/usr/bin/cat "$INCLUDE" >> $TMP/usr/bin/grep -v '^INCLUDE' "$COLORS" >> $TMPeval "`/usr/bin/dircolors --sh $TMP 2>/dev/null`"/usr/bin/rm -f $TMPelseeval "`/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
fiunset TMP COLORS INCLUDEalias 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]# 

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

  相关解决方案