Master the macOS Terminal like a pro

  • Understands paths and PATH to execute commands accurately and without typing endless paths.
  • Enhance your environment with iTerm2, Zsh, and Oh My Zsh: themes, fonts, and colors that enhance productivity.
  • Gain speed with plugins (syntax highlighting, autosuggestions) and aliases like ll/la.
  • Apply good practices when using advanced commands (ditto, curl, defaults, rm) safely.

Terminal on macOS

If you want to get the most out of your Mac, the Terminal can become your best ally: It is very fast, flexible and allows you to automate tasks. that become a pain with the graphical interface. In this in-depth guide, I'll tell you how to master it from scratch, with practical examples and a modern setup that will make your life easier.

In addition to the basic commands and some more advanced ones, we will see how to leave the console impeccable with iTerm2, Zsh and Oh My Zsh, add cool themes and fonts, integrate plugins like syntax highlighting and auto-suggestions, and create aliases to speed up your daily life. I'll explain it to you straightforwardly, with a friendly touch and tips that will save you time.

What is Terminal on macOS and why is it worth it?

Terminal is the macOS command-line app, a window into the guts of the system where you can execute Unix instructions with surgical precision; Its main advantage is speed and the ability to chain tasks without lifting your hands from the keyboard.

When you open Terminal you will see a window with your username, the active shell (bash or zsh) and the window size; since macOS Catalina, the default shell is Zsh, although You can switch between shells by typing bash o zsh directly and pressing Enter.

If the default color scheme doesn't suit you, you can go to the app menu and open a new window with a different profile; There are light and dark themes ready to use, and later we will see how to install many more.

Looking for alternatives? There are third-party terminals like Core Shell, and to monitor your Mac without leaving the menu bar, you have utilities like iStat Menus; They are add-ons that fit very well with a console-based workflow..

Terminal Interface

Paths in Terminal: absolute, relative, and the PATH variable

In the Terminal world, the word "path" is used in two different senses: on the one hand, the path to a file or folder within the file system, and on the other, the special variable PATH which indicates in which directories the system looks for executables when you type a command.

About the file system: an absolute path starts at the root of the disk (/) and it doesn't depend on where you are, for example /Aplicaciones/Utilidades/Terminal.app; a relative path starting from your current position, and is expressed with ./ in front of (if you are already in /Aplicaciones/, to go to Utilities just ./Utilidades/).

When you start Terminal you start in your home folder, something like /Users/tuusuario/; This is important to understand where the commands are executed if you do not specify a full path.

The other meaning of "route" is the variable PATH, which stores directories where the shell will search for executables without you having to type their full path; to see their contents type echo $PATH and you will see a list separated by colons, allowing you to add your own directories for custom tools.

If you install a program and want to be able to call it by name from anywhere, add its binaries folder to the PATH and that's it; It is one of the keys to working agilely on the console and avoid long routes again and again.

How to open Terminal and navigate the system

There are several ways to open the app: use Spotlight with Command+Space, type "Terminal" and press Enter; you can also go to Launchpad > Utilities, or open Finder > Applications > Utilities and double-click it; choose the one that is fastest for you.

To navigate, use cd (change directory) and ls (list contents). For example: cd ~/Documentos and then ls to view the files; the character ~ means your user folder, a shortcut that saves you from typing long paths.

A powerful trick: open Finder, drag a folder or file into the Terminal window and the path will be pasted automatically; This minimizes errors with spaces and capital letters, which are very important on console.

To edit or open settings, you can launch apps from Terminal: for example open ~/.zshrc will open your configuration file in the default editor; If you prefer to do it in Terminal, nano ~/.zshrc It is a simple option.

If you get lost, remember that pwd shows your current location and that you can complete names with the Tab key; If Tab doesn't complete, check capital letters, quotes, and spaces because every character counts.

Open and use Terminal

Essential Commands: Structure, Rules, and Examples

Every command consists of the command name, arguments, and optionally options; for example, to move a file you would use mv followed by the origin and destination routes, and You can add options to change the behavior.

Basic example to practice: cd ~/Documentos, then mkdir TerminalTest to create a folder, and finally cd TerminalTest to enter; check its contents with ls and you will see the newly created folder if you go back to a higher level.

To rename a file inside that folder, place a test file and run mv TerminalTestFile.rtf TerminalTestFile2.rtf; the command mv It serves both to move and to rename depending on the parameters you pass to it.

If you need to move a file between directories, specify both paths: for example mv ~/Documents/TerminalTest/TerminalTestFile.rtf ~/Documents/TerminalTest2/TerminalTestFile.rtf; Note that the routes are absolute to avoid confusion..

Some golden rules: spaces are written as is or escaped between quotes, commands are executed in the current directory if you do not specify a path, and You can interrupt execution with Control+C if something is not going well.

Check the integrated help with man comando to see its manual, and try pressing Tab to autocomplete; Learning the syntax of a few tools multiplies your productivity since the first day.

Somewhat more advanced commands for everyday tasks

Copying entire folders respecting structure and permissions is a task of ditto: writes ditto /carpeta/origen /carpeta/destino to clone its content; Add -v if you want to see the details of the copy while running.

To download files from the Internet without a browser you can use curl: go to Downloads with cd ~/Descargas and run curl URL-del-archivo; If you need to save it with a specific name, add -o nombre.ext at the end of the command.

Customize where your screenshots are saved with defaults write com.apple.screencapture location /ruta/deseada and apply changes with killall SystemUIServer; If you also want them to be JPG, use defaults write com.apple.screencapture type JPG and repeats the killall.

To delete files, rm It is direct and unforgiving; if you want interactive confirmation, use rm -i archivo, and to remove entire directories use rm -R carpeta o rm -iR carpeta; Take extreme caution and double-check the route before pressing Enter.

Do you need to clean up space without risking it? rmThere are dedicated utilities, such as CleanMyMac, that analyze and suggest secure deletions; For routine maintenance they may be more convenient than the command line, especially if you haven't mastered the options yet.

Set up a modern environment: Homebrew, iTerm2, and Zsh

Before installing anything, make sure you have the Xcode command line tools: run xcode-select --install and if that fails, try xcode-select -r to reset; This installs basic compilers and utilities that some tools need..

Install Homebrew (macOS package manager) following the instructions on its official website; in many environments you'll see the classic Ruby installer or the current Bash command, both of which will get you ready to go. brew; With Homebrew you can install apps with a single command..

For iTerm2, the most popular Terminal replacement, use brew install --cask iterm2 (in old guides it appears brew cask install iterm2); iTerm2 brings tabs, split panes, advanced search, and a thousand other details that you will notice from the first minute.

macOS brings Zsh in /bin/zsh, but you can install the Homebrew version with brew install zsh; check the version with zsh --version to confirm, and set Zsh as the default shell with chsh -s $(which zsh) (please log in to apply the change).

With iTerm2 and Zsh ready, it's time to give them superpowers with Oh My Zsh, a community framework that centralizes themes, plugins, and configuration; install it with sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" and when you're done, you'll be able to update it with upgrade_oh_my_zsh.

Themes, fonts, and color schemes that make a difference

Oh My Zsh brings a good handful of themes; edit ~/.zshrc and adjust the line ZSH_THEME the one you like the most, for example ZSH_THEME="agnoster"; save changes and reload with source ~/.zshrc to apply instantly.

If you want a more complete one, install Powerlevel9k by cloning the repo with git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k and defines ZSH_THEME="powerlevel9k/powerlevel9k"; reload the configuration with source ~/.zshrc and ready.

Some themes require fonts with Powerline or Nerd Fonts symbols; you can install Powerline from their repository with git clone https://github.com/powerline/fonts.git, cd fonts y ./install.sh; then change the font in iTerm2 > Preferences > Profiles > Text.

A very popular choice is FiraCode Nerd Font, which provides ligatures for prettier arrows and operators; check the "Use ligatures" box if your theme supports it, and If it doesn't apply instantly, close and reopen iTerm2 so that it takes the new source.

To finish, import color schemes from iTerm2-Color-Schemes: download the ZIP, extract it and in iTerm2 go to Profiles > Colors > Color Presets > Import to add them; Activate your favorite (for example, "Batman" is very popular) and enjoy the new look.

Powerlevel10k: Guided setup and ultra-fast prompt

If you're looking for an agile and highly configurable prompt, Powerlevel10k is a safe bet; install it with git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k and put ZSH_THEME="powerlevel10k/powerlevel10k" trust your ~/.zshrc; recharge with source ~/.zshrc and a wizard will be launched.

The configurator will ask you if you see certain symbols (diamond, lock, arrow); answer with y o n according to your case and choose the style you prefer; You can choose Unicode, more compact icons, or a classic prompt. according to your tastes.

Some questions measure the spacing so that the symbols fit together without overlapping; if you notice overlap, select the negative option and let Powerlevel10k adjust the offset. If you make a mistake, relaunch the wizard with p10k configure whenever you want.

Upon completion, a configuration will be saved to your ~/.zshrc me in ~/.p10k.zsh; Accept the recommended suggestions if you are just starting out and you will now be able to enjoy a quick and very clear, informative prompt.

If something doesn't quite work after changing the font, restart the terminal; sometimes the font adjustment isn't applied until you close and reopen it. It is normal and is solved in seconds.

Essential plugins and aliases to go full throttle

Oh My Zsh comes with a Git plugin by default, but you can add many more; open ~/.zshrclook for the line plugins=(...) and add the ones you want; then execute source ~/.zshrc to activate the new list.

For Docker, clone the plugin with git clone https://github.com/zsh-users/zsh-docker.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-docker and add it to plugins; You will gain shortcuts and specific auto-completion for your containers.

Syntax highlighting: zsh-syntax-highlighting Color correct commands in green and errors in red; install it with git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting; don't forget to include it in the plugin list.

Auto-suggestions: zsh-autosuggestions displays, in faint, the last matching command as you type; install with git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions and add it to plugins; It will save you a lot of typing.

For a more attractive directory listing than ls, proof exa: on macOS brew install exa and in Ubuntu sudo apt install exa (in very recent versions you may need to install it from their GitHub); create useful aliases in ~/.zshrc , the alias ll="exa -lh" y alias la="exa -lha".

Package management with Homebrew and other system essentials

Homebrew makes installing and updating software as simple as possible: brew update refreshes formulas, brew install <paquete> installs and brew upgrade update; for graphical apps, use brew install --cask <app> and you forget.

If you also work with Linux (for example Ubuntu), remember that the package manager is apt: update with sudo apt update and install with sudo apt install <paquete>; Most concepts of Zsh and Oh My Zsh are identical in both systems.

When you edit ~/.zshrc, remember to recharge with source ~/.zshrc to apply changes on the fly; if something doesn't work as expected, open a new terminal to make sure no old variables remain in memory.

If you're concerned about stability, keep your tools up to date: upgrade_oh_my_zsh for the framework, brew upgrade for packages and softwareupdate for macOS; Small maintenance prevents rare problems later.

Clear Mac Terminal History

Good practices, security and graphic alternatives

Always keep in mind that Terminal accesses every part of the system: check every command (and every path) before launching it, and use interactive options (-i) in dangerous commands when you are learning.

If your goal is to free up space or monitor resources, consider dedicated apps: for cleaning, solutions like CleanMyMac offer secure deletions; To monitor CPU, disk or network, iStat Menus gives you data in the bar without opening the console.

Finally, take advantage of iTerm2 profiles for different projects: different colors, fonts, environment variables, and home directories; Having it organized by context makes you faster and reduces errors when changing tasks.

Mastering Terminal on macOS is not just about memorizing commands, but also about understanding paths (absolute, relative, and the PATH), practice essential commands, and support yourself in a modern environment with iTerm2, Zsh, and Oh My Zsh; When you add themes, fonts, colors, plugins, and aliases, the console goes from "useful" to "must-have." for anyone who wants to work like a true professional.