The command-line interface or CLI gives you access to many tools.
Some achieve the same as the macOS interface but many others allow you to perform advanced
tasks.
This is Jeremy, and I'll introduce you to the command line in macOS.
If you are administering or managing Macs, there may come a time when you need to delve
into the command line.
The Terminal app is used to access the command line in macOS, and can be found in Applications
and Utilities.
For more than 10 years, bash was the default command-line interpreter for the Mac platform.
Starting with macOS Catalina, Z shell is the default for all newly created user accounts.
To keep things basic, Z shell is mostly compatible with bash but has some other features - like
enhanced tab completion - that are discussed in our video on using Terminal more effectively.
When a terminal windows first opens it displays some helpful information.
The title bar shows the current directory, or folder, login shell, and windows size.
In this case, my home folder, the z-shell, and 80 by 24 means this window can display
80 characters wide by 24 characters tall.
The text inside the window shows the user name of who is logged in, the host name of
the computer, and the current directory again.
Since the current directory is the logged in user's home folder, this is indicated by
the tilde character.
The last character is the percent sign, which is displayed for all users except the root
user.
For more information about the root user, check out our other command line interface
videos.
Let's compare the Finder and the command line side-by-side.
With a Finder window open, click Go in the menu bar and choose Computer, then select
your Mac's hard drive.
The Finder shows four folders in the top level or the root of the Macintosh HD.
Listing the same contents in Terminal with with ls space forward slash - where the forward
slash indicates the root level of the disk - we can see there are many more items visible
in the command line.
This is because the Finder hides items that are of no use to a user.
If they were visible, users may try to move or delete these files.
I'll enter full screen in Terminal and make the font size a little bigger so we can focus
on the command line.
Now, let's look at the structure of a command.
A command is a program that tells the computer to do something and has three parts - firstly
the command itself, like ls.
Second are options for the command.
An option can change the way a command is performed, and is preceded by a hyphen.
If I add a space after ls followed by hyphen l, this will list items in long format, which
expands the information returned.
The third part is an argument.
An argument indicates what to perform its actions on.
Using a forward slash to indicate the root directory will list all items in the root
directory in long format.
For most commands, more than one option can be strung together.
I'll type the same command, but this time include a capital T with the l option.
When used with the lowercase l option, this displays the complete time information for
each item, now including seconds and years.
It's important to note commands, options, and arguments are all case-sensitive - upper
and lowercase characters can have very different meanings.
Next, let's take a look at how to get some help in the command line.
Help comes in the form of manual pages.
To access manual pages, type man followed by the name of the command to look up.
I'm going to use the same command, ls.
Notice ls is the command to list directory contents.
Below that is a synopsis, or a summary of possible options and arguments, followed by
the description.
Scrolling is accomplished using the arrow keys to move one line at a time so I can see
more information.
Or, use the space bar to scroll down an entire page at a time.
Multitouch gestures in macOS allow for an even easier scrolling experience.
Simply swipe up or down with two fingers on a trackpad, or one finger on a Magic Mouse.
When you're ready to enter more commands, press the Q key to quit or exit out of a manual
page.
If you're just getting started with the command line, it's difficult to know what commands
are available.
The which command is used to find the path to commands.
For example, which ls shows the ls command can be found in the /bin directory.
Listing the contents of the /bin directory displays several more commands.
Then you can view their manual pages to learn more about each one.
Looks like the date command is used to display or set this computer's date and time.
I can search this manual page by pressing the forward slash key, and I'll search for
examples.
The first instance of my search term is highlighted and I'm instantly brought to that section.
But it looks like the actual examples are further down.
So I'll move down one line in the manual page, press the forward slash key, and then the
up arrow to pull up my previous search - press Return and now I'm at the section of this
manual page with example uses for the date command.
With more than a thousand commands, Terminal is an extremely powerful app for accessing
the CLI in macOS, so try finding some more helpful commands.
That's all for our introduction to the CLI.
Thanks for watching, and be sure to check out our other videos on the CLI and Terminal!