You are on page 1of 1

Mac Terminal Commands

List the file names with size, owner, Change the ownership of a file to user
ls -lo and flags chown <user>:<group> and group. Add -R to include folder
Shortcuts <file> contents
List detailed directory contents,
ls -la including hidden files
Tab Auto-complete file and folder names
Go to the beginning of the line you're Processes
Ctrl + A currently typing on
Go to the end of the line you're
File Size and Disk Space Output currently running processes.
Ctrl + E List usage for each subdirectory and Here, a shows processes from all
currently typing on ps -ax
du its contents users and x shows processes that are
Ctrl + U Clear the line before the cursor not connected with the Terminal
Human readable output of all files in a
Ctrl + K Clear the line after the cursor du -sh [folder] Shows all the processes with %cpu,
directory ps -aux
Ctrl + W Delete the word before the cursor %mem, page in, PID, and command
du -s Display an entry for each specified file
Swap the last two characters before Display live information about
Ctrl + T List files and folders, totaling the size top currently running processes
the cursor
du -sk* | sort -nr including the subfolders. Replace sk*
Swap the last two words before the with sm* to list directories in MB Display processes sorted by CPU
Esc + T top -ocpu -s 5 usage, updating every 5 seconds
cursor
Calculate your system's free disk
Ctrl + L Clear the screen df -h space top -o rsize Sort top by memory usage

Ctrl + C Kill whatever you're running Calculate free disk space in powers of Quit process with ID <PID>. You'll see
df -H 1,000 (as opposed to 1,024) kill PID PID as a column in the Activity
Ctrl + D Exit the current shell Monitor
Option + → Move cursor one word forward ps -ax | grep <appname> Find a process by name or PID
Option + ← Move cursor one word backward
Ctrl + F Move cursor one character forward File and Directory Management Network
Ctrl + B Move cursor one character backward mkdir <dir> Create new folder named <directory>
ping <host> Ping host and display status
Paste whatever was cut by the last mkdir -p <dir>/<dir> Create nested folders
Ctrl + Y command whois <domain> Output whois info for a domain
mkdir <dir1> <dir2> <dir3> Create several folders at once
Puts whatever you're running into a Download file via HTTP, HTTPS, or
Ctrl + Z Create a folder with a space in the curl -O <url/to/file> FTP
suspend background process mkdir "<dir>" filename
Ctrl + _ Undo the last command Establish SSH connection to <host>
Delete a folder (only works on empty ssh <username>@<host> with user <username>
rmdir <dir> folders)
scp <file><user>@<host>:/
rm -R <dir> Delete a folder and its contents remote/path Copy <file> to a remote <host>
Create a new file without any
Basics touch <file> extension
/ (Forward Slash) Top level directory
cp <file> <dir> Copy a file to the folder
Homebrew
. (Single Period) Current directory brew doctor Check brew for potential problems
cp <file> <newfile> Copy a file to the current folder
.. (Double Period) Parent directory brew install <formula> Install a formula
Copy a file to the folder and rename
~ (Tilde) Home directory cp <file>~/<dir>/<newfile> the copied file brew uninstall <formula> Uninstall a formula
Run command with the security Copy a folder to a new folder with brew list List all the installed formulas
sudo [command] privileges of the super user cp -R <dir> <"new dir"> spaces in the filename
brew search Display available formulas for brewing
nano [file] Opens the Terminal editor Prompts you before copying a file
cp -i <file><dir> with a warning overwrite message Upgrade all outdated and unpinned
open [file] Opens a file brew upgrade brews
cp <file1> <file2> <file3>/
[command] -h Get help about a command Copy multiple files to a folder Fetch latest version of homebrew and
Users/<dir> brew update
Show the help manual of the formula
man [command] Delete a file (This deletes the file
command rm <file> Remove older version of installed
permanently; use with caution.) brew cleanup formula
Delete a file only when you give
rm -i <file> confirmation brew tap homebrew/cask Tap the cask repository from GitHub
Change Directory
rm -f <file> Force removal without confirmation brew cask list List all installed casks
cd Home directory
brew cask install <cask> Install the given cask
cd [folder] Change directory, e.g. cd Documents Delete multiple files without any
rm <file1> <file2> <file3> confirmation brew cask uninstall <cask> Uninstall the given cask
cd ~ Home directory
mv <file> <newfilename> Move/rename
cd/ Root of the drive
Move a file to the folder, possibly by
Previous directory or folder you last mv <file> <dir>
cd - overwriting an existing file
browsed Search
Optional -i flag to warn you before
pwd Show your working directory mv -i <file> <dir> Find all files named <file> inside <dir>.
overwriting the file
cd.. Move up to the parent directory find <dir> -name <"file"> Use wildcards (*) to search for parts
Move all PNG files from current folder of filenames
cd../.. Move up two levels mv *.png ~/<dir> to a different folder
Output all occurrences of <text>
grep "<text>" <file> inside <file> (add -i for case
insensitivity)
Command History
Search for all files containing <text>
List Directory Contents Search through previously used grep -rl "<text>" <dir> inside <dir>
Ctrl + R commands
Display the name of files and
ls subdirectories in the directory Shows the previous commands
Force multi-column output of the history n you've typed. Add a number to limit to Output
ls -C listing the last n items
cat <file> Output the content of <file>
List all entries including those with . Execute the last command typed that
ls -a ![value] starts with a value Output the contents of <file> using
(period) and ..(double period) less <file> the less command that supports
Output the list of files in one entry per !! Execute the last command typed pagination and more
ls -1 line format head <file> Output the first 10 lines of <file>
Display a / (slash) immediately after Appends the output of <cmd> to
each path that is a directory, * <cmd> > > <file> <file>
ls -F (asterisk) after executable programs Permissions
or scripts, and @ after a symbolic link <cmd> > <file> Direct the output of <cmd> into <file>
Display the default permission for a
ls -S Sort files or entries by size ls -ld home directory Direct the output of <cmd1> to
<cmd1> | <cmd2> <cmd2>
List in a long format. Includes file Display the read, write, and access
mode, owner and group name, date ls -ld/<dir> permission of a particular folder
ls -l and time file was modified, pathname,
Change the permission of a file to
and more chmod 755 <file> 755
List the files sorted by time modified
ls -lt Change the permission of a folder
(most recent first) chmod -R 600 <dir> (and its contents) to 600
Long listing with human readable file
ls -lh sizes in KB, MB, or GB

Copyright © 2020 MakeUseOf. For more cheat sheets, head over to www.makeuseof.com.

You might also like