Cookie
Electronic Team uses cookies to personalize your experience on our website. By continuing to use this site, you agree to our cookie policy. Click here to learn more.

Mac Terminal commands to improve your workflow

If you want to take control over your computer, learn how to open Terminal on Mac as well as how to execute commands in Mac Terminal then this article is right what you have been looking for.


We will try to provide you with all the necessary information about useful Mac Terminal commands, how to use Terminal on Mac, different tips and tricks when working with it as well as the best Terminal replacement Commander One.



Cloud management: key points and top tools

What is a Terminal on Mac

As it turned out, huge amounts of search queries concerning the topic “Terminal on Mac”, “Mac hacks Terminal” appear on the Internet almost every day. Moreover, many people want to find out how to run Terminal in the Apple operating system. As it is well known, a regular user has no reason to use or even open Terminal, an Apple Command Line interface application, but it’s worth a try because, in fact, it gives access to many tricks and shortcuts. So, let’s start.

It is a well - known fact that Apple has its own Mac Command Line interface, in which you can easily and quickly manage tasks than perform a normal and long process. However, its interface looks rather specific, especially if you do not have the technical knowledge or any clue how to use the Terminal on Mac. However, once you take a look at this useful application, you will surely like it. Who knows?

Terminal is a standard system utility for interacting with Mac using the Command Line. Linux has a similar management tool because both operating systems are Unix-like. In brief, all you need to know about the Terminal is that it is an application that allows you to control your computer using commands, besides that opens the possibility to work with locked functions, etc.

How to open Terminal on Mac

For the record, there are several ways to open Mac Terminal. Choose the one that meets your requirements the most.

Terminal window

1. How to open Command Line on Mac via the Dock

There is usually “Applications” shortcut on the Dock panel on macOS. Click on it and a list of all installed programs on your Mac will be open. Find and open the “Utilities” folder, inside you will find the “Terminal” app. Run it. Please note that in recent versions of Mac OS X, this shortcut is called Launchpad.

2. Opening Terminal through the Finder

Open Finder (in the Dock it is always on the left). In the left menu, select "Applications" and in the list of all programs that open, find the directory/folder "Utilities". Click on it and search for the application "Terminal.app" in it. Double-click the Terminal.

3. Opening Terminal on Mac through the Spotlight search bar

Hold down the Ctrl + Spacebar key combination at the same time. In the pop-up window, enter the word "Terminal". Once you have typed you will see the application you need, all you need is just click it.

4. Basic Terminal Mac shortcuts

  • Command (⌘) + T is used in order to open a new terminal window.
  • Command (⌘) + N is used in order to open a new tab in the terminal.
  • Command (⌘) + Shift + T is used to switch tabs back and forth.

Mac Terminal tricks you should know

Mac OS Terminal can do a lot, from moving a lot of files to changing preferences that we couldn't even think of. To demonstrate what Terminal can do, we have put together 11 really excellent tips and tricks that you might find useful.

1. Enable showing hidden files and folders

If you want to see all the folders and files hidden by the system, then run the following command in the Terminal: defaults write com.apple.finder AppleShowAllFiles -bool TRUE killall finder
Tip: To hide them back, change the value from TRUE to FALSE.

2. View the contents of any files

If you have a damaged file or you suspect that something else is hidden inside it, then you can force the Terminal to open it, despite the failure of normal applications, with the corresponding command: cat ~ / path / to / file
Be careful, if you try to open a photo or any other non-text document, you will see a wall of illegible characters.

3. Copy the contents of a folder from one location to another

Of course, you can just copy-paste the entire contents of the folder, but in cases where you need to simplify and / or automate this process, the following Mac Terminal command will help you: ditto -V ~ / source / folder / ~ / new / folder /

4. Changing the file format of screenshots

While using Terminal on Mac, you can change the format of screenshots from .PNG to any other, including PDF and JPG. defaults write com.apple.screencapture type jpg

5. Disable shadows in screenshots

Those who take a lot of screenshots and want nothing extra on them can turn off the drop shadow effect and leave only the window itself being shot. defaults write com.apple.screencapture disable-shadow -bool TRUE killall SystemUIServer

6. New names for screenshots

I absolutely do not like that boring and inconvenient format for the names of screenshots (“Screenshot date-time”), so below there will be a command that allows you to replace the word “Screenshot” with something more appropriate. defaults write com.apple.screencapture name "New name" killall SystemUIServer
By the way, to return the setting to the original name, you need to enter this: defaults write com.apple.screencapture name "" killall SystemUIServer

7. New folder for screenshots

By default, all screenshots are saved to your desktop, clogging up valuable space. To change this, simply enter the following command from the list of Useful Terminal commands: defaults write com.apple.screencapture location ~ / your / location / here killall SystemUIServer

8. Your own greeting in the login window

Using a special command, you can place your own message on the login screen. You might want to write something funny and original, or leave your phone number in case your Mac goes missing. sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Somebody told me there is a place where everything is better and everything's safe."

9. How long has my Mac been on?

When was the last time you have rebooted your computer? You can check this with a command in the Terminal: uptime

10. Disable sleep mode

Sometimes it becomes necessary to keep the Mac awake, for example, when downloading a torrent or creating a backup. While using Mac Terminal you can disable hibernation on your Mac by typing: caffeinate
Now your Mac will not fall asleep under any pretext.

Tip: For this command, you can specify the time (in seconds) after which the Mac will automatically go to sleep if it is inactive. caffeinate -u -t 5400

11. Start auto-restart when the Mac completely freezes

Of course, it also happens: for no reason at all, the Mac freezes and you have nothing left but a forced reboot. The following command forces OS X to reboot if it realizes that the system is not responding:
sudo systemsetup -setrestartfreeze on

12. Drag and drop folders and files to automatically generate paths

One trick that saves the most time and makes using Terminal easier is automatically generating paths. Working in the terminal, you need to enter custom file paths often. First, you have to locate the file or folder, then copy the file path into the terminal. It can take a long time, and it’s easy to make typos.

Instead, you can grab a file or folder and drag and drop it directly into the terminal window. This trick even works mid-command, so whenever you need a file or folder path, just grab the icon and generate it automatically when you drop it into Terminal.


13. Activate the type to talk feature

While automatically generating paths saves you a significant amount of time while working, the type-to-talk feature is mostly just for fun. When you type the “say” command, your Mac will repeat anything you type after it.

Mac has over 100 voices from which to pick. By adding a name to the command “say -v name” you can change the voice it uses to repeat the text you enter into the terminal. There are two ways to get the list of the names:

  • Use the “say -v ?” command to get a list of the voice names
  • Navigate to the Accessibility menu in System Preferences
    • - Select Speech in the lefthand menu list
    • - Open the System Voice drop-down menu
    • - Select Customize
    • - Browse the voice options available and pick your favorites

The say command recognizes periods and commas, but since the Return key executes any command, you have to type everything into a single line. Type out longer paragraphs of speech in a text document first, then copy and paste it into Terminal.


14. Repeat characters by holding down a single key

Those who use both Windows and Mac OS will notice slight differences in the keyboard functions for each operating system. It can take some adapting to the different keystroke responses of Mac. One of the most noticeable ones is holding a single key.

On macOS, holding down a single key reveals a number of variations of that character. In Windows, that same shortcut allows you to repeat that character for as long as you hold down the key.

Both are useful functions, but it’s only possible to repeat the spacebar key in macOS by holding it down in a text field. If you find you’re not using alternative characters very often (keep in mind you can always copy/paste them from Wikipedia as well), then you can permanently switch the function for Mac.

Open Terminal and type the following, and press Return to execute:
-g ApplePressAndHoldEnabled -bool FALSE

Quit any open applications and restart them for the change to take effect. If you change your mind later and want to go back to the alternate characters, you can enter the same command with TRUE instead of FALSE:
-g ApplePressAndHoldEnabed -bool TRUE

Remember to hit the Return key to execute the command once you have it entered.

15. Turn Text into an ASCII Banner

As a throwback to the early days of the internet, you can turn text into an ASCII banner using Terminal. ASCII art pre-dates the stylish art and graphics available now; it uses the American Standard Code for Information Interchange keyboard to create large graphics. It’s also incredibly easy to use the banner function in Terminal.

  • Launch Terminal from Utilities under Applications
  • Type: banner
  • Follow with the text you want to be displayed: banner your text goes here

ASCII banners default to 132 characters wide, which can look nonsensical on a computer screen. It’s easy to adjust the size of your banner using the width flag.

  • Type: banner -w 30 your text goes here

You can reduce the width of your ASCII art to any size or increase it if you want.

16. Watch Star Wars in ASCII

It should be no surprise that the MacOS programmers were fans of the sci-fi classic Star Wars. It’s possible to “watch” the first movie in the original trilogy, A New Hope, in ASCII. Use the command:
nc towel.blinkenlights.nl 23

You can watch the entire movie in ASCII art, with text captions of the dialogue. When you’re stuck in a boring meeting or on a flight without wi-fi, it’s a good distraction.

17. Customize a Login Window Message

Whether you spend a lot of time on the computer or just use one for fun, it’s nice when your devices feel customized to you. Using Terminal, you can create your own message for the login window of your computer or create one to use on a fleet of computers for work or school. The command line is:
$ sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Your message here"

Just log off your account or restart your computer, and the message will now greet you every time you log in to use your computer. If you want to change the message seasonally or remove it altogether, just use the command:
$ sudo defaults delete /Library/Preferences/com.apple.loginwindow

Using Terminal tricks is one way to get more computer savvy, have fun with the native features of macOS, and customize your computer to your preferences. Here’s a cheat sheet with the most commonly used Terminal commands and shortcuts.

Terminal Mac Commands List to improve productivity

Shortcuts

Command Action

Tab

Use auto-completion for file and folder names

Ctrl + A

Return to the start of the current line

Ctrl + E

Skip to the end of the current line

Ctrl + U

Delete the current line ahead of the cursor

Ctrl + K

Delete the current line behind the cursor

Ctrl + W

Clear the last word before the cursor

Ctrl + T

Exchange the two characters before the cursor

Esc + T

Exchange the two words before the cursor

Ctrl + L

Clear the entire screen

Ctrl + C

Stop what is currently running

Ctrl + D

Exit from the active shell

Option + →

Skip the cursor one word forward

Option + ←

Skip the cursor one word backward

Ctrl + F

Skip the cursor one character forward

Ctrl + B

Skip the cursor one character backward

Ctrl + Y

Paste cut text

Ctrl + Z

Suspends whatever is running in the background

Ctrl + _

Undo your last command

Option + Shift + Cmd + C

Copy selected text

Shift + Cmd + V

Paste the copied selection

exit

End your current shell session

Basics

Command Action

/ (Forward Slash)

Root directory

. (Single Period)

Current working directory

.. (Double Period)

Parent of the current working directory

~ (Tilde)

Home folder for the logged-in user

sudo [command]

Run current command using super user security privileges

nano [file]

Open the Terminal editor

open [file]

Open a specified file

[command] -h

Open help for a specific command

man [command]

Access the help manual for a specific command

Change Directory

Command Action

cd

Navigate from one directory to another

cd [folder]

Change the directory to a new specified folder

cd ~

Navigate to home directory of logged-in user

cd/

Navigate to the root directory

cd -

Navigate to the last directory you opened

pwd

Shows the current working directory

cd..

Navigate up to the parent of the current directory

cd../..

Navigate up two parent directors from the current

List Directory Contents

Command Action

ls

Shows all file and subdirectory names in the current directory

ls -C

Show listing in forced multi-column

ls -a

Lists all entries including (.) and (..) directories

ls -1

Show file list in single-entry per line format

ls -F

Organizes output with a slash (/) after directory paths, asterisk (*) after programs and scripts and at (@) after symbolic links

ls -S

Organizes files and entries by size

ls -l

Long-form list with: file owner, group name, mode, date, time, pathnames, and more.

ls -l /

Symbolic link list of the file system from the root

ls -lt

Files listed by time, with most recently modified first

ls -lh

Long-form list organized by human-readable file size in KB, MB, or GB

ls -lo

List organized by file names with file size, owner, and any flags

ls -la

Detailed list of a directory’s contents including any hidden files

File Size and Disk Space

Command Action

du

List showing the usage of every subdirectory and its contents

du -sh [folder]

Get a human readable output of the files in a directory

du -s

Show entries for every specified file

du -sk* | sort -nr

Displays a list of all files and folders with a total of the subfolder-included size in KB Use sm* instead of sk* to get directory size in MB

df -h

Display the free disk space on your system

df -H

Display your system’s free disk space in powers of 1,000 instead of 1,024

du -sh [folder]

Display a human-readable output of a directory’s files

du -s

List entries for specific files

du -sk* | sort -nr

Display all files and folders with total size including subfolders in KB Replace the sk* with sm* for size in MB

df -h

Display free disk space on your system

df -H

Display your system’s free disk space in powers of 1,000 instead of 1,024

File and Directory Management

Command Action

mkdir

Generate a new folder with name

mkdir -p

/

Generate nested folders

mkdir

Make several folders at once, without nesting

mkdir "

"

Generate a folder with a space in the file nae

rmdir

Delete an empty folder (won’t work for files with contents)

rm -R

Delete both a file and its contents

touch

Generate new file without specifying an extension

cp

Duplicate a file to a specified folder

cp

Duplicate a file to the current folder in use

cp ~/

/

Duplicate and rename a file to a specified folder

cp -R

<"new dir">

Duplicate a folder to a new, specified folder when there are spaces in the filename

cp -i

Provides a warning prompt before copying a file regarding overwrite

cp /Users/

Duplicate multiple files to a single folder

ditto -V [folder path][new folder]

Duplicate a folder’s contents to a new specified folder “V” prints a line status for all the copied files

rm

Permanently deletes a file: be cautious when using this command

rm -i

Asks for confirmation before deleting a file

rm -f

Forcibly removes a files without needing confirmation

rm

Delete several files at once without needing confirmation

mv

Move a file location and rename it

mv

Relocate a file to a new folder; allows possible overwrite of existing files

mv -i

Add an optional -i flag warning before file overwrites

mv *.png ~/

Relocate files with PNG extension from current folder to a new one

Command History

Command Action

Ctrl + R

Perform a search in prior commands

history n

Display prior typed commands. Add a value to n to limit the displayed items.

![value]

Execute last typed common that begins with a value

!!

Execute whatever command was typed last

Permissions

Command Action

ls -ld

Shows a home directory’s default permissions

ls -ld/

Shows a folder’s permissions for read, write, and access

chmod 755

Revise a file’s permission to 755

chmod -R 600

Revise both a folder and its contents permission to 600

chown :

Change a file’s ownership to a new user and group The addition of -R will include the folder’s contents in the change

Processes

Command Action

ps -ax

Displays currently running processes. a displays processes from all users x displays processes disconnected with the Terminal

ps -aux

Displays processes with %cpu, %mem, page in, PID, and command

top

Shows relevant live information about running processes

top -ocpu -s 5

Get an update every 5 seconds of processes sorted by CPU usage

top -o rsize

Displays a list of processes sorted by memory usage

kill PID

Quite all processes with the ID View PID as a column in the Activity Monitor

ps -ax | grep

Locate processes by name or PID

Network

Command Action

ping

Ping the display status and host

whois

Show the whois for a specified domain

curl -O

Download a selected file with HTTP, HTTPS, or FTP

ssh @

Create a SSH connection from a specified with a user designated with

scp @:/remote/path

Copy a specified to a remote

arp -a

Display a list of your local network’s devices with IP and MAC addresses

ifconfig en0

Display your own device’s IP and MAC address

traceroute [hostname]

When packets traverse from your device to a designated address, see the path and hops

Homebrew

Command Action

brew doctor

Review the homebrew for potential issues

brew help

Display a list of useful formula and cask commands for homebrews

brew install |

Installs a homebrew formula or cask

brew uninstall |cask>

Uninstall a homebrew formula or cask

brew list --formula

Display a list of the installed formulas and nothing else

brew list --cask

Display a list of the installed casks and nothing else

brew deps |

Display a list of a formula or cask’s dependencies

brew search text|/regex/

Use regex to search for formulas or casks

brew upgrade |

Perform upgrades for the specified formulas or casks

brew outdated |

Perform a search for out-of-date formula or casks

brew outdated --formula

Perform a search for an outdated formula alones

brew outdated --cask

Perform a search for an outdated cask alone

brew pin [installed_formula]

Add a pin to a formula to prevent an upgrade

Environment Variable or Path

Command Action

printenv

Shows a list of the environment variables currently set and which are in current use

$echo

Specify something for the terminal to print and display

echo $PATH

Evaluate a PATH variable value that’s storing a list of directories and executables files

echo $PATH >path.txt

Exports the current path directory to a text file

export PATH=$PATH:absolute/path to/program/

Restrict a program execution via terminal to your current session For regularly used programs, add the path to the shell configuration

Search

Command Action

find

-name <"file">

Locate all specified files by name, , within a certain directory,

Use * to search for parts of filenames

grep ""

Display an output of every occurrence of specified within a certain Use -i to ignore case sensitivity

grep -rl ""

Locate any files containing specified within a certain

Output

Command Action

cat

Output all content of a specified

less

Use the less command to support pagination and other features when outputting contents of a specified

head

Output only the first ten lines of a specified

> >

Adds the output of a specified to the

>

Specify the output of into a certain

|

Specify the output from one to a second

Commander One – great Terminal emulator for Mac

Price: $29.99
Free version: Download
Mac App Store version: Available here
Commander One

This FTP Terminal would be a cup of tea for those who want to keep everything under control and within reach. Commander One isn't just a decent Terminal emulator app for Mac but also a rather functional file manager. To execute Terminal commands Mac users need first of all to invoke Terminal in Commander One by pressing simultaneously the combination CTRL + O, and after that follow the above Mac Terminal commands cheat sheet.

Terminal window

Once everything is done, you can return to the previous mode of Commander One by pressing the mentioned above hotkey. Besides that, the app has a lot of other features that can surprise the user, such as copying, deleting, compressing and uncompressing files, connecting to FTP servers, mounting popular cloud storages as local drives, mounting MTP and iOS devices, viewing processes in the system, etc.

The most remarkable that is worth to be mentioned is the incredible speed at which the app performs all the actions.

Conclusion

Remember that Terminal is not a completely safe thing. An inexperienced user can do some kind of trouble. Before executing any Mac Terminal commands, check your knowledge with the Geeks on the Internet, do not take on excessive risk. This advice also applies to courageous people who want to roll back the Mac OS update without having enough information about the procedure.

However, we hope that this article was rather informative for you and you found something interesting in it.

Frequently Asked Questions


Terminal is an application that gives you access to the inner workings of a Mac through a command line interface (CLI). Using this application gives you the ability to make any changes to the operating system that are not available from the graphical user interface (GUI). Typically, it is not intended for the average client. Instead, it serves as a great tool for power users and developers.

Terminal.app is located in /Applications/Utilities/Terminal.app and can be found in different ways. To know more read the corresponding paragraph in the article.
There are several ways to access Terminal on Mac, namely via Spotlight, Launchpad (Dock), Finder. More information you can find in the corresponding paragraph in this article.
The command line begins with the name of the computer, followed by the name of the current directory - by default, the user's home directory opens, which is denoted by ~ (tilde) on Unix systems. This is followed by the username followed by the $ sign - an invitation to enter commands. All commands are entered after the $ sign and are written in bash language.
Find Terminal in the Mac menu bar. Click it and choose Quit Terminal from the menu. Or alternatively, you can press the Command+Q keys together.
- sudo - updates your command as administrator (superuser) and requires a password. Be careful though, as incorrect commands can damage macOS and require a fresh install.
Basic Terminal commands are the following:
  • cat - list the contents of a file or folder;
  • cd - like DOS, use this command to change directories;
  • cp - copy a file or folder;
  • defaults - this command changes the settings that are not specified in the settings;
  • ls - this command lists the contents of the directory;
  • mkdir - make a directory;
  • mv - move a file or folder;
  • nano - open the terminal editor;
  • ssh - short for Secure Shell, this command creates a secure encrypted connection between two hosts;
  • sudo - updates your command as an administrator (superuser) and requires a password.

Be careful though, as incorrect commands can damage macOS and require a fresh install.
Many users are satisfied with the capabilities of the built-in Terminal App on Mac, while others want more. In fact, there are many alternatives, we recommend you using Commander One, a decent Mac Terminal replacement with an impressive set of features.
Top choice

Commander One

  • Rank 4.7 based on 889+ users, Write a review
  • Requirements: Mac (Mac OS X) 58.68MB of free space.
  • Version 3.3(3508). (2 Sep, 2021). Release notes
  • Category: Other solutions