Skip to content

Latest commit

 

History

History
262 lines (164 loc) · 6.82 KB

File metadata and controls

262 lines (164 loc) · 6.82 KB

Mac Terminal Cheatsheet

Tecnate | Last Updated: 2024-05-19

Table of Contents


About This Document

This cheatsheet is for quick reference to common commands for the Mac terminal (with significant carryover to Linux as well).

  • Assume Bash/Zsh shells unless specified otherwise.
  • Assume that multi-key commands written with the + symbol are chords (key combinations in sequence). Don't actually type the + sign unless instructed.
  • &&: chains commands together (if the preceding command succeeds).

Common Mac Keyboard Symbols

  • / Command (Cmd)
  • Option/Alt
  • Control (⌃)
    • Not ^ caret (the "6" key special character on a standard US keyboard)
  • Shift
  • / Up/Down Arrows
  • / Right/Left Arrows
  • Enter Enter/Return
  • Space Spacebar

Processing & Searching Text

There are three main tools to search and process text:

  1. grep: finds text patterns in a file. (Most simple.)
  2. sed: finds and modifies data.
  3. awk: a programming language. (Most complex.) It is usually used to:
    1. Process field-oriented data.
    2. Perform numeric comparisons/calculations.
    3. Modify data based on calculations.

Command Line Navigation

Move Cursor To Beginning Of Input

⌃A

Move Cursor To End Of Input

⌃E

Move Backward One Word

⌥←

Move Forward One Word

⌥→


Input Manipulation

All of the following Clear commands will "copy" the cleared text and make it available to yank (paste), except for the ⌃C signal interrupter.

Clear Entire Input

⌃U

Clear Entire Input After Cursor

⌃K

Clear Previous Word

⌃W

Clear Next Word

Esc D

Clear Terminal Screen

⌃L

This clears the terminal screen of text by adding newlines to your window.

Yank (Paste Previously Cleared) Text

⌃Y

The most recently cleared text, regardless of length, is available to be recalled.

Cancel (Signal Interrupt) Current Command Line

⌃C

This terminates execution of the process and wipes the command line regardless of cursor position, but you will only be able to yank (recall/paste) previously cleared text.


Directory & File Manipulation

Make A Single Directory

mkdir directoryName

Make Multiple Directories

  • -p: the parents option.

Create directories within the current working directory. mkdir -p dir1 dir2 dir3

Create directories within a specified parent directory. mkdir -p parentDirectory/dir1 dir2 dir3

Make Nested Directories

mkdir -p county/city/neighborhood/

Copy a Directory

cp -r sourceFolder destinationFolder

Create A File

touch fileName.txt

Create Multiple Files

touch file1.txt file2.js file3.jpg file4.html

Create A Directory & File Together

mkdir folderName && touch folderName/fileName.txt

Move File(s) To A Directory

mv file1.txt file2.js folderName


Admin Privileges

Executing some commands will require admin (superuser) privileges.

  • sudo: superuser do.
    • Requires your system password to execute.

Run Commands As Superuser

Prepend sudo to any command.

Run A Shell As Superuser

sudo -s

  • -s: shell.
    • ⛔️ This option will open a new shell session with superuser privileges so you don't have to prepend everything with sudo.

Computer Utilities (MacOS)

Shutdown, Restart, Sleep

Modifying system power will likely require sudo permissions.

Use the following options with any of the shutdown commands below:

  • -h: halt (shut down/power off)
  • -r: reboot (restart)
  • -s: sleep

Shutdown Immediately

sudo shutdown -h now

Shutdown In 10 Minutes

sudo shutdown -h +10

Schedule Shutdown

Use 24-hour (hh:mm) time to schedule a power off.

sudo shutdown -h 22:30

Image manipulation

Image Format Conversion

Convert a jpg to png sips -s format png oldImage.jpg --out newImage.png

Resize Image

Set max height/width to 800 pixels. sips -Z 800 image.jpg

Check Network Stats

networkQuality

File Conversion

Convert a text file to HTML textutil -convert html document.txt

Convert a text file to PDF textutil -convert pdf document.txt -output document.pdf

Text To Speech

say hello world