1. Mac Os X Bash Commands
  2. Bash On Mac

This version of Bash is included in all versions of macOS, even the newest one. The reason that Apple includes such an old version of Bash in its operating system has to do with licensing. Since version 4.0 (successor of 3.2), Bash uses the GNU General Public License v3 (GPLv3), which Apple does not (want to. Watermelon Blocks is a puzzle game, with switch blocks, enemies and spikes. The game has 46 levels for you to venture out, its difficulty is gradual, but nothing that you cannot solve and have fun in this watermelon game. Bash is the default login shell on Linux and Mac OS, and adding it to your skillset will open up a whole new world of possibilities. For one thing, it gives you access to a huge number of command line utilities, simplifying many everyday tasks. But Bash also provides you with a powerful scripting language for automating just about anything. In bash, use $OSTYPE and $HOSTTYPE, as documented; this is what I do.

Turn on and set up FileVault

FileVault 2 is available in OS X Lion or later. When FileVault is turned on, your Mac always requires that you log in with your account password.

  1. Choose Apple menu () > System Preferences, then click Security & Privacy.
  2. Click the FileVault tab.
  3. Click , then enter an administrator name and password.
  4. Click Turn On FileVault.

If other users have accounts on your Mac, you might see a message that each user must type in their password before they will be able to unlock the disk. For each user, click the Enable User button and enter the user's password. User accounts that you add after turning on FileVault are automatically enabled.

Choose how you want to be able to unlock your disk and reset your password, in case you ever forget your password:

  • If you're using OS X Yosemite or later, you can choose to use your iCloud account to unlock your disk and reset your password.*
  • If you're using OS X Mavericks, you can choose to store a FileVault recovery key with Apple by providing the questions and answers to three security questions. Choose answers that you're sure to remember.*
  • If you don't want to use iCloud FileVault recovery, you can create a local recovery key. Keep the letters and numbers of the key somewhere safe—other than on your encrypted startup disk.

If you lose both your account password and your FileVault recovery key, you won't be able to log in to your Mac or access the data on your startup disk.

Encryption occurs in the background as you use your Mac, and only while your Mac is awake and plugged in to AC power. You can check progress in the FileVault section of Security & Privacy preferences. Any new files that you create are automatically encrypted as they are saved to your startup disk.

When FileVault setup is complete and you restart your Mac, you will use your account password to unlock your disk and allow your Mac to finish starting up. FileVault requires that you log in every time your Mac starts up, and no account is permitted to log in automatically.

Reset your password or change your FileVault recovery key

If you forget your account password or it doesn't work, you might be able to reset your password.

If you want to change the recovery key used to encrypt your startup disk, turn off FileVault in Security & Privacy preferences. You can then turn it on again to generate a new key and disable all older keys.

Turn off FileVault

If you no longer want to encrypt your startup disk, you can turn off FileVault:

  1. Choose Apple menu > System Preferences, then click Security & Privacy.
  2. Click the FileVault tab.
  3. Click , then enter an administrator name and password.
  4. Click Turn Off FileVault.

Decryption occurs in the background as you use your Mac, and only while your Mac is awake and plugged in to AC power. You can check progress in the FileVault section of Security & Privacy preferences.

Learn more

  • Learn how to create and deploy a FileVault recovery key for Mac computers in your company, school, or other institution.
  • If you're using FileVault in Mac OS X Snow Leopard, you can upgrade to FileVault 2 by upgrading to OS X Lion or later. After upgrading OS X, open FileVault preferences and follow the onscreen instructions to upgrade FileVault.
  • RAID partitions or non-standard Boot Camp partitions on the startup drive might prevent OS X from installing a local Recovery System. Without a Recovery System, FileVault won't encrypt your startup drive. Learn more.

* If you store your recovery key with Apple or your iCloud account, there's no guarantee that Apple will be able to give you the key if you lose or forget it. Not all languages and regions are serviced by AppleCare or iCloud, and not all AppleCare-serviced regions offer support in every language. If you set up your Mac for a language that AppleCare doesn't support, then turn on FileVault and store your key with Apple (OS X Mavericks only), your security questions and answers could be in a language that AppleCare doesn't support.

Today’s hint is for those of you who, like me, use Terminal often and occasionally have a need to do things there as the root user. If you don’t know what Terminal is, don’t know what the root user is, or haven’t ever heard of the sudo command, this hint probably isn’t for you.

Bash

In Terminal, you enter root mode with the sudo command; in particular, if you’ve got a lot to do as root, it’s easiest to open a root shell with sudo -s. You then stay in root mode until you type exit, whereupon you revert to your “normal” admin-level powers.

There’s just one problem with this, though—the default root command prompt isn’t nearly scary enough to remind you of the power you’re wielding while in this mode.

When running in root mode, the default prompt of bash-3.2# looks too much like the standard prompt for my tastes—I want something that really reminds me of what I’m doing, to hopefully prevent me from doing something really stupid while operating as root.

If you’d like to change your root prompt, assuming you’re using the default bash shell, here’s how to do it. Using nano or vi or BBEdit or whatever your favorite pure text editor may be, edit the file named .profile in your user’s home directory.

(If this file doesn’t exist, create it. There’s also a slim chance you may have a file named .bash_profile instead; if you do, edit that file and not .profile.)

To set the root prompt, you need to set a variable named SUDO_PS1 in this file. If you’d like to mimic your normal shell prompt—showing your machine name, current directory, and username, you would add this command to the .profile file:

export SUDO_PS1='[h:w] u$ '

Prompt strings are very strange-looking foreign creatures, and so the above probably doesn’t make a lot of sense. In a nutshell, h, w, and u display the machine (host) name, the current directory, and the user name. When using sudo -s, the user name will display as root#, versus the usual robg$ when logged in as a normal user.

Save the file, quit the editor, and open a new Terminal window to see your changes take effect (after running sudo -s, of course).

While the above is a good start, it still doesn’t stand out enough for me.

So I modified the above to make the differences plainly visible, as you can see in the image at right.

Mac Os X Bash Commands

Bash

To create my prompt, I used this entry in my .profile file:

Bash On Mac

export SUDO_PS1='[e[33;1;41m][u] w $[e[0m] '

(Note to true Unix experts: I’m not positive my prompt is perfect; perhaps it could be simplified. However, it works for me, and has done so for many years.) There’s a whole lot going on there, and to explain it all in detail would take well more words and space than I have available here. However, the basic breakdown is as follows:

  • [ – what follows are non-printing characters, so they aren’t counted for line-wrap purposes
  • e[ – the start of an escape sequence, to set the colors
  • 33;1;41m – the actual color string, to create bold yellow text on a red background
  • ] – the end of the non-printing characters
  • [u] w $ – the user name in brackets, followed by the directory and the # symbol
  • [e[0m] – another non-printing sequence; this one sets the colors back to the defaults, so only the prompt is yellow-on-red

You can learn a bit more about prompts by reading the bash manual (type man bash in Terminal). Search (by typing a forward slash, /) for When executing interactively to jump directly to the section on prompting. Even that, though, won’t help explain most of the above. For that, you’ll need some help from Google. In particular, I like this tutorial for its good overview, and this one for its coverage of color usage.

If this hint inspires you to change your default non-sudo prompt, you can do that, too. Add another line to the .profile file which begins export PS1='..., and then build the prompt string as you wish.

If you mess something up and wind up with an unreadable prompt (What? No, that’s never happened to me!), just remove the line from the .profile file, save your changes, and open a new Terminal window. I will caution you, though, that playing with prompt strings can be an amazingly time-consuming diversion…“just one more little change!”