# macOS and Linux Basics for A+

> Chapter 6 of the Courseiva A-PLUS-CORE-2 curriculum — https://courseiva.com/learn/a-plus-core-2/macos-linux-basics

**Official objective:** 1.6 — Operating Systems

## Introduction

CompTIA A+ Core 2 (220-1102) Objective 1.6 focuses on macOS and Linux basics. You will learn the fundamental differences between these two Unix-like operating systems, their filesystem structures, common command-line tools, and troubleshooting techniques. Approximately 10-15% of the Operating Systems domain questions touch on macOS or Linux, making this a moderate but critical topic. Mastery here ensures you can support both platforms in a mixed environment.

## macOS and Linux: Two Kitchens, One Chef

A professional kitchen offers a practical analogy for an operating system. Windows is a fast-food chain: everything is standardized, you press a button and get a predictable result, but customization is limited. macOS is a high-end restaurant kitchen: it looks beautiful, the tools are intuitive, and the workflow is smooth, but you can't change the layout of the stoves. Linux is a modular kitchen in a food truck: you start with an empty shell, pick your own stove, fridge, and countertop (desktop environment), and you can rearrange everything. The 'chef' (user) in both macOS and Linux can access the command line (Terminal) to issue precise instructions. In macOS, the Terminal uses a Unix foundation (Darwin) similar to Linux, so many commands work identically. However, macOS has a graphical 'Finder' that hides the filesystem complexity, while Linux often expects you to know the command line. Both systems use case-sensitive filesystems (by default on Linux, optional on macOS), and both treat everything as a file—including hardware devices. The CompTIA A+ exam expects you to navigate both kitchens: know the common commands, understand the filesystem hierarchy, and be able to perform basic troubleshooting without relying on a GUI.

## Core explanation

### Introduction to macOS and Linux

macOS and Linux share a common Unix heritage. macOS is built on Darwin, an open-source Unix-like operating system derived from NeXTSTEP. Linux is a Unix-like kernel created by Linus Torvalds, combined with GNU utilities. Both are POSIX-compliant, meaning they support a standard set of commands and system calls. The CompTIA A+ 220-1102 exam expects you to know basic navigation, file management, and troubleshooting commands for both.

### Filesystem Hierarchy

Both systems use a hierarchical filesystem starting at the root directory `/`. Key directories include:

- `/bin` – Essential user command binaries (e.g., `ls`, `cp`)
- `/sbin` – System binaries for administration (e.g., `fdisk`, `ifconfig`)
- `/etc` – Configuration files
- `/var` – Variable data like logs (`/var/log`)
- `/tmp` – Temporary files
- `/home` – User home directories (Linux)
- `/Users` – User home directories (macOS)
- `/Applications` – Installed applications (macOS)
- `/Volumes` – Mounted drives (macOS)

macOS also has `/System` and `/Library` for system frameworks. The exam may ask about these paths.

### Command Line Basics

Both macOS and Linux use a terminal emulator. The default shell on macOS is Zsh (since Catalina), while Linux often uses Bash. Common commands:

- `ls` – List directory contents. Options: `-l` (long format), `-a` (all files including hidden), `-h` (human-readable sizes).
- `cd` – Change directory.
- `pwd` – Print working directory.
- `cp` – Copy files. Syntax: `cp source destination`. Use `-r` for directories.
- `mv` – Move or rename.
- `rm` – Remove files. Use `-r` for directories, `-f` to force. Be careful: no recycle bin.
- `mkdir` – Create directory.
- `rmdir` – Remove empty directory.
- `cat` – Concatenate and display file content.
- `less` – View file content page by page.
- `grep` – Search text using patterns. Example: `grep 'error' /var/log/system.log`
- `chmod` – Change file permissions. Permissions: read (4), write (2), execute (1). Example: `chmod 755 script.sh`
- `chown` – Change file owner. Example: `chown user:group file`
- `ps` – List processes. `ps aux` shows all processes.
- `kill` – Terminate process by PID. `kill -9 PID` forces kill.
- `top` – Display real-time processes (Linux). `htop` is enhanced but not default.
- `dmesg` – Print kernel ring buffer messages (useful for hardware issues).
- `ifconfig` – Configure network interfaces (older). `ip addr` on modern Linux.
- `ping` – Test network connectivity.
- `traceroute` – Trace route to host (Linux). macOS uses `traceroute` as well.
- `nslookup` – Query DNS (deprecated, but still tested). `dig` is modern.
- `sudo` – Execute command as superuser. Example: `sudo apt update`

### macOS-Specific Commands

- `defaults write` – Modify user defaults (plist files). Example: `defaults write com.apple.finder AppleShowAllFiles YES`
- `diskutil` – Manage disks. Example: `diskutil list`
- `dscacheutil` – Directory service cache utility. `dscacheutil -flushcache` flushes DNS cache.
- `system_profiler` – Display system hardware/software information.
- `pmset` – Power management settings. `pmset -g` shows current settings.
- `spctl` – Security policy (Gatekeeper). `spctl --master-disable` disables Gatekeeper.
- `csrutil` – System Integrity Protection (SIP) status. `csrutil status`

### Linux-Specific Commands

- `apt-get` or `apt` – Package management on Debian/Ubuntu. `apt update && apt upgrade`
- `yum` – Package management on RHEL/CentOS (older). `dnf` is modern.
- `systemctl` – Control systemd services. `systemctl start service`, `systemctl enable service`
- `journalctl` – View systemd logs. `journalctl -u service`
- `ip` – Modern network configuration. `ip addr`, `ip route`
- `nmtui` – Network Manager text user interface.
- `fdisk` – Partition table manipulator.
- `mount` – Mount filesystems. `mount /dev/sdb1 /mnt`
- `umount` – Unmount filesystem.

### File Permissions

Both systems use the same permission model: three types (read, write, execute) for three categories (owner, group, others). View with `ls -l`. Example output:

```
-rwxr-xr-- 1 user group 1024 Mar 15 10:00 file.sh
```

First character: file type (`-` file, `d` directory). Next nine characters: permissions. `rwx` = owner has all; `r-x` = group read/execute; `r--` = others read only. Numeric: `chmod 754 file` means owner=7 (rwx), group=5 (r-x), others=4 (r--).

### Boot Process

macOS: Boot ROM -> EFI -> boot.efi -> kernel (XNU) -> launchd (PID 1) -> user space.
Linux: BIOS/UEFI -> bootloader (GRUB) -> kernel -> init/systemd -> user space.

### Troubleshooting

Common issues:
- **Application won't launch**: Check permissions, verify file integrity, check console logs (macOS: Console app, Linux: `journalctl` or `/var/log/syslog`).
- **Network connectivity**: Use `ping`, `ifconfig`/`ip addr`, check DNS with `nslookup`. On macOS, `networksetup -listallnetworkservices` shows interfaces.
- **Slow performance**: Use `top`/`htop` to find CPU/memory hogs, `df -h` for disk space, `du -sh *` for directory sizes.
- **Cannot install software**: Check package manager (Linux) or Gatekeeper (macOS). For Linux, ensure repositories are updated (`apt update`). For macOS, allow apps from unidentified developers via System Preferences > Security & Privacy.

### Recovery Modes

- **macOS Recovery**: Boot with Command+R (Intel) or hold power button (Apple Silicon). Options: Disk Utility, Reinstall macOS, Terminal, Restore from Time Machine.
- **Linux Recovery**: Boot into single-user mode (add `single` or `init=/bin/bash` to kernel command line) or use a live USB.

### Key Differences from Windows

- No drive letters; everything under `/`.
- Case-sensitive filenames (Linux default, macOS optional).
- Forward slashes in paths.
- Hidden files start with dot (`.`).
- Command line is powerful and often required for troubleshooting.
- Package managers instead of .exe/.msi.

### Exam Tips

The 220-1102 exam focuses on:
- Recognizing common commands and their outputs.
- Understanding the filesystem structure.
- Knowing how to change permissions and ownership.
- Basic troubleshooting steps (e.g., check disk space, kill process, flush DNS).
- Differences between macOS and Linux where they diverge (e.g., package managers, recovery modes).

Memorize key commands and their options. Practice in a virtual machine or dual-boot environment.

## Real-world context

In a typical enterprise environment, macOS and Linux systems serve different roles. macOS is often used by designers, developers, and executives who prefer the user experience and integration with other Apple devices. Linux dominates server infrastructure, cloud instances, and embedded systems. A systems administrator might manage a mixed environment where they support both platforms.

**Scenario 1: Web Server Migration**
A company is migrating a web server from a Windows IIS to a Linux Apache server. The administrator must transfer files, set permissions, and configure the web server. Using `scp` or `rsync` to copy files, `chmod` to set correct permissions (e.g., 755 for directories, 644 for files), and `chown` to set ownership to `www-data`. They also need to configure Apache virtual hosts in `/etc/apache2/sites-available/`. Common pitfalls: forgetting to enable the site with `a2ensite`, or incorrect SELinux contexts (on RHEL-based systems) causing 403 errors.

**Scenario 2: macOS Support for Developers**
A software development team uses macOS laptops. The IT support team must handle issues like application crashes, network connectivity, and software installation. For example, a developer cannot install a tool via Homebrew because of permission issues. The administrator runs `sudo chown -R $(whoami) /usr/local/bin` to fix ownership. Another common issue is DNS cache corruption causing 'server not found' errors; flushing the DNS cache resolves it. The support team also uses `system_profiler SPHardwareDataType` to gather hardware info for warranty claims.

**Scenario 3: Linux Server Hardening**
A security team needs to harden a Linux server. They disable root login via SSH (`PermitRootLogin no` in `/etc/ssh/sshd_config`), change default SSH port, and configure firewall with `iptables` or `ufw`. They use `chmod` to secure configuration files (e.g., `/etc/shadow` should be 640 or 600). They also set up `fail2ban` to block brute-force attacks. Regular updates are applied via `unattended-upgrades`. Misconfiguration of permissions can lead to service failures or security breaches, so careful testing is required.

## Exam focus

The CompTIA A+ 220-1102 exam tests Objective 1.6: 'Given a scenario, use appropriate macOS and Linux tools and commands.' The exam expects you to know:

1. **Common commands**: `ls`, `cd`, `pwd`, `cp`, `mv`, `rm`, `mkdir`, `rmdir`, `cat`, `less`, `grep`, `chmod`, `chown`, `ps`, `kill`, `top`, `dmesg`, `ifconfig`, `ping`, `traceroute`, `nslookup`, `sudo`. You must know their basic options. For example, `ls -la` shows all files with details; `chmod 755` sets rwx for owner, rx for group/others.

2. **Filesystem hierarchy**: Know that `/etc` holds config files, `/var/log` holds logs, `/home` (Linux) and `/Users` (macOS) hold user homes, `/Applications` is for apps on macOS, `/Volumes` for mounted drives.

3. **macOS specific**: Recovery mode (Command+R on Intel, hold power on Apple Silicon), Terminal, Disk Utility, System Preferences, Gatekeeper, SIP (`csrutil status`).

4. **Linux specific**: Package managers (`apt`, `yum`, `dnf`), systemd (`systemctl`), GRUB bootloader, virtual consoles (Ctrl+Alt+F1-F6).

**Common wrong answers**:
- Confusing `chmod` and `chown`: `chmod` changes permissions, `chown` changes ownership. A common trap is asking to 'change permissions' and offering `chown` as an answer.
- Mixing up `kill` options: `kill -9` is SIGKILL (force kill), `kill -15` is SIGTERM (graceful). The exam may ask which command forces a process to stop.
- Thinking `ifconfig` is the only network command: on modern Linux, `ip` is preferred, but `ifconfig` is still valid and tested.
- Assuming macOS and Linux are identical: they share many commands but have different default shells (Zsh vs Bash), different recovery methods, and different filesystem layouts (e.g., `/Users` vs `/home`).

**Edge cases**:
- The exam may ask about a command that exists on both but with different behavior. For example, `traceroute` on Linux uses ICMP by default, while on macOS it uses UDP. However, the exam typically tests the command name, not the protocol.
- File permissions: be able to interpret `-rwxr--r--` (owner rwx, group r, others r). Numeric: 744.
- Hidden files: start with `.`; `ls -a` shows them.
- Superuser: `sudo` is used; `su` switches user. Know that `sudo` requires the user to be in the sudoers file.

**How to eliminate wrong answers**:
- If the question asks for 'list files', the answer must include `ls`. Options like `dir` (Windows) or `list` are wrong.
- If the question involves 'change directory', the answer is `cd`.
- If the question involves 'view process list', the answer is `ps` or `top`. `ps aux` shows all processes.
- If the question involves 'search text in files', the answer is `grep`.
- If the question involves 'network configuration', look for `ifconfig` or `ip`.
- If the question involves 'package installation', look for `apt` (Debian) or `yum` (RHEL). The exam may specify the distribution.

Memorize these commands and practice in a lab environment. The exam expects practical knowledge, not just theory.

## Step by step

1. **Boot the System** — For macOS, press the power button. On Intel Macs, you can boot into Recovery Mode by holding Command+R immediately after the chime. On Apple Silicon, hold the power button until you see startup options. For Linux, the BIOS/UEFI loads the bootloader (GRUB), which presents a menu. If no input, it boots the default kernel. The kernel initializes hardware, mounts the root filesystem, and starts the init process (systemd on modern distros). The boot process can be observed via `dmesg` or `journalctl -b`.
2. **Open Terminal** — On macOS, go to Applications > Utilities > Terminal, or use Spotlight (Command+Space, type 'Terminal'). On Linux, use the desktop environment's terminal emulator (e.g., GNOME Terminal, Konsole) or switch to a virtual console with Ctrl+Alt+F1-F6. The terminal provides a shell prompt (e.g., `username@hostname:~$`). The default shell on macOS is Zsh; on Linux, it's often Bash. Both support tab completion, command history (up arrow), and piping (`|`).
3. **Navigate the Filesystem** — Use `pwd` to see current directory. Use `cd` to change directories: `cd /etc` goes to /etc, `cd ~` goes home, `cd ..` goes up one level. Use `ls` to list contents: `ls -la` shows all files with details. Hidden files (starting with dot) are shown with `-a`. Use `find` to search: `find / -name '*.conf'` finds all .conf files starting from root. Use `locate` (if installed) for faster searches via a database.
4. **Manage Files and Permissions** — Create a directory with `mkdir newdir`. Copy a file with `cp source dest`. Move/rename with `mv old new`. Delete with `rm file` (use `-r` for directories). Change permissions with `chmod 755 file` (owner rwx, group rx, others rx). Change owner with `chown user:group file`. To view permissions, `ls -l`. The `umask` command sets default permissions for new files. For example, `umask 022` results in 755 for directories, 644 for files.
5. **Install and Update Software** — On macOS, most software is installed via the App Store or drag-and-drop .app bundles. Command-line tools can be installed via Homebrew (`brew install package`). On Linux, use the package manager: `sudo apt update && sudo apt install package` (Debian/Ubuntu), `sudo yum install package` (RHEL/CentOS), or `sudo dnf install package` (Fedora). Always update package lists before installing. To remove, `sudo apt remove package`. To upgrade all, `sudo apt upgrade`.
6. **Troubleshoot Network Issues** — First, check connectivity with `ping 8.8.8.8` (if fails, check physical connection). Use `ifconfig` (macOS/Linux) or `ip addr` (Linux) to see IP address. Check DNS with `nslookup google.com` or `dig google.com`. On macOS, flush DNS cache with `sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder`. On Linux, restart networking with `sudo systemctl restart networking` or `sudo service network-manager restart`. Use `traceroute` to identify where packets are dropped.

## Comparisons

### macOS vs Linux

**macOS:**
- Default shell is Zsh (since macOS Catalina).
- Package management via App Store, Homebrew (third-party), or .app bundles.
- Filesystem: uses HFS+ or APFS; case-insensitive by default.
- Recovery mode: Command+R (Intel) or hold power button (Apple Silicon).
- GUI is integral; command line is secondary for most users.

**Linux:**
- Default shell is Bash (many distros), but Zsh is also common.
- Package management via apt, yum, dnf, pacman, etc., depending on distribution.
- Filesystem: ext4, XFS, Btrfs, etc.; case-sensitive by default.
- Recovery: single-user mode, live USB, or GRUB rescue.
- GUI is optional; many servers run headless.

## Common misconceptions

- **Misconception:** macOS and Linux are completely different operating systems with no common commands. **Reality:** Both are Unix-like and share many commands such as `ls`, `cd`, `cp`, `mv`, `rm`, `chmod`, `chown`, `ps`, `kill`, `grep`, `ping`, `ifconfig`, and `sudo`. The differences lie in package managers, default shells, filesystem paths (e.g., `/Users` vs `/home`), and recovery methods.
- **Misconception:** The `chmod` command changes file ownership. **Reality:** `chmod` changes file permissions (read, write, execute). `chown` changes file ownership (user and group). For example, `chmod 755 file` sets permissions; `chown user:group file` changes owner.
- **Misconception:** You cannot delete files from the command line without a recycle bin. **Reality:** The `rm` command permanently deletes files. There is no recycle bin in the terminal. Use with caution; consider `rm -i` for interactive confirmation or `trash-cli` on Linux for a safer alternative.
- **Misconception:** Linux does not have a graphical user interface. **Reality:** Linux can run desktop environments like GNOME, KDE, Xfce, etc. Many servers run headless (no GUI), but desktop distributions like Ubuntu, Fedora, and Linux Mint provide full GUIs. The exam focuses on command-line tools but acknowledges GUI exists.
- **Misconception:** macOS Recovery Mode is only accessible via Command+R on all Macs. **Reality:** On Intel Macs, Command+R boots into Recovery. On Apple Silicon Macs, you must hold the power button until startup options appear, then click Options. Apple Silicon also has a built-in recovery partition accessible via the power button.

## Key takeaways

- macOS and Linux are both Unix-like; many commands are identical (ls, cd, cp, mv, rm, chmod, chown, ps, kill, grep, sudo).
- The filesystem root is `/`; macOS uses `/Users` for home directories, Linux uses `/home`.
- File permissions: read=4, write=2, execute=1; chmod 755 gives owner rwx, group rx, others rx.
- Hidden files start with a dot (.) and are shown with `ls -a`.
- macOS Recovery: Command+R (Intel) or hold power button (Apple Silicon).
- Linux package managers: apt (Debian/Ubuntu), yum/dnf (RHEL/Fedora).
- Common troubleshooting: check disk space with `df -h`, process list with `ps aux` or `top`, network with `ping` and `ifconfig`.
- Use `sudo` to run commands as superuser; `su` switches user.
- Flush DNS on macOS: `sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder`.
- The exam expects you to know command options like `ls -la`, `chmod 755`, `ps aux`, `kill -9`.

## FAQ

**What is the difference between `chmod` and `chown`?**

`chmod` changes file permissions (read, write, execute) for owner, group, and others. `chown` changes the ownership of a file (user and/or group). For example, `chmod 755 file.sh` sets permissions; `chown user:group file.sh` changes owner to 'user' and group to 'group'. On the exam, if the question says 'change permissions', the answer is `chmod`; if 'change owner', it's `chown`.

**How do I list all files including hidden ones in Linux/macOS?**

Use `ls -a` or `ls -la` for a detailed listing. The `-a` flag shows all files, including those starting with a dot (hidden files). `-l` gives a long format with permissions, size, and date. Example: `ls -la /home/user`.

**What command kills a process forcefully?**

`kill -9 PID` sends SIGKILL, which immediately terminates the process without cleanup. For a graceful termination, use `kill -15 PID` (SIGTERM). On the exam, 'force kill' implies `-9`. Example: `kill -9 1234`. You can find the PID with `ps aux` or `pgrep`.

**How do I install software on Ubuntu Linux?**

Use `apt-get` or `apt`. First, update the package list: `sudo apt update`. Then install: `sudo apt install package-name`. To remove: `sudo apt remove package-name`. To upgrade all: `sudo apt upgrade`. On RHEL/CentOS, use `yum install package-name` or `dnf install package-name`.

**What is macOS Recovery Mode and how do I access it?**

Recovery Mode provides utilities like Disk Utility, Terminal, and Reinstall macOS. On Intel Macs, restart and hold Command+R until the Apple logo appears. On Apple Silicon Macs, hold the power button until startup options appear, then click Options. It's used for troubleshooting, disk repair, and OS reinstallation.

**How do I check disk space on Linux/macOS?**

Use `df -h` to see disk usage in human-readable format (e.g., GB, MB). To see directory sizes, use `du -sh directory-name`. Example: `df -h` shows mounted filesystems and their used/available space. `du -sh /home` shows the size of the /home directory.

**What is the difference between `sudo` and `su`?**

`sudo` allows a permitted user to execute a command as the superuser (or another user) based on the /etc/sudoers file. `su` switches the current user to another user (default root) and requires the target user's password. `sudo` is more secure because it logs commands and limits privileges. Example: `sudo apt update` runs apt as root; `su -` switches to root shell.

---

Interactive version with quiz and diagrams: https://courseiva.com/learn/a-plus-core-2/macos-linux-basics
