Intro
Mastering the macOS Terminal can be a game-changer for anyone looking to enhance their productivity and control over their computer. This guide walks you through the basics of using the Terminal, from simple commands to more advanced techniques, helping you to harness the full potential of your macOS system.
Opening Terminal:
- Via Spotlight: Press
Cmd + Spaceand type “Terminal,” then hitEnter. - Via Applications: Navigate to
Applications > Utilities > Terminal.
Understanding the Command Line Interface (CLI):
- Prompt: The line where you type commands, usually in the format:
username@hostname ~ %. - Cursor: The blinking box or line that indicates where your text will appear when you start typing.
Basic Commands:
Displaying the Current Directory (pwd)
- Command:
pwd - Usage: Prints the current working directory.
Listing Files and Directories (ls)
- Command:
ls - Usage: Lists files and directories in the current directory.
Changing Directories (cd)
- Command:
cd [directory] - Usage: Changes the current directory to the specified one.
Creating Directories (mkdir)
- Command:
mkdir [directory name] - Usage: Creates a new directory.
Creating Files (touch)
- Command:
touch [file name] - Usage: Creates a new, empty file.
Viewing File Contents (cat, less)
- Command:
catorless - Usage: Displays the content of a file or views it page by page.
Copying Files and Directories (cp)
- Command:
cp [source] [destination] - Usage: Copies files or directories.
Moving/Renaming Files and Directories (mv)
- Command:
mv [source] [destination] - Usage: Moves or renames files or directories.
Deleting Files and Directories (rm, rmdir)
- Command:
rmorrmdir - Usage: Deletes files or empty directories.
Opening Files with Default Application (open)
- Command:
open [file or directory] - Usage: Opens a file or directory with the default application.
Navigation Shortcuts:
cd ~: Go to the home directory.cd ..: Move up one directory level.Ctrl + C: Cancel the current command.Ctrl + L: Clear the Terminal screen.
Managing Processes:
ps: Displays currently running processes.kill [PID]: Stops a process with the specified Process ID (PID).top: Displays active processes and system usage.
Permissions:
chmod [permissions] [file]: Changes file permissions.sudo [command]: Executes a command with superuser (root) privileges.
Customizing Terminal:
- Profiles: Customize the appearance by going to
Terminal > Preferences > Profiles. - Aliases: Create shortcuts for commands by editing the
.zshrcor.bash_profilefile.
Advanced Tips:
Piping (|)
- Send the output of one command as input to another.
Redirection (>, >>)
- Redirect output to a file.
Additional Resources:
- Manual Pages: Learn more about a command using
man [command]. - Online Resources:
