|||

Mac Terminal command-line interface (CLI) cheatsheet

Last updated on January 13th, 2021

summary


This is the syntax I use throughout this cheatsheet:

syntax description
$ a shell prompt
text in monospaced font a command or other terminal text
[text in brackets] an optional parameter
underlined text a parameter you must replace with a value
[…] a parameter that might be repeated
/ the top level directory a.k.a. folder
. the current directory
.. the parent directory
~ the home directory

editing shortcuts description
Ctrl ⌃ + A then Ctrl ⌃ + K
or Ctrl ⌃ + E then Ctrl ⌃ + U
delete the entire line of text
Ctrl ⌃ + U delete the line of text before the cursor
Ctrl ⌃ + K delete the line of text after the cursor
Ctrl ⌃ + H
or delete
delete the character before the cursor
Ctrl ⌃ + W delete the word before the cursor
Ctrl ⌃ + A move cursor to beginning of the line
Ctrl ⌃ + E move cursor to end of the line
Ctrl ⌃ + T swap the last two characters before the cursor
Esc + T swap the last two words before the cursor

navigation commands description
$ pwd display path to current directory
$ cd [~] go to home directory
$ cd directory-relative-path go to directory
$ cd / go to root of the drive
$ cd - go back to previous directory
$ cd .. go to parent/enclosing directory
$ cd ../.. go to parent/enclosing directory of parent/enclosing directory
$ q exit
$ clear
or Ctrl ⌃ + L
or Command ⌘ + K
clear screen
Tab auto-complete file and directory names

history commands description
$ history n display n previously typed commands
arrow up display previously typed commands one by one
Ctrl ⌃ + R then search-query then Ctrl ⌃ + R to display anterior match search history of commands previously used in Terminal

file and directory management commands description
$ ls display list of items in current directory
$ ls -a display list of items and hidden items of current directory
$ ls -lh display list of items with details, with size in human readable format
$ ls -lSh display list of items with details, sorted by size in descending order, in human readable format
$ touch file-name.extension-name create a new file
$ cp source-path destination-path copy file
$ mv current-file-name new-file-name rename file
$ mv source-path destination-path move file
$ mv keyword* destination-path move all files starting with a specific keyword
$ mv *keyword* destination-path move all files including a specific keyword
$ rm file remove file
$ rm -i file remove file with confirmation
$ rm -r directory remove a directory and contents
$ rm -f file force removal without confirmation
$ rm -i file display prompt before
$ mkdir name-of-new-directory create a directory
$ cat file display content of a file
drag the file or folder to the Terminal window enter the path of a file or folder
$ find directory -name file find a file in a directory
$ open file open file with default application
$ open file -a application open file with specific application

applications management commands description
$ open -a application-name open an application from any directory (-a)
$ open -a tor browser” open an application (with a space in its name) from any directory
$ open https://romainaubert.com open a url in your default browser
$ nano open terminal text editor

system commands description
$ df -h display disk usage information of a file system in human readable format
$ du -sh display size information of a file or a directory in human readable format
$ du -sh * display size information of items in a directory in human readable format
$ date display current date and time
$ cal display current month calendar
$ caffeinate -d prevent display from sleeping
$ caffeinate -i prevent system from idle sleeping
$ caffeinate -m prevent disk from going idle
$ caffeinate -s keep Mac awake while it is plugged into AC power
$ caffeinate keep Mac awake as long as the Terminal is running. To stop process: Ctrl ⌃ + C
$ caffeinate -t n in second keep you Mac awake for a set number of second

CLI-based application commands description
$ curl wttr.in display weather of current location (based on IP address)
$ curl wttr.in/city display weather in any city (blog post coming soon, subscribe to RSS feed)
$ ddgr search query display search query from DuckDuckGo (blog post coming soon, subscribe to RSS feed)

Hey, I’m writing a book to explain how platforms and applications get away with what they promise they will do (and don’t do); and what impact your usage has on your well-being. You can sign up here to get an email when the book is out.

Up next A roadmap to reclaiming my attention, relationships, intimacy and privacy I’ve always felt I spend too much time on my smartphone and “social media.” I’ve also noticed that some applications have become the architecture of Mac Terminal commands to prevent Mac from sleeping This is the syntax I use throughout this document: syntax description $ a shell prompt text in monospaced font a command or other terminal
Latest posts Update: added EtherCal (web-based spreadsheet), Etherpad (web-based word processor), Framadate (polls), Drop (file transfer) to list.romainaubert.com Mac Terminal commands to prevent Mac from sleeping Mac Terminal command-line interface (CLI) cheatsheet A roadmap to reclaiming my attention, relationships, intimacy and privacy Bypass cookie banners by toggling “reader view” in your browser Book review - alone together: why we expect more from technology and less from each other - by sherry turkle Update: added 2 Android OS, 2 phones, a search engine, a map app, 2 blog CMS, and a tool to delete Tweets to list.romainaubert.com Should people negotiate financial income from the use of their personal data? Peer-to-peer/decentralized network architectures and information commons as an alternative to a centralized internet Yelp is screwing over restaurants by replacing their phone numbers on listings and routing customers’ calls thru a referral marketing business. how to ditch Facebook, Twitter, Google News, Instagram, and LinkedIn — and still follow news, people and organizations you like Tour of Queyras (GR58), 140 km, 7,000m elevation, 7 days Facebook’s “privacy notifications” and “co creation strategies” to protect people’s privacy Privacy-friendly and open source alternatives to Google’s products Privacy 101: simple steps to protect your privacy online Bongo 9. twtxt Asynchronous communication for open source projects git - remote: Invalid username or password. fatal: Authentication failed for [remote’s URL] product development resources 10 Days in Silence: Vipassana Meditation Book review - un peuple de promeneur - alexandre romanès Book review - journey under the midnight sun (白夜行, byakuyakō) - keigo higashino Book review - how to fail at everything and still win big - scott adams Book review - the remains of the day - kazuo ishiguro Book review - man’s search for meaning - viktor e. frankl Book review - cosmos - michel onfray We don’t care about personas “Building a more private web” by Google — comment on Reddit Replacing Facebook with newsletters Now