如何将 bash 重置为出厂设置 - MacOS Sierra

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45793870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:23:31  来源:igfitidea点击:

How to 'reset' bash to factory settings - MacOS Sierra

bashmacosshell

提问by M. Choy

I'm using MacBook Air 2014 and tried to install a Python library via command line in terminal. I've tried to research this, and performing commands such as "bash exit" seem not to work.

我正在使用 MacBook Air 2014 并尝试通过终端中的命令行安装 Python 库。我试图对此进行研究,并且执行诸如“bash exit”之类的命令似乎不起作用。

MacBook Air: Mac OSX Sierra 10.12.3

MacBook Air:Mac OSX Sierra 10.12.3

This is what I see in Terminal when it opens.

这是我在终端打开时看到的内容。

Last login: Sat Aug 19 14:22:18 on console
-bash: touch: command not found
[Name of Computer]:~ [Username]$

Terminal settings: On startup, open: "new window with profile, 'basic'" Shells open with: 'Default login shell' New windows open with: Default profile, default working directory

终端设置:在启动时,打开:“带有配置文件的新窗口,'基本'”外壳打开方式:'默认登录外壳'新窗口打开方式:默认配置文件,默认工作目录

New tabs open with: same profile, same working directory

新标签打开:相同的配置文件,相同的工作目录

Any help would be much appreciated

任何帮助将非常感激

回答by hmedia1

TLDR;

TLDR;

(Edit: Tested on 10.14 Mojave)

(编辑:在 10.14 Mojave 上测试)

To restore Terminal to a factory state (tested on Mac OS X 10.12.6 Sierra), backing up bash profile, history file, Terminal preferences and savedstate :

要将终端恢复到出厂状态(在 Mac OS X 10.12.6 Sierra 上测试),备份 bash 配置文件、历史文件、终端首选项和保存状态:

#backing up
backupdir="$HOME/Terminal_Backup_Files"
mkdir -p "$backupdir"
defaults export com.apple.Terminal - > "$backupdir"/Terminal_defaults.xml
cp -rf "$HOME/Library/Saved Application State/com.apple.Terminal.savedState" "$backupdir"/
cp "$HOME/Library/Preferences/"com.apple.Terminal.plist* "$backupdir"/
cp -RLafv "$HOME"/.bash* "$backupdir"/

#restoring to factory state
defaults delete com.apple.Terminal
rm "$HOME/Library/Preferences/"com.apple.Terminal.plist*
rm -rf "$HOME/Library/Saved Application State/com.apple.Terminal.savedState/"
rm "$HOME"/.bash*
killall Terminal

To restore it back to how it was

让它恢复原状

backupdir="$HOME/Terminal_Backup_Files"
defaults import com.apple.Terminal - < "$backupdir"/Terminal_defaults.xml
cp -rf "$backupdir"/com.apple.Terminal.savedState "$HOME/Library/Saved Application State"/ 
cp "$backupdir"/com.apple.Terminal.plist* "$HOME/Library/Preferences/"
source "$backupdir"/.bash_profile     #in case backup profile & history was over the default 500 lines
cp -RLafv "$backupdir"/.bash* "$HOME"/
killall Terminal


Explanation;

解释;

bashdoesn't have preferences, but it does follow directives such as profiles, environment variables, and any other sources and flags upon starting a login session. Some of this is influenced by the Terminalapp itself.

bash没有首选项,但它在启动登录会话时确实遵循配置文件、环境变量和任何其他来源和标志等指令。其中一些受到Terminal应用程序本身的影响。

One surefire method that will reset both Terminal and delete the user profile:

一种可以重置终端并删除用户配置文件的万无一失的方法

  1. Delete the Terminal.app defaults
  2. Remove the preference files (and any preference lock files)
  3. Delete .bash*files and folders from the home folder.
  4. Kill existing instances of Terminal
  1. 删除 Terminal.app 默认值
  2. 删除首选项文件(和任何首选项锁定文件)
  3. .bash*从主文件夹中删除文件和文件夹。
  4. 杀死现有的终端实例