方法1
-
现将文件夹移动到对应用户的
~
目录下(或其他目录)bashmv /home/asushiro/miniconda3 /root/miniconda3
-
建立软链接
然后创建软链接,相当于快捷方式bashln -s /root/miniconda3 /home/aushiro/miniconda3
方法2
将对应miniconda中的文件路径全部改掉
这里使用python脚本实现
主要需要改的地方是/.../miniconda3/bin/*
以及/.../miniconda3/etc/profile.d/*
中的全部文件
-
先修改
~/.bashrc
bashvim ~/.bashrc
添加上
bash# >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/root/miniconda3/etc/profile.d/conda.sh" ]; then . "/root/miniconda3/etc/profile.d/conda.sh" else export PATH="/root/miniconda3/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<<
-
首先改
bin
目录里的
将需要改的文件名输入到target.txt文件夹里shellecho `ls` > ~/target.txt
然后再
~
文件夹下创建modify.py
内容为pythonimport os from tqdm import tqdm with open("./target.txt", 'r') as f: line = f.readline() file_name_total = list(map(str, line.split())) for file_name in tqdm(file_name_total): file_path = os.path.join("/root/miniconda3/bin/", file_name) try: with open(file_path, 'r', encoding="utf-8") as f: content = f.read() content = content.replace("/home/asushiro", "/root") with open(file_path, 'w', encoding="utf-8") as f: f.write(content) except UnicodeDecodeError: print("decode error") continue
-
同理然后进入
etc/profile.d
文件夹下shellecho `ls` >~/target.txt
运行
modify.py
pythonimport os from tqdm import tqdm with open("./target.txt", 'r') as f: line = f.readline() file_name_total = list(map(str, line.split())) for file_name in tqdm(file_name_total): file_path = os.path.join("/root/miniconda3/etc/profile.d/", file_name) try: with open(file_path, 'r', encoding="utf-8") as f: content = f.read() content = content.replace("/home/asushiro", "/root") with open(file_path, 'w', encoding="utf-8") as f: f.write(content) except UnicodeDecodeError: print("decode error") continue
-
最后刷新环境变量即可
shellsource ~/.bashrc