Apple Macs are not only popular for students, and simple people who need to use a computer, they are popular with power users who build apps and software that runs the world. This is because despite Macs looking like toys, underneath the hood is one of the most powerful and robust operating systems ever built. It is estimated that macOS has around 86 million lines of code.

To unleash the power, one of the main gateways is using the command line, which is wrapped in an application called Terminal. Here’s a basic guide on how to use it and why you should at least learn the basics of it.

Introduction: The Terminal

The Terminal app is Apple’s official application that runs a shell, a computer program that exposes macOS services to a human. Through this shell, you issue commands and the computer will faithfully execute them. Many kinds of shell programs are available in macOS, but this is beyond the scope of this article. What’s important is that you launch the Terminal app and you get a command prompt, which we call a shell.


The Terminal app can be found in Applications folder under Utilities

Alternatively, you can use Spotlight to get it for you.

To launch the terminal app, the easiest way to find it is to launch the Finder App, go to the Applications folder, then the Utilities folder, and double-click on the Terminal app. The other alternative is to bring up Spotlight and type terminal. Usually, the first suggestion would point to the terminal app.

Brief Background

There are two things I want to address. Why the app is called Terminal and why most developers are still using the command line despite advances in computer graphics where you can do everything with the click of a mouse.

A brief history lesson is that macOS, the operating system that runs all modern Macs is based on NextSTEP, an operating system that Steve Jobs runs before rejoining Apple. That NextSTEP OS is based on parts of operating systems that were a research project in well-known universities like Carnegie Mellon and Berkeley. And those research projects are based on the Unix operating system.


The PDP-11, the first computer that uses UNIX operating system. The typewriter like device in the red circle is called the Terminal, where you type in commands to the computer.

Why am I going back all the way in the late 1960s? Because all way back then, computers were the size of rooms, and having a display was very expensive. So they used something like a typewriter to send commands and the computer will send the results back by typing on the typewriter. That typewriter device is called a terminal.

Now we have that little history lesson out of the way, why do developers and power users still reply using text-based commands despite the power of the graphical user interface? Because text-based commands are more powerful if you know how to use them. File manipulation, for example, can be more useful since it’s easier to do pattern matching on the command line. For example, if you want to delete all files that begin with the letter ‘a’ and have of type jpg, you can type rm a*.jpg and you’ll be done. It’s clunkier to do it in the Finder app.

Another reason is that you can easily launch background services using the command line. You can run virtual computers, databases, network services, and many more in the background by using the right commands. Furthermore, it’s easier to connect to other computers to control them using the command line.

The Basics


The Terminal. Many great ideas are built from here.

Now let’s get down to basics. When you launch the Terminal app, you are presented with a shell. It’s a blinking cursor that is waiting for your next command. If no shell is present, just press⌘ + n together, and the terminal will bring out a new window. pressing ⌘ + n will make new tabs in your terminal window.

So the terminal is ready and waiting for your next command. What to do? That’s the next section.

Directory structure.

The operating system is organized by files and folders. In the Terminal, folders are separated by the / character. Just like the UNIX operating system, the main folder is the / folder, which usually is where you put your macOS. Your home folder resides in the /Users/<your username>. If you have other drives plugged into your Mac, they usually reside in the /Volumes/ folder.

File manipulation

The most basic thing to do in the terminal is file manipulation. The first command would be ls. Here it will list out your file at your current working directory. Here give it a go.

ls

To know your current working directory, use the pwd command.

pwd

To change directories, use the cd command to change directories.

cd /Users/<username>/Desktop

Now you can move around in your directories.

Running commands

The core concept of macOS is just like UNIX and its flavors, everything is treated like a file. That means there are three ways to handle a file: read, write, or execute the commands in the file. Coincidently, those three modes are present in the file system and you can check out the permissions on any file or folder by issuing this command

ls -l

The output will show, on each line, the file name and other details like when it was last modified, who owns the file, the size of the file, and what you can do with it.

To run commands, you just type the appropriate command and press enter. To find out what commands are available to you, the easiest way is to type the first letter of the command and press tab. The shell will bring out suggestions on what commands that is possible.

File Operations

One of the common things to do in the terminal is file manipulation, that is moving, copying, or deleting files. These are the most common commands that have to do with file manipulation:

* `ls` - list files
* `cp <source> <target>` - copy files, basically type `cp <source> <target>`
* `mv <source> <target>` - move files, same as a copy but the source will be deleted
* `rm <target>` - remove files. for folders, you need to do it recursively, as in going through each folder and deleting it manually. there's a cheat for this `rm -r <folder name>`
* `mkdir <folder name>` - create a directory
* `less <filename>` - read a file/directory. Press q to quit the program.
* `open <filename>` - opens a file. macOS will launch the default program and open the file. 

Getting Help

By convention, most programs would have a way of explaining how to run their commands. The common theme is adding flags the the program that you run. Usually, flags are denoted by -<letter> or --<word> keywords.

To get help with the program that you want to run, you can use the –help. Sometimes it will show an error and will give you a complete picture of available flags.

ls --help

For more detailed info about the program, we have the man pages or the command man. The way we use it is man <command name> and man will find the appropriate manual and display it using the less command. To get back to the terminal, you press q.

man ls

The command above will give you a detailed overview of the ls command and all the options that are available to that ls command.

Next Steps

Now you have the hang of it, there’s more to the command line than just manipulating files. You can run services like databases, other programs, and many more. We will update with a new article on how to do so.

Plug

Support this free website by visiting my Amazon affiliate links. Any purchase you make will give me a cut without any extra cost to you

BasePro
iPhonesiPhone 15 / iPhone 15 Plus (Renewed) - (Amazon)iPhone 15 Pro / iPhone 15 Pro Max (Renewed) - (Amazon)
WatchApple Watch SE (Amazon) / Apple Watch Series 9 (Amazon)Apple Watch Ultra 2 (Amazon)
AirPodsAirPods 3 (Amazon)AirPods Pro 2 (Amazon) / AirPods Max (Amazon)
iPadiPad 9 (Amazon) / iPad Mini (Amazon)iPad Air (Amazon) / iPad Pro M2 (Amazon)
LaptopsMacBook Air M3 (Amazon)MacBook Pro M3
DesktopMac Mini (Amazon) / iMac (Amazon)Mac Studio / Mac Pro
DisplaysStudio Display (Amazon)Pro Display XDR (Amazon)

Other Ecosystem Items