Using the Terminal in Big Sur

Behind the macOS desktop lies another element that’s usually hidden to most users: the Terminal. The Terminal is a command-line interface where you can control almost the entire OS. It’s powerful and complex at times but also an incredibly handy skill to learn.

Terminal Velocity

Before we begin to look at some Terminal commands it’s worth a quick look at what exactly the Terminal is. The macOS Terminal or Terminal Emulator to be exact, is a shell that enables you to gain text-based access to the operating system. Since macOS is a UNIX-based operating system, the Terminal will open a command-line interface where you can enter UNIX commands, create automated scripts and much more.

It can be daunting to those new to a command line and within it you could potentially crash the entire system but with care you can also unlock a whole new world of control beyond the eye-catching graphics of the desktop.

1 – To find the Terminal app, open LaunchPad and look to the Other icon – which is a group of apps. Click on Other and within this group you’ll find the Terminal app. Click it to open the Terminal on your desktop.

Terminal1

2 – The Terminal app window will look a little devoid of anything interesting at first but that’s only because it’s waiting for you to enter something amazing into it. However, before that, we can look at a few types of Terminal. Click on to the top menu bar: Shell > New Window and select Grass from the available options.

Terminal2

3 – The Grass Shell you’ve opened is still the Terminal, in that it’ll work in the same way as the original Terminal you opened in Step 1; but it’s using a different profile. Terminal profiles offer you better viewing options than simple black text on a white background. Some like the retro feel of a green background, for example. In short, it’s a personal thing.

Terminal3

4 – Let’s try a command. Begin by opening a Safari window. Now click the Terminal app window to bring it to the fore and inside it, enter:

killall Safari

Press Enter to execute the command and you’ll notice that the Safari app has been instantly shutdown.

Terminal4

5 – You can do things like copy files from one folder to another. For example, we’ve create two folders in the Downloads folder, called test1 & test2. In test1 we’ve placed several files and we want to copy them to folder test2:

ditto /Users/jamesgale/Downloads/test1 /Users/jamesgale/Downloads/test2

This command will copy the files from one folder to the other. The /jamesgale/ part is our username, so replace that with yours.

6 – Let’s try something else, how about watching an ASCII version of Star Wars in your Terminal? Before we begin, we need to install some software. Enter the following into the Terminal:

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

Press the Enter key and the Terminal will contact the website to download the Homebrew software. It may take some minutes, so be patient. When it’s finished, you’ll be returned to the command prompt.

7 – Once the process has finished you can clear the screen by entering: clear. This doesn’t delete anything, it just clears away the content so you can see better. Now we need to install Telnet, which is a text line-based communications tool. We can do that with the following line:

brew install telnet

Hit Enter and let the installation run.

8 – When the Telnet installation is done, clear the screen again, then enter:

telnet towel.blinkenlights.nl

Hit Enter once again and an ASCII version of Star Wars will begin to play.

9 – To close the Telnet session playing Star Wars, press the Ctrl + ] keys, then type quit. This will bring you back to the Terminal command prompt. Depending on what Terminal profile you’re using, the Telnet Star Wars content may look a little odd. Many users prefer the Pro Shell, at 80×24 window size.

10 – Needless to say there’s a lot you can do in the Terminal, such as downloading a file from the Internet without a browser:

cd ~/Downloads/

This will change your working directory to the Downloads folder. Then:

curl -O the URL of the file

Enter the name of the URL, such as: curl -O https://github.com/attreyabhatt/Space-Invaders-Pygame/blob/master/main.py


Top Terminal Commands

There are hundreds of macOS Terminal commands, some are extremely powerful and can restore your entire system, whereas others simply display a command-line calendar. Here’s some of the more commonly used commands you’re likely to come across.

A

afconvert – Used to convert audio files.

afinfo – Can display information of an audio file.

afplay – Can play an audio file.

alias – Used to create alias commands. For example, the clear command can be aliased to CLS.

awk – Used to find and replace text within a file or files.

B

basename – Can be used to convert a full pathname to a single filename

bash – A different type of Shell, the Bourne-Again SHell.

bg – Send a process to the background.

break – Used to exit from a For, While, Until or Select command loop within a script.

bzip2 – A compression tool to compress or decompress files and folders.

C

caffeinate – Used to prevent the system from going into Sleep mode.

cal – Displays a calendar in the command line.

cancel – Used top cancel all print jobs.

cat – Used to concatenate and display the contents of files.

chmod – Used to change access permissions on a file(s) or folder(s).

chroot – Used to run a command within a different root directory.

clear – Clears the Terminal screen.

cmp – Used to compare two files.

cp – Copy one or more files to another location.

cpio – Used to copy files to and from compressed archives.

curl – Used to transfer data from or to a server; to download files from the Internet.

cut – Divides a file into several parts.

D

date – Displays or allows change to the date and time.

dd – Used to duplicate disks, convert and copy files, clone disks.

df – Displays the available free disk space.

diff – Used to display the differences between two files.

ditto – Used top copy files and folders.

du – Used to estimate file space usage.

E

echo – Used to display text on the screen, usually in scripts.

env – Displays the system environment variables.

exit – Used to exit the current Terminal Shell.

export – Used to set a system environment variable.

F

fdisk – Very powerful command to partition, format and create disks.

fg – Send a job to the foreground.

find – Used to search for files.

for – A loop command used in scripts.

ftp – A tool used to transfer files to and from remote servers.

fuser – Lists the processes that have one or more files open.

G

goto – Used in scripts to jump from one label to another.

grep – Used to search files for lines that match a specific pattern.

gzip – Used to compress or decompress files into an archive.

H

halt – Used to stop and restart the operating system.

hash – Used to display and refresh the cached location of commands.

head – Can display the first lines of a file.

history – Lists the command history of the user.

I

id – Prints the user and group names.

ifconfig – Displays information about any connected networking device.

iostat – Reports on CPU usage and I/O stats.

iosnoop – Allows you to ‘snoop’ on I/O events as they happen.

J

jobs – Not Steve, but lists active jobs.

K

kextfind – Lists the macOS kernel extensions.

kickstart – Configures the Apple Remote Desktop feature.

kill – Used to kill a process or app using a specific PID.

killall – Kills a process or app by name, such as Safari.

L

last – Displays the last logins of users, local and remote.

less – Displays output one screen at a time.

ln – Used to make links between files in different locations on the hard drive.

locate – Used to find files.

logname – Displays the current login name.

login – Used to login to another computer.

logout – Used to exit a login shell.

lp – Used to print files.

ls – Used to list files within a folder.

lsof – Lists currently open files on the system.

M

man – When used in front of any command will display the command’s manual.

mdfind – Executes a command-line Spotlight search

mkdir – Used to create a new folder.

mkfile – Used to create a new file.

mount – Mounts a file system so you can view its contents.

mv – Move or rename files and folders.

N

nano – A simple command-line text editor.

nc – Used to read and write data across networks.

netstat – Used to show network stats.

O

open – Opens a file, folder, URL or application.

P

passwd – Used to modify a user’s password.

paste – Used to merge lines of files.

pbcopy – Used to copy data to the system clipboard.

ping – Used to send small data packets to remote network locations for testing.

pkill – Used to kill a process or application by its full or partial name.

pwd – Print Working Directory.

Q

quota – Displays your current disk usage and any limits.

R

rcp – Used to copy files between remote machines.

reboot – Used to restart, reboot, the system.

rm – Remove files.

rmdir – Removes folders.

S

say – Used to convert anything you type into speech.

screencapture – Can capture a screenshot to file or disk.

set – Sets a system environment variable.

shutdown – Used to shutdown or restart a Mac.

stop – Stops a job or process.

sudo – Executes a command as another user, usually as an administrator.

T

tar – An archiving tool.

top – Displays process information.

type – Used to describe a command.

U

umount – Unmounts a mounted device or virtual disk.

unalias – Unaliases any alias commands.

uname – Prints the kernel version, release and machine name.

until – Loop command used in scripts.

users – Displays the login names of current users.

V

vi – A simple command-line text editor.

W

w – Used to display who is logged in and what they’re doing.

wait – Used to wait for a process to complete.

wall – Write messages to other users.

write – Send a message to another user.

Z

zip – A compression and archive utility.

Find more guides like this in…

Ian Osborne

Ian has worked on computer and video games magazines since the legendary Crash and Zzap! 64 in the early Nineties, so he’s seen many changes over the years (including an expanding waistline and receding hairline). A lifelong Mac user, he bought his first Mac in the year 2000. It’s a testament to the resilience of the Mac that his mother is still using that computer to this very day.

Related Articles

Back to top button