3

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

arco444
  • 22,002
  • 12
  • 63
  • 67
flying_loaf_3
  • 397
  • 2
  • 3
  • 12
  • What do you want it to look like. – Lohit Gupta Aug 21 '17 at 09:53
  • The default settings that come with Mac OS? – flying_loaf_3 Aug 21 '17 at 09:57
  • I would suggest you copy the contents of `.bashrc` and `.bash_profile` files in `$HOME` directory from another Mac OS and paste onto your system files respectively. This will reset the terminal after restart. – Lohit Gupta Aug 21 '17 at 10:08
  • I'm quite new to this stuff, so how would I access the folder containing these files? – flying_loaf_3 Oct 04 '17 at 02:37
  • Would factory resetting the Mac do anything? – flying_loaf_3 Oct 09 '17 at 02:39
  • Make sure to take a backup of your installed software and data, as after factory resetting you would lose those. – Lohit Gupta Oct 09 '17 at 06:25
  • So what you're saying is that it WOULD work? – flying_loaf_3 Oct 19 '17 at 02:55
  • Yes but you would lose all installed software and data after factory reset. Or you can just copy the above files I mentioned from a different system and replace yours with those. These files are located in the default directory you start your terminal. To see them you can check via `ls -al` as these are hidden by default. – Lohit Gupta Oct 20 '17 at 07:07
  • This belongs on [apple.se], [SuperUser](https://superuser.com/), or [unix.se], as it's neither a question about writing code or about tools exclusively used for that purpose. – Charles Duffy Jan 04 '19 at 05:20

1 Answers1

9

TLDR;

(Edit: Tested on 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 :

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

bash doesn'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 Terminal app itself.

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
Community
  • 1
  • 1
hmedia1
  • 5,552
  • 2
  • 22
  • 27
  • Thanks for the reply. Is there a way that I can copy these files so that I have a backup of them? – flying_loaf_3 Aug 21 '17 at 10:26
  • @M.Choy Yes, I have edited and added these instructions. – hmedia1 Aug 21 '17 at 12:23
  • I just realised that I can't use terminal, which is the fundamental problem (because the bash profile being used in Terminal is messed up). [Is that the right way of saying it?] – flying_loaf_3 Oct 04 '17 at 02:38
  • @M.Choy if you're getting `[Name of Computer]:~ [Username]$` as your prompt, you should still be able to execute: `mv ~/.bash_profile ~/.bash_profile_backup` and then quit `Terminal` and enter it again – hmedia1 Oct 05 '17 at 02:36
  • I am unable to execute that line of code. In the terminal window, I get: '[Name of Computer]:~ [Username]$ ' and when I type 'mv ~/.bash_profile ~/.bask_profile_backup' , I get the error '-bash: mv: command not found' – flying_loaf_3 Oct 08 '17 at 01:48
  • @M.Choy FYI for the sake of completeness - don't use the single `'` quotes around the command line, the command is `mv` *not* 'mv ~/.bash_profile ~/.bash_profile_backup' – hmedia1 Jan 04 '19 at 04:03
  • IMO, you should back up the .bash* files either. – Windsooon May 20 '19 at 02:34