/etc/bash.bashrc でシステムエイリアスを調べる
~/.bashrc
のようなユーザー固有の設定ファイルに加えて、システム上のすべてのユーザーに適用されるシステム全体の設定ファイルもあります。Bash の場合、そのようなファイルの 1 つが /etc/bash.bashrc
です。
このファイルには、システム管理者がすべてのユーザーに利用可能にしたいデフォルト設定やエイリアスが含まれていることが多いです。
このファイルは /etc
ディレクトリにあり、このディレクトリは通常、システム設定用に予約されているため、変更するには管理者権限が必要になる場合があります。ただし、特別な権限なしで cat
を使用してその内容を表示することができます。
/etc/bash.bashrc
ファイルの内容を表示してみましょう。次のコマンドを入力して Enter キーを押します。
cat /etc/bash.bashrc
システム全体の Bash 設定ファイルの内容が表示されます。エイリアスを定義する行を探してください。
## System-wide .bashrc file for interactive bash(1) shells.
## To enable the setting of the locale environment variables see
## /etc/profile.d/locale.sh. By default in Ubuntu OnLine,
## this is done from /etc/profile.
## If not running interactively, don't do anything
[ -z "$PS1" ] && return
## check the window size after each command and, if necessary,
## update the values of LINES and COLUMNS.
shopt -s checkwinsize
## If set, the pattern "**" used in a pathname expansion context should
## match only directories and subdirectories in addition to the contents of
## the current directory.
#shopt -s globstar
## make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
## set variable identifying the chroot you work in (used in the prompt)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
## enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
## colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=(01;34):quote=01;32'
## some more ls aliases
#alias ll='ls -l' #alias ll='ls -alF'
#alias la='ls -a' #alias la='ls -AF'
#alias l='ls -CF'
## Add an alias for the 'alert' command
#alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\\s*[0-9]*\\s*//;s/[;&|]\\s*alert$//'\'')"'
## enable programmable completion features (you don't need to enable
## this, if it's already enabled in /etc/bash.bashrc and /etc/profile
## sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
alias
コマンドで見たのと同じエイリアスの一部、たとえば色付き表示をサポートする ls
エイリアスが表示されるはずです。これは、使用するデフォルトのエイリアスの一部がシステム全体で設定されていることを確認するものです。
エイリアスがどこで定義されているかを理解することは、予期しない動作のトラブルシューティングや環境の効果的なカスタマイズに役立ちます。
これで、アクティブなエイリアスを一覧表示し、それらが保存されている一般的な設定ファイルを調べる方法を学びました。
続ける をクリックしてこの実験を完了します。