< All Topics Main Mac The Mac Terminal Commands Cheat Sheet Print The Mac Terminal Commands Cheat Sheet PostedDecember 13, 2021 UpdatedDecember 13, 2021 ByAdministrator Our mega cheat sheet of Mac terminal commands provides a great reference for all the important commands you should know.macOS is an intuitive operating system, so you don’t have to spend lot of time learning the basics; Knowing this, why should you learn and take advantage of the Unix command line available on your Mac? We have four good reasons:There are dozens of open source and freely available Unix-based apps. You don’t have to spend money on these.When you’re having difficulty searching for files in Spotlight, you can turn to Unix search tools. They’re way more powerful than Spotlight.You can manage files, folders, and file archives in an automated manner. Setting up a cron job will handle this automatically.It gives you more power and control over your system.With so many Mac commands, it’s often difficult to remember and use them all. We’re here to help with a detailed cheat sheet of Mac Terminal commands you can use to unlock enhanced productivity on your system.Launch the Terminal app from Applications > Utilities or search for it via Spotlight. Then you can get started with some of the powerful commands below.FREE DOWNLOAD: This cheat sheet is available as a downloadable PDF from our distribution partner, TradePub. You will have to complete a short form to access it for the first time only. Download the Mac Terminal Commands Cheat Sheet.The Mac Terminal Commands Cheat SheetCOMMANDACTIONShortcutsTabAuto-complete file and folder namesCtrl + AGo to the beginning of the line you’re currently typing onCtrl + EGo to the end of the line you’re currently typing onCtrl + UClear the line before the cursorCtrl + KClear the line after the cursorCtrl + WDelete the word before the cursorCtrl + TSwap the last two characters before the cursorEsc + TSwap the last two words before the cursorCtrl + LClear the screenCtrl + CKill whatever you’re runningCtrl + DExit the current shellOption + →Move cursor one word forwardOption + ←Move cursor one word backwardCtrl + FMove cursor one character forwardCtrl + BMove cursor one character backwardCtrl + YPaste whatever was cut by the last commandCtrl + ZPuts whatever you’re running into a suspended background processCtrl + _Undo the last commandOption + Shift + Cmd + CCopy plain textShift + Cmd + VPaste the selectionexitEnd a shell sessionBasics/ (Forward Slash)Top level directory. (Single Period)Current directory.. (Double Period)Parent directory~ (Tilde)Home directorysudo [command]Run command with the security privileges of the super usernano [file]Opens the Terminal editoropen [file]Opens a file[command] -hGet help about a commandman [command]Show the help manual of the commandChange DirectorycdHome directorycd [folder]Change directory, e.g. cd Documentscd ~Home directorycd/Root of the drivecd –Previous directory or folder you last browsedpwdShow your working directorycd..Move up to the parent directorycd../..Move up two levelsList Directory ContentslsDisplay the name of files and subdirectories in the directoryls -CForce multi-column output of the listingls -aList all entries including those with .(period) and ..(double period)ls -1Output the list of files in one entry per line formatls -FDisplay a / (slash) immediately after each path that is a directory, * (asterisk) after executable programs or scripts, and @ after a symbolic linkls -SSort files or entries by sizels -lList in a long format. Includes file mode, owner and group name, date and time file was modified, pathname, and morels -l /List of the file system from root with symbolic linksls -ltList the files sorted by time modified (most recent first)ls -lhLong listing with human readable file sizes in KB, MB, or GBls -loList the file names with size, owner, and flagsls -laList detailed directory contents, including hidden filesFile Size and Disk SpaceduList usage for each subdirectory and its contentsdu -sh [folder]Human readable output of all files in a directorydu -sDisplay an entry for each specified filedu -sk* | sort -nrList files and folders, totaling the size including the subfolders. Replace sk* with sm* to list directories in MBdf -hCalculate your system’s free disk spacedf -HCalculate free disk space in powers of 1,000 (as opposed to 1,024)File and Directory Managementmkdir <dir>Create new folder named <dir>mkdir -p <dir>/<dir>Create nested foldersmkdir <dir1> <dir2> <dir3>Create several folders at oncemkdir “<dir>”Create a folder with a space in the filenamermdir <dir>Delete a folder (only works on empty folders)rm -R <dir>Delete a folder and its contentstouch <file>Create a new file without any extensioncp <file> <dir>Copy a file to the foldercp <file> <newfile>Copy a file to the current foldercp <file>~/<dir>/<newfile>Copy a file to the folder and rename the copied filecp -R <dir> <“new dir”>Copy a folder to a new folder with spaces in the filenamecp -i <file><dir>Prompts you before copying a file with a warning overwrite messagecp <file1> <file2> <file3>/Users/<dir>Copy multiple files to a folderditto -V [folder path][new folder]Copy the contents of a folder to new folder. In here “-V” print a line of status for every file copiedrm <file>Delete a file (This deletes the file permanently; use with caution.)rm -i <file>Delete a file only when you give confirmationrm -f <file>Force removal without confirmationrm <file1> <file2> <file3>Delete multiple files without any confirmationmv <file> <newfilename>Move/renamemv <file> <dir>Move a file to the folder, possibly by overwriting an existing filemv -i <file> <dir>Optional -i flag to warn you before overwriting the filemv *.png ~/<dir>Move all PNG files from current folder to a different folderCommand HistoryCtrl + RSearch through previously used commandshistory nShows the previous commands you’ve typed. Add a number to limit to the last n items![value]Execute the last command typed that starts with a value!!Execute the last command typedPermissionsls -ldDisplay the default permission for a home directoryls -ld/<dir>Display the read, write, and access permission of a particular folderchmod 755 <file>Change the permission of a file to 755chmod -R 600 <dir>Change the permission of a folder (and its contents) to 600chown <user>:<group> <file>Change the ownership of a file to user and group. Add -R to include folder contentsProcessesps -axOutput currently running processes. Here, a shows processes from all users and x shows processes that are not connected with the Terminalps -auxShows all the processes with %cpu, %mem, page in, PID, and commandtopDisplay live information about currently running processestop -ocpu -s 5Display processes sorted by CPU usage, updating every 5 secondstop -o rsizeSort top by memory usagekill PIDQuit process with ID <PID>. You’ll see PID as a column in the Activity Monitorps -ax | grep <appname>Find a process by name or PIDNetworkping <host>Ping host and display statuswhois <domain>Output whois info for a domaincurl -O <url/to/file>Download file via HTTP, HTTPS, or FTPssh <username>@<host>Establish SSH connection to <host> with user <username>scp <file><user>@<host>:/remote/pathCopy <file> to a remote <host>arp -aView a list of all devices on your local network. It will show you the IP and MAC address of all the devicesifconfig en0View your device IP and MAC addresstraceroute [hostname]Identify the path and the hops traversed by the packets from your device to the destination addressHomebrewbrew doctorCheck brew for potential problemsbrew helpList of useful homebrew formula and cask commandsbrew install <formula>|<cask>Install a formula or caskbrew uninstall <formula>|cask>Uninstall a formula or caskbrew list –formulaList only installed formulasbrew list –caskList only installed caskbrew deps <formula>|<cask>List all the dependencies of a formula or caskbrew search text|/regex/Search formula or cask through regexbrew upgrade <formula>|<cask>Upgrade the formula or caskbrew outdated <formula>|<cask>Search for outdated formula or caskbrew outdated –formulaSearch for outdated formulabrew outdated –caskSearch for outdated caskbrew pin [installed_formula]Pin a formula from getting upgradedbrew unpin [installed_formula]Unpin to upgrade a packagebrew cleanupRemove stale lock files and outdated packages for all formula and casks.Environment Variable or PathprintenvDisplay a list of currently set environment variables. Also tells you which shell you’re using$echoTells the terminal to print something and show it to youecho $PATHCheck the value of the PATH variable which storea a list of directories with executable filesecho $PATH >path.txtExport the path directory to a text fileexport PATH=$PATH:absolute/path to/program/Execute a program via terminal only in your current session. If you use a program regularly, add the path to shell configuration file.Searchfind <dir> -name <“file”>Find all files named <file> inside <dir>. Use wildcards (*) to search for parts of filenamesgrep “<text>” <file>Output all occurrences of <text> inside <file> (add -i for case insensitivity)grep -rl “<text>” <dir>Search for all files containing <text> inside <dir>Outputcat <file>Output the content of <file>less <file>Output the contents of <file> using the less command that supports pagination and morehead <file>Output the first 10 lines of <file><cmd> > > <file>Appends the output of <cmd> to <file><cmd> > <file>Direct the output of <cmd> into <file><cmd1> | <cmd2>Direct the output of <cmd1> to <cmd2>Next, Customize the Mac TerminalThere are many commands in this cheat sheet. But you don’t have to learn all of them at once! Pick a few that integrate well with your workflow and save you the most time. Once you’ve mastered these commands, there’s still more to learn about the Terminal to enhance your experience with it.You can take this further and customize the Mac Terminal to make it even more useful.(source: https://www.makeuseof.com/tag/mac-terminal-commands-cheat-sheet/)