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 17 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 && killall SystemUIServer

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 delete 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. 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

9. 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

10. 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

11. 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.

12. 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.

13. 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:

defaults write NSGlobalDomain 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:

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool TRUE

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

14. 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

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

15. 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.

16. 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 LoginwindowText

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
Suspend 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

Basics

Command Action
/
Root directory
.
Current working directory
..
Parent of the current working directory
~
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
exit
End your current shell session

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
Show 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
Show all file and subdirectory names in the current directory
ls -C
Show listing in forced multi-column
ls -a
List all entries including . and .. directories
ls -1
Show file list in single-entry per line format
ls -F
Organize output with a slash / after directory paths, asterisk * after programs and scripts, at @ after symbolic links
ls -S
Organize 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 contents including any hidden files

File Size and Disk Space

Command Action
du
List showing the usage of every subdirectory and its contents
df -h
Display your system free disk space
df -H
Display your system free disk space in powers of 1,000 instead of 1,024
du -sh [folder]
Display a human-readable output of a directory files
du -s
List entries for specific files
du -sk * | sort -nr
Display all files and folders with total size including subfolders in KB; use sm instead of sk to get directory size in MB

File and Directory Management

Command Action
mkdir <dir>
Generate a new folder with name <dir>
mkdir -p <dir>/<dir>
Generate nested folders
mkdir <dir1> <dir2> <dir3>
Make several folders at once, without nesting
mkdir "<dir>"
Generate a folder with a space in the file name
rmdir <dir>
Delete an empty folder; doesn't work for folders with contents
rm -R <dir>
Delete both a folder and its contents
touch <file>
Generate new file without specifying an extension
cp <file> <dir>
Duplicate a file to a specified folder
cp <file> <newfile>
Duplicate a file to the current folder in use
cp <file> ~/<dir>/<newfile>
Duplicate and rename a file to a specified folder
cp -R <dir> "<new dir>"
Duplicate a folder to a new, specified folder when there are spaces in the filename
cp -i <file> <dir>
Provide a warning prompt before copying a file regarding overwrite
cp <file1> <file2> <file3> /Users/<dir>
Duplicate multiple files to a single folder
ditto -V [folder path] [new folder]
Duplicate a folder contents to a new specified folder V prints a line status for all the copied files
rm <file>
Delete permanently a file: be cautious when using this command
rm -i <file>
Ask for confirmation before deleting a file
rm -f <file>
Remove forcibly a files without needing confirmation
rm <file1> <file2> <file3>
Delete several files at once without needing confirmation
mv <file> <newfilename>
Move a file location and rename it
mv <file> <dir>
Relocate a file to a new folder; allows possible overwrite of existing files
mv -i <file> <dir>
Add an optional -i flag warning before file overwrites
mv *.png ~/<dir>
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
Show a home directory default permissions
ls -ld <dir>
Show a folder permissions for read, write and access
chmod 755 <file>
Revise a file permission to 755
chmod -R 600 <dir>
Revise both a folder and its contents permission to 600
chown <user>:<group> <file>
Change a file ownership to a new user and group; the addition of -R will include the folder contents in the change

Processes

Command Action
ps -ax
Display currently running processes; a display processes from all users; x display processes disconnected with the Terminal
ps -aux
Display processes with %cpu, %mem, page in, PID and command
top
Show 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
Display a list of processes sorted by memory usage
kill PID
Quit all processes with the ID PID; view PID as a column in the Activity Monitor
ps -ax | grep <appname>
Locate processes by name or PID

Network

Command Action
ping <host>
Ping the display status and host
whois <domain>
Show the whois for a specified domain
curl -O <url/to/file>
Download a selected file with HTTP, HTTPS or FTP
ssh <username>@<host>
Create a SSH connection from a specified host with a user designated with username
scp <file> <user>@<host>:/remote/path
Copy a specified file to a remote host
arp -a
Display a list of your local network devices with IP and MAC addresses
ifconfig en0
Display your own device IP and MAC address
traceroute [hostname]
See the path and hops when packets traverse from your device to a designated address

Homebrew

Command Action
brew doctor
Review the homebrew for potential issues
brew help
Display a list of useful formula and cask commands for homebrew
brew install <formula>|<cask>
Install a homebrew formula or cask
brew uninstall <formula>|<cask>
Uninstall a homebrew formula or cask
brew list --formula
Display a list of the installed formula and nothing else
brew list --cask
Display a list of the installed cask and nothing else
brew deps <formula>|<cask>
Display a list of a formula or cask dependencies
brew search text|/regex/
Use regex to search for formula or cask
brew upgrade <formula>|<cask>
Perform upgrades for the specified formula or cask
brew outdated <formula>|<cask>
Perform a search for out-of-date formula or cask
brew outdated --formula
Perform a search for an outdated formula alone
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
brew unpin [installed_formula]
Unpin formula to upgrade a package
brew cleanup
Remove stale lock files and outdated packages for all formula and cask

Environment Variable or Path

Command Action
printenv
Show a list of the environment variables currently set and which are in current use
echo "Hello"
Specify something for the terminal to print and display
echo $PATH
Evaluate a PATH variable value that storing a list of directories and executables files
echo $PATH >path.txt
Export 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 <dir> -name "<file>"
Locate all specified files by name <file> within a certain directory <dir>; use * to search for parts of filenames
grep "<text>" <file>
Display an output of every occurrence of specified <text> within a certain <file>; use -i to ignore case sensitivity
grep -rl "<text>" <dir>
Locate any files containing specified <text> within a certain <dir>

Output

Command Action
cat <file>
Output all content of a specified <file>
less <file>
Use the less command to support pagination and other features when outputting contents of a specified <file>
head <file>
Output only the first ten lines of a specified <file>
<cmd> >> <file>
Add the output of a specified <cmd> to the <file>
<cmd> > <file>
Specify the output of <cmd> into a certain <file>
<cmd1> | <cmd2>
Specify the output from <cmd1> to <cmd2>

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 simply need to type the command in a window for entering commands in Commander One or 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) macOS 10.12 61.51MB of free space.
  • Version 3.5.2(3667). (23 Jan, 2023). Release notes
  • Category: Utilities