2020年1月5日星期日

Server config file ./bashrc: reset and restore

When using a server, there may be unexpected situations such as the configuration file /.bashrc being suddenly emptied. This article documents the recovery steps for /.bashrc.




1. Reset / .bashrc

The default .bashrc of the server is usually in the /etc/skel directory, so the empty ./bashrc file can be reset by the following statement:

cp /etc/skel/.bashrc ~/

NOTE:
If you use windows to copy through mount and other methods, an error may occur:

-bash: /home/XXX/.bashrc: line 1: syntax error near unexpected token `$'in\r''
'bash: /home/XXX/.bashrc: line 1: `case $- in
So it is recommended to copy directly through the above command.

The following are some personalized configurations, such as adding MATLAB, anaconda, etc. to the path.

2. Add anaconda initialization command

# added by Anaconda2 4.4.0 installer
export PATH="/home/XXX/anaconda3/bin:$PATH"

if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/home/XXX/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/XXX/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/home/XXX/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

3. Add custom shortcuts


For example:

# Shortcut for Anaconda Environment
sra(){
    CONDA_ROOT="-/anaconda3"
    env=$1
    source activate $env
    export LD_LIBRARY_PATH="$CONDA_ROOT/envs/$env/lib:$LD_LIBRARY_PATH"
}
alias srd='source deactivate'
# <<< conda shortcut <<<<<<<

没有评论:

发表评论