Applying Your Linux Skills to macOS: Terminal BASH and Common Commands

As you now know from my introductory article, macOS is a flavor of UNIX, similar to Linux. But unlike Linux, macOS does not support virtual terminals by default.

A Macbook with the headline Talk Tech to Me: Linux + macOS

This article is part two in a series about using Linux skills when working in a mac operating system. Check out the other articles in the series:

As you now know from my introductory article, macOS is a flavor of UNIX, similar to Linux. But unlike Linux, macOS does not support virtual terminals by default. Instead, you can use the Terminal app (/Applications/Utilities/Terminal) to obtain a command line terminal and BASH shell.

Alternatively, you can type >console as the username at the macOS login prompt (no password needed) to obtain a login prompt that allows you to log directly into a command line terminal and obtain a BASH shell.

After you obtain a BASH shell, you can run many of the same commands you’ve become accustomed to on Linux. It’s also important to note that the same syntax rules that you used on Linux apply to BASH on macOS:

NOTE: If you wish to perform system administration as the root user, you must first enable the root user using the Directory Utility app (in /System/Library/CoreServices/Applications). Once you open this app, simply select Change Root Password from the Edit menu.

Common macOS Commands

Below are some common macOS commands, organized by general function. Bookmark this page so you can refer back to it often. Although most options to these commands are identical between Linux and macOS, be sure to view the manual page for commands that you will use in the future.

System Documentation Commands in macOS

File Management Commands in macOS

Text Tools in macOS

Filesystem Administration in macOS

Disk quotas are configured differently in macOS. In Linux, you enable quotas using the appropriate option in /etc/fstab. However, /etc/fstab is not available in macOS. Instead, you must create two files in the root of the filesystem that you wish to enable quotas on (.quota.ops.user and .quota.ops.group).

Shutdown and System State in macOS

Compression, Backup and Software in macOS

BASH Management in macOS

As in Linux, macOS stores its variables in environment files. The /etc/profile and /etc/bashrc files are used by default on the system. Each user can also create their own ~/.bash_profile and ~/.bashrc files. In addition, ~/.bash_logout may be used to perform tasks at shell exit. Here are more BASH management commands for macOS.

Process Management in macOS

User and Group Administration in macOS

User and group administration differs slightly in macOS from Linux. There are no useradd or userdel commands. Instead, you must use the System Preferences utility to create user accounts properly. User information is stored in a directory database under the /var/db directory. The /etc/shadow file does not exist and the /etc/passwd and /etc/group files exist only to provide information to apps.

Common Unix Printing System (CUPS) Printing in macOS

Network- and Security-related Commands in macOS

Network devices have different names in macOS. The first ethernet adapter is called en0 (typically wired ethernet), and the second is called en1 (typically wireless ethernet). Ensure that you use System Preferences to change any network parameters, as they are not stored in text files as they are on Linux systems. For example, the /etc/resolv.conf file still exists in macOS and lists DNS servers configured in System Preferences, but it is not used by the system – it is merely there in case an app queries it. The only network-related file that is used actively and may be edited is /etc/hosts (for local host name resolution). Here are more network- and security-related commands in macOS.

System and Miscellaneous Commands in macOS

Now you’ve got the macOS basics down, and you know the common commands. In the next installment, I’ll be discussing apps. Stay tuned!

Round out your IT skill set with CompTIA Linux+.