How to Use Mac Terminal Commands

How to Use Mac Terminal Commands

How to Use Mac Terminal Commands GA S REGULAR Menu Lifewire Tech for Humans Newsletter! Search Close GO Computers, Laptops & Tablets > Apple 30 30 people found this article helpful

How to Use Mac Terminal Commands

Your cheat sheet to boosting Mac productivity

By Dawna Roberts Dawna Roberts Writer University of Phoenix Dawna M. Roberts has 20+ years' experience in technology. Her works have appeared in Forbes, Huffington Post, Actiontec, Hackernoon, and other publications. lifewire's editorial guidelines Updated on April 21, 2021 Tweet Share Email Tweet Share Email

In This Article

Expand Jump to a Section What Is Mac Terminal, Anyway? How to Open Terminal Keyboard Shortcuts to Use With Terminal Working With Files and Folders Special Commands Control Permissions Network and Server Commands Bonus: Most Popular Commands If you are looking to get the most power out of your Mac, you need to embrace the Mac's terminal and learn some helpful terminal commands. Most users are fine using menus and the mouse to control settings, files, and folders, but if you want to get down under the hood of macOS, terminal can get you there quickly and get the job done.

What Is Mac Terminal

Mac terminal is an included program on macOS that allows you to use Unix commands (think DOS) to perform dozens of functions quickly and easily without any interference from the operating system. The technical term for it is a command-line interface (CLI). Using the terminal can be very powerful and efficient, but also dangerous. Be very careful when using terminal commands. If misused, you could end up deleting files and folders faster than you can react (to the point where you might need to restore it from a backup.) Terminal is sometimes compared to Windows command prompt program. They are similar; however terminal uses Unix commands to function. Windows uses its own command prompt language. Some users (think IT administrators and developers) use the terminal because it can be faster than the graphical interface most of us use and, the real kicker, it allows access to functions not available through the regular macOS interface. When using terminal commands, precision matters (including capitalization), so be careful of every character, even spaces.

How to Open Terminal Command Prompt on Mac

You can use terminal by opening Finder > Applications > Utilities > Terminal. A window will open, and you will see a command prompt ending with a $. The command line shown is ComputerName:CurrentDirectory ~Username$. At the top of the window, you will see the word Bash; it stands for 'Bourne again shell.' Bash is the language used for terminal on a Mac. You are ready to start typing commands. After every command, press the Return key to execute it. You can also copy and paste into the terminal window.

Keyboard Shortcuts to Use With Terminal

Tab Auto-completes files and folder names Ctrl + A Moves to the beginning of the line you are typing on Ctrl + E Moves to the end of the line you are typing on Ctrl + W Deletes the word before the cursor Ctrl + T Swaps the last two characters before the cursor Esc + T Swaps the last two words before the cursor Ctrl + L Clears the screen Ctrl + C Kills the current process Ctrl + R Search through previously used commands Option + Move the cursor one word forward Option + Move the cursor one word backward Ctrl + F Move the cursor one character forward Ctrl + B Move the cursor one character backward Ctrl + Y Paste whatever was cut by the last command Ctrl + _ Undo the last command Ctrl + D Exit the current shell

Working With Files and Folders

cd Shows your home directory cd Change to a specific directory cd ~ Home directory, e.g. ‘cd ~/folder/’ cd / Root of drive ls Shows a listing of all files in the current directory ls -C Sort files or entries by size ls -lt List the files sorted by time modified (most recent first) ls -l Shows a long listing of all files in the current directory. ls -a Listing including hidden files ls -lh Long listing with human readable file sizes ( KB, MB, or GB) ls -R Shows the entire contents of folder recursively top Displays the active processes. Press q to quit q Exit clear Clear the screen touch Create a new file with no extension pwd Full path to the working directory .. Parent directory ls -l .. Long listing of parent directory cd ../../ Move 2 levels up . Current folder cat The current folder rm Remove a file rm -i Remove with confirmation rm -r Remove a directory and its contents - Use with caution! rm -f Force a removal without confirmation rm -i Will display prompt before removal cp Copy a file to file cp Copy a file to a directory mv Move/Rename a file mkdir Create new directory named mkdir Create multiple directories at once mkdir -p / Create nested directories rmdir Remove an entire directory ( only works on empty directories ) find -name <"file"> Find all files named inside . Use wildcards (*) to search for partial filenames

Special Commands

sudo Run a command with the security privileges of super user nano Opens the Terminal editor open Opens a file -h Show help about a command man Show the help manual of the command

Control 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

Network and Server Commands

ping Ping a host and display its status whois Output WHOIS information about a domain curl -O Download a file via HTTP, HTTPS, or FTP ssh @ Establish an SSH connection to with user scp @:/remote/path Copy a to a remote

The Most Popular Mac Terminal Commands

As a bonus to our terminal cheat sheet, here are some of the most popular terminal commands to get the most out of your Mac.

Show Hide Hidden Files and Folders

There are times when you need to view hidden files and folders on a Mac, and there is a command for that. defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

To reverse the command above, change TRUE to FALSE.

Download Files From the Internet

To quickly download a file from the internet use the command below. curl -O URL of the file you want to download

Change the Default Location for Screen Shots

Not everyone wants their screenshots saved to the Desktop. With a single command, you can change where they go. defaults write com.apple.screencapture location path to folder where you want screenshots to be saved

Press Return. killall SystemUIServer

Press Return.

Change the Default File Type for Screenshots

If you want to change the default file type of screenshots, use the following command. defaults write com.apple.screencapture type JPG

Press Return. killall SystemUIServer

Press Return.

Delete All Files in a Folder

You can easily delete all files in a folder using a single command. However, be warned there is no undo button, once you press Return, the files are gone. rm -R foldername

You must include the entire path for the folder name.

Read the Manual

Bash has a complete manual built-in, and you can access the pages through terminal using the “man” command. For example, if you wanted to know how to use the cd command, you would type in: man cd

You can scroll through pages of the manual by pressing the spacebar. These are the most common commands, but there are thousands (you can even combine them into one series of commands) you can try in terminal to make your Mac experience more powerful and more enjoyable. But remember, there's a lot of power in these commands so make sure you type them in correctly. Was this page helpful? Thanks for letting us know! Get the Latest Tech News Delivered Every Day Subscribe Tell us why! Other Not enough details Hard to understand Submit More from Lifewire How to Delete a File in Terminal on Your Mac How to Make a Bootable Flash Installer of OS X or macOS How to Use the Netstat Command on Mac How to Show or Hide Hidden Files and Folders on Mac How to Turn off Mouse Acceleration on Mac View Hidden Files and Folders on Your Mac With Terminal DIRECTORY File (What It Is & How to Open One) What Is the Windows Terminal & How Does It Work? How to Install Android Debug Bridge (ADB) How to Open Command Prompt (Windows 11, 10, 8, 7, etc.) How to Delete Temporary Files in Windows WinDirStat Review (Free Disk Space Analyzer) What Is a Hidden File & Why Are Some Files Hidden? How to Block a Website XAR File (What It Is and How to Open One) How to Install and Setup BASH on Windows 10 Newsletter Sign Up Newsletter Sign Up Newsletter Sign Up Newsletter Sign Up Newsletter Sign Up By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookies Settings Accept All Cookies
Share:
0 comments

Comments (0)

Leave a Comment

Minimum 10 characters required

* All fields are required. Comments are moderated before appearing.

No comments yet. Be the first to comment!

How to Use Mac Terminal Commands | Trend Now | Trend Now