RedHatサーバーでエイリアスを設定するには?

RedHatサーバーでエイリアスを設定するには?

私は通常のユーザー(Sudoではなく)であるサーバーを使用しています。

経由でサーバーにアクセスしますssh

以下は、サーバー上で実行されるいくつかのコマンドの出力です。

[username@machinename: ~]$ ps -p $$
    PID TTY          TIME CMD
1332818 pts/55   00:00:00 bash
[username@machinename: ~]$ echo $$SHELL
1332818SHELL
[username@machinename: ~]$ echo $-
himBHs
[username@machinename: ~]$ uname
Linux
[username@machinename: ~]$ uname -v
#1 SMP Thu May 11 07:38:47 EDT 2023
[username@machinename: ~]$ uname -r
4.18.0-372.57.1.el8_6.x86_64
[username@machinename: ~]$ cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.6 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.6 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/8/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.6
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.6"

ユーザー名とコンピュータ名は隠されています。

オペレーティングシステム情報は次のとおりです。

LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: RedHatEnterprise
Description:    Red Hat Enterprise Linux release 8.6 (Ootpa)
Release:    8.6
Codename:   Ootpa

通常、Ubuntu/Linux にエイリアスを追加するには、 ~/.bashrc ファイルを編集します。ただし、このファイルは最初にシステムに入ったときに終了しなかったため、ホームディレクトリに直接作成してエイリアスを入力しました。

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# 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

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/tien/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/tien/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/tien/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/tien/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

export PATH="/usr/local/cuda-12.1/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-12.1/lib64:$LD_LIBRARY_PATH"

alias c='clear'
alias gpu='watch -n 0.5 nvidia-smi'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias h='history'
alias j='jobs -l'
alias gst='git status'

ただし、ログアウトして再度ログインすると、エイリアスは機能しません。

それでは、これをどのようにデバッグしますか?

私に関する情報は次のとおりです。

[username@machinename: ~]$ which alias
/usr/bin/alias
[username@machinename: ~]$ alias
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 vi='vim'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'

ベストアンサー1

~/.profileに含めました。

# if running bash
# include .bashrc if it exists
[ -n "$BASH_VERSION" ] && [ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc"

おすすめ記事