The Shell
In order to use commands on a Macintosh, you’ll need a program that
reads and executes them. That program is called the
shell, which runs inside the Terminal and is OS X’s
command-line user interface.[3] You type a command and press Enter, and the shell runs
whatever program (or programs) you’ve requested. For example, to list the files in
your Documents folder, one per line,
you could execute the ls -1 command in
a shell:
➜ ls -1 ~/Documents
data.pdf
letter.txt
song.mp3A single command can also invoke several programs at the same time,
and even connect programs together so they interact. Here’s a command that
redirects the output of the preceding ls command to become the input of the wc program, which counts lines of text in a
file; the result is the number of lines printed by ls:
➜ ls -1 ~/Documents | wc -l
3telling you how many files are in your Documents folder. The vertical bar, called a
pipe, makes the connection between ls and wc.
A shell is actually a program itself, and OS X has several different ones: the Bourne shell, the Korn shell, the C shell, and others. This book focuses on a popular shell called bash, the Bourne-Again Shell, located in /bin/bash, which is the default for user accounts. However, all these shells have similar basic functions.
[3] The same shell is found on Linux systems, and on Windows PCs that run Cygwin.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access