The Mac Terminal Commands Cheat Sheet

The Mac Terminal Commands Cheat Sheet

Here we can see, “The Mac Terminal Commands Cheat Sheet”

Our mega cheat sheet of Mac terminal commands provides an excellent reference for all the important orders you ought to know.

macOS is an intuitive OS, so you do not need to spend a lot of your time learning the basics; Knowing this, why do you have to learn and cash in on the Unix instruction available on your Mac? we’ve four good reasons:

— There are dozens of open source and freely available Unix-based apps. You do not need to spend money on these.

— When you’re having difficulty checking out files in Spotlight, you’ll address Unix search tools. They’re far more powerful than Spotlight.

— You can manage files, folders, and file archives automatically. Fixing a cron job will handle this automatically.

— It gives you more power and control over your system.

With numerous Mac commands, it’s often difficult to recollect and use all of them. So we’re here to assist with an in-depth cheat sheet of Mac Terminal commands you’ll use to unlock enhanced productivity on your system.

Launch the Terminal app from Applications > Utilities or look for it via Spotlight. Then you’ll start with a number of the powerful commands below.

The Mac Terminal Commands Cheat Sheet

Command

Action

Shortcuts

Tab

Auto-complete file and folder names

Ctrl + A

Go to the beginning of the line you’re currently typing on

Ctrl + E

Go to the end of the line you’re currently typing on

Ctrl + U

Clear the line before the cursor

Ctrl + K

Clear the line after the cursor

Ctrl + W

Delete the word before the cursor

Ctrl + T

Swap the last two characters before the cursor

Esc + T

Swap the last two words before the cursor

Ctrl + L

Clear the screen

Ctrl + C

Kill whatever you’re running

Ctrl + D

Exit the current shell

Option + →

Move cursor one word forward

Option + ←

Move cursor one word backward

Ctrl + F

Move cursor one character forward

Ctrl + B

Move cursor one character backward

Ctrl + Y

Paste whatever was cut by the last command

Ctrl + Z

Puts whatever you’re running into a suspended background process

Ctrl + _

Undo the last command

Basics

/ (Forward Slash)

Top level directory

. (Single Period)

Current directory

.. (Double Period)

Parent directory

~ (Tilde)

Home directory

sudo

Run command with the security privileges of the super user

nano

Opens the Terminal editor

open

Opens a file

-h

Get help about a command

man

Show the help manual of the command

Change Directory

cd

Home directory

cd

Change directory, e.g. cd Documents

cd ~

Home directory

cd/

Root of the drive

cd -

Previous directory or folder you last browsed

pwd

Show your working directory

cd..

Move up to the parent directory

cd../..

Move up two levels

List Directory Contents

ls

Display the name of files and subdirectories in the directory

ls -C

Force multi-column output of the listing

ls -a

List all entries including those with .(period) and ..(double period)

ls -1

Output the list of files in one entry per line format

ls -F

Display a / (slash) immediately after each path that is a directory, * (asterisk) after executable programs or scripts, and @ after a symbolic link

ls -S

Sort files or entries by size

ls -l

List in a long format. Includes file mode, owner and group name, date and time file was modified, pathname, and more

ls -lt

List the files sorted by time modified (most recent first)

ls -lh

Long listing with human readable file sizes in KB, MB, or GB

ls -lo

List the file names with size, owner, and flags

ls -la

List detailed directory contents, including hidden files

File Size and Disk Space

du

List usage for each subdirectory and its contents

du -sh

Human readable output of all files in a directory

du -s

Display an entry for each specified file

du -sk* | sort -nr

List files and folders, totaling the size including the subfolders. Replace sk* with sm* to list directories in MB

df -h

Calculate your system’s free disk space

df -H

Calculate free disk space in powers of 1,000 (as opposed to 1,024)

File and Directory Management

mkdir

Create new folder named

mkdir -p /

Create nested folders

mkdir

Create several folders at once

mkdir “”

Create a folder with a space in the filename

rmdir

Delete a folder (only works on empty folders)

rm -R

Delete a folder and its contents

touch

Create a new file without any extension

cp

Copy a file to the folder

cp

Copy a file to the current folder

cp ~//

Copy a file to the folder and rename the copied file

cp -R

Copy a folder to a new folder with spaces in the filename

cp -i

Prompts you before copying a file with a warning overwrite message

cp /Users/

Copy multiple files to a folder

rm

Delete a file (This deletes the file permanently; use with caution.)

rm -i

Delete a file only when you give confirmation

rm -f

Force removal without confirmation

rm

Delete multiple files without any confirmation

mv

Move/rename

mv

Move a file to the folder, possibly by overwriting an existing file

mv -i

Optional -i flag to warn you before overwriting the file

mv *.png ~/

Move all PNG files from current folder to a different folder

Command History

Ctrl + R

Search through previously used commands

history n

Shows the previous commands you’ve typed. Add a number to limit to the last n items

!

Execute the last command typed that starts with a value

!!

Execute the last command typed

Permissions

ls -ld

Display the default permission for a home directory

ls -ld/

Display the read, write, and access permission of a particular folder

chmod 755

Change the permission of a file to 755

chmod -R 600

Change the permission of a folder (and its contents) to 600

chown :

Change the ownership of a file to user and group. Add -R to include folder contents

Processes

ps -ax

Output currently running processes. Here, a shows processes from all users and x shows processes that are not connected with the Terminal

ps -aux

Shows all the processes with %cpu, %mem, page in, PID, and command

top

Display live information about currently running processes

top -ocpu -s 5

Display processes sorted by CPU usage, updating every 5 seconds

top -o rsize

Sort top by memory usage

kill PID

Quit process with ID . You’ll see PID as a column in the Activity Monitor

ps -ax | grep

Find a process by name or PID

Network

ping

Ping host and display status

whois

Output whois info for a domain

curl -O

Download file via HTTP, HTTPS, or FTP

ssh @

Establish SSH connection to with user

scp @:/remote/path

Copy to a remote

Homebrew

brew doctor

Check brew for potential problems

brew install

Install a formula

brew uninstall

Uninstall a formula

brew list

List all the installed formulas

brew search

Display available formulas for brewing

brew upgrade

Upgrade all outdated and unpinned brews

brew update

Fetch latest version of homebrew and formula

brew cleanup

Remove older version of installed formula

brew tap homebrew/cask

Tap the cask repository from GitHub

brew cask list

List all installed casks

brew cask install

Install the given cask

brew cask uninstall

Uninstall the given cask

Search

find -name

Find all files named inside . Use wildcards (*) to search for parts of filenames

grep “”

Output all occurrences of inside (add -i for case insensitivity)

grep -rl “”

Search for all files containing inside

Output

cat

Output the content of

less

Output the contents of using the less command that supports pagination and more

head

Output the first 10 lines of

> >

Appends the output of to

>

Direct the output of into

|

Direct the output of to

Next, Customize the Terminal

There are a lot of commands during this cheat sheet. But you do not need to learn all of them at once! Instead, pick a couple that integrates well together with your workflow and prevents the foremost time. Once you’ve mastered these commands, there’s still more to learn about the Terminal to reinforce your experience with it.

Conclusion

I hope you found this guide useful. If you’ve got any questions or comments, don’t hesitate to use the shape below.

User Questions:

- What are bash commands?

Bash (AKA Bourne Again Shell) may be a sort of interpreter that processes shell commands. A shell interpreter takes orders in plain text format and calls OS services to try to to something. For instance, the ls command lists the files and folders during a directory. Bash is that the improved version of sh (Bourne Shell).

Is the Mac terminal the same as Linux?

As you now know from my introductory article, macOS may be a flavor of UNIX, almost like Linux. But unlike Linux, macOS doesn’t support virtual terminals by default. So instead, you’ll use the Terminal app (/Applications/Utilities/Terminal) to get an instruction terminal and BASH shell. … All commands are case sensitive.

What does Terminal on Mac do?

The Mac Terminal may be an instruction system that will assist you in quickly take hold of your OS and make changes. Going to the Terminal app is straightforward — you’ll navigate via your Mac’s Finder or through Spotlight.

OSX Admin Cheat Sheet/Tutorial?

https://www.reddit.com/r/sysadmin/comments/1rbd2h/osx_admin_cheat_sheettutorial/

Tips for learning to use Terminal?

https://www.reddit.com/r/osx/comments/4gzo3a/tips_for_learning_to_use_terminal/