服务器./bashrc 的重置和恢复

在使用服务器的时候,可能会出现配置文件/.bashrc突然清空等意外情况。本文记录了/.bashrc的恢复步骤。

参考链接:https://www.computationalimaging.cn/2020/01/server-config-file-bashrc-reset-and.html

1. 重置/.bashrc

服务器默认的.bashrc一般在/etc/skel目录下,因此通过以下语句即可重置清空的./bashrc文件

cp /etc/skel/.bashrc ~/

注意

若通过挂载等方式利用windows复制则可能会出现错误:

-bash: /home/XXX/.bashrc: line 1: syntax error near unexpected token `$'in\r''
'bash: /home/XXX/.bashrc: line 1: `case $- in

故建议通过上述命令直接复制。

下面的步骤因人而异。

2. 添加anaconda的初始化命令

# added by Anaconda2 4.4.0 installer
export PATH="/home/XXX/anaconda3/bin:$PATH"
# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/home/XXX/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
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. 添加自定义快捷指令

如:

# 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 <<<<<<<

 

你可能感兴趣的:(#,Deep,Learning,#,Code,服务器)