Cover | Table of Contents
-N
to open each one, and
-~
to cycle between them without removing your hands from the keyboard.
-N
to open each one, and
-~
to cycle between them without removing your hands from the keyboard.
-F
(select Find Panel from the Edit menu) and enter the specific
text.
-G
(Find Next) lets you search down the scroll buffer for the next
occurrence, and
-D
(Find Previous) lets you search up the scroll buffer for the previous
occurrence. You can also accomplish this by highlighting a passage,
entering
date command. They can also be
more complex; you may need to type more than the command or program
name.
command option(s) filename(s)
-
,
also called "hyphen" or
"minus") and set off by any number
of spaces or tabs. Multiple options in one command line can be set
off individually (such as -a -b). In some cases,
you can combine them after a single dash (such as
-ab), but most commands'
documentation doesn't tell you whether this will
work; you'll have to try it.
--delete or
--confirm-delete. When you enter a command line,
you can use this option style, the single-letter options (which each
start with a single dash), or both.
telnet and who (shown earlier
in this chapter), have arguments that aren't
filenames.
open command. For
instance, when you type open
/Applications/Chess.app at a shell prompt, the chess game
starts. It opens one or more windows on your screen. The program has
its own way to receive your commands—through menus and buttons
on its windows, for instance.
ftp at a shell prompt,
you'll see a new prompt from the
ftp
program.
Enter FTP commands to transfer files to and from remote systems. When
you enter the special command
quit
to quit the ftp
program, ftp will stop prompting you. Then
you'll get another shell prompt, where you can enter
other Unix commands.
jobs command to find the
program's name, then restart the program with
fg
or terminate it with
kill
.
less command to
display one "page" (a Terminal
window filled from top to bottom) of text at a time.
less, you can try a very similar program named
more. (In fact, the name less
is a play on the name of more, which came first.)
The syntax for less is:
less option(s) file(s)
less lets you move forward or backward in the
files by any number of pages or lines; you can also move back and
forth between two or more files specified on the command line. When
you invoke less, the first
"page" of the file appears. A
prompt appears at the bottom of the Terminal window, as in the
following example:
% less ch03
A file is the unit of storage in Unix, as in most other systems.
A file can hold anything: text (a report you're writing,
.
.
.
:
less
prompt is a colon
(:); although, for the first screenful,
less displays the file's name as
a prompt. The cursor sits to the right of this prompt as a signal for
you to enter a less command to tell
less what to do. To quit, type
q.
less, the prompt can
be customized. For example, using the -M starting
flag on the less command line makes the prompt
show the filename and your position in the file (as a percentage).
If
you want this to happen every time you use less,
you can set the LESS environment variable to
M (without a dash) in your shell setup file. See
Section 4.2.
less prompt. For instance, if you have the short
less prompt (a colon), you can enter
-M while less is running.
less responds "Long prompt (press
Return)," and for the rest of the session,
ls to see what's in the directory
and use wildcards to match files in it.
% maTab
mach_init mailq make makemap man
machine mailstat makedbm makepsres
mail mailstats makedepend malloc_history
% ma
i, for example—and then press Tab once more
to list only the mail-related commands.
/, which is reserved as the
separator between files and directories in a pathname. Filenames are
usually made of upper- and lowercase letters, numbers,
"." (dots), and
"_" (underscores). Other characters
(including spaces) are legal in a filename, but they can be hard to
use because the shell gives them special meanings. However, spaces
are a standard part of Macintosh file and folder names, so while we
recommend using only letters, numbers, dots, and underscore
characters for filenames, the reality is that you will have to figure
out how to work with the spaces in file and directory names. The
Finder, by contrast, dislikes colons (which it uses as a directory
separator, just as Unix uses the slash). If you display a file called
test:me in the Finder, the name is shown as
test/me instead.
") around the
argument or preface each space with a
backslash (\).
rm program, covered later in this
chapter, removes Unix files. To remove a file named a
confusing name, the first rm command in
the following snippet doesn't work, but the second
one does. Also note that you can escape spaces (that is, avoid having
the shell interpret them inappropriately) by using a backslash
character, as shown in the third example:
% ls -l
total 2
-rw-r--r-- 1 taylor staff 324 Feb 4 23:07 a confusing name
-rw-r--r-- 1 taylor staff 64 Feb 4 23:07 another odd name
% /, which is reserved as the
separator between files and directories in a pathname. Filenames are
usually made of upper- and lowercase letters, numbers,
"." (dots), and
"_" (underscores). Other characters
(including spaces) are legal in a filename, but they can be hard to
use because the shell gives them special meanings. However, spaces
are a standard part of Macintosh file and folder names, so while we
recommend using only letters, numbers, dots, and underscore
characters for filenames, the reality is that you will have to figure
out how to work with the spaces in file and directory names. The
Finder, by contrast, dislikes colons (which it uses as a directory
separator, just as Unix uses the slash). If you display a file called
test:me in the Finder, the name is shown as
test/me instead.
") around the
argument or preface each space with a
backslash (\).
rm program, covered later in this
chapter, removes Unix files. To remove a file named a
confusing name, the first rm command in
the following snippet doesn't work, but the second
one does. Also note that you can escape spaces (that is, avoid having
the shell interpret them inappropriately) by using a backslash
character, as shown in the third example:
% ls -l total 2 -rw-r--r-- 1 taylor staff 324 Feb 4 23:07 a confusing name -rw-r--r-- 1 taylor staff 64 Feb 4 23:07 another odd name % rm a confusing name rm: a: no such file or directory rm: confusing: no such file or directory rm: name: no such file or directory %
* (asterisk), ? (question
mark), and [
] (square
brackets). When used in a file or directory name given as an argument
on a command line, the following is true:
*
ae* would match
aegis, aerie,
aeon, etc. if those files were in the same
directory. You can use this to save typing for a single filename (for
example, al* for
alphabet.txt) or to choose many files at once
(as in ae*). A * by itself
matches all file and subdirectory names in a directory, with the
exception of any starting with a period. To match all your dot files,
try .??*.
?
h?p matches
hop and hip, but not
help).
[]
[Cc]hapter would match either
Chapter or chapter, but
chap[12] would match chap1 or
chap2. Use a hyphen (-) to
separate a range of consecutive characters. For example,
chap[1-3] would match chap1,
chap2, or chap3.
% ls
chap10 chap2 chap5 cold
chap1a.old chap3.old chap6 haha
chap1b chap4 chap7 oldjunk
% open command within the Terminal to
launch the editor with the proper file already loaded. For example:
open -e myfile.txt.
cp and
CpMac commands: if you copy a file to a directory,
it automatically reuses the filename in the new location. This can
save lots of typing!
mkdir program. The syntax
is:
mkdir dirname(s)
% mkdir spy boston.dine
cp program when copying plain files and
directories. All other Macintosh files (that is, those with resource
forks) should be copied with CpMac (available only
if you have installed Apple's Mac OS X developer
CD).
cp program can put a copy of a file into the same
directory or into another directory.
set prompt="%/ %h% " setenv LESS 'eMq' alias desktop "cd /Users/taylor/Desktop" date
set
prompt tells
the shell to use a different prompt
than the standard one. We'll explain the details of
prompt setting in Section 4.2.1 later in this chapter.
setenvman
cmd. Start with man man
to learn more about the man system.
lpr, getting it to work
on OS X involves reconfiguring your system and a number of tricky
system administration tasks best avoided if you're
not a Unix expert.
atprint
for
AppleTalk-based printers, and
Print, a program that's supposed
to inject your print jobs into the regular Aqua print queue.
enscript for good results. Before
we cover printing itself, let's look at both
pr and enscript to see how they
work.
pr program does minor formatting of files on the
terminal screen or for a printer. For example, if you have a long
list of names in a file, you can format it onscreen into two or more
columns.
pr option(s) filename(s)
pr changes the format of the file only on the
screen or on the printed copy; it doesn't modify the
original file. Table 5-1 lists some
pr options.
atprint
for
AppleTalk-based printers, and
Print, a program that's supposed
to inject your print jobs into the regular Aqua print queue.
enscript for good results. Before
we cover printing itself, let's look at both
pr and enscript to see how they
work.
pr program does minor formatting of files on the
terminal screen or for a printer. For example, if you have a long
list of names in a file, you can format it onscreen into two or more
columns.
pr option(s) filename(s)
pr changes the format of the file only on the
screen or on the printed copy; it doesn't modify the
original file. Table 5-1 lists some
pr options.
|
Option
|
Description
|
|---|---|
-k
|
Produces
k columns of output |
-d
|
Double-spaces the output (may not work on all versions of
pr |
atprint
command, or use man atprint to learn how to
simplify your life considerably.
sudo
command to simply run the edit command as root:
% sudo vi /etc/printcap
lp|local line printer:\
:lp=/dev/lp:sd=/var/spool/output/lpd:lf=/var/log/lpd-errs:
less, and more do work together
in this way.) It also doesn't apply to graphical
programs, such as the Finder or Internet Explorer, that open their
own windows on your screen.
< (less-than symbol) operator. For example,
the
mail program (see Section 8.2.3 in Chapter 8) normally reads the message to send
from your keyboard. Here's how to use the input
redirection operator to count the number of lines in the file
to_do :
% wc -l < to_do
%
>)
operator. The pipe operator
(|) sends the standard output of one program to
the standard input of another program. Input/output redirection is
one of the most powerful and flexible Unix features.
< (less-than symbol) operator. For example,
the
mail program (see Section 8.2.3 in Chapter 8) normally reads the message to send
from your keyboard. Here's how to use the input
redirection operator to count the number of lines in the file
to_do :
% wc -l < to_do
%
>)
operator. The pipe operator
(|) sends the standard output of one program to
the standard input of another program. Input/output redirection is
one of the most powerful and flexible Unix features.
cat
, which is
short for "concatenate," reads files
and outputs their contents one after another, without stopping.
|) on the command line between two commands. When
a pipe is set up between two commands, the standard output of the
command to the left of the pipe symbol becomes the standard input of
the command to the right of the pipe symbol. Any two commands can
form a pipe as long as the first program writes to standard output
and the second program reads from standard input.
grep
program searches
a file or
files for lines that have a certain pattern. The syntax is:
grep "pattern" file(s)
ed (a Unix line editor) command
g/re/p, which means
"globally search for a regular
expression and print all matching lines containing
it." A regular
expression
is either some plain text (a word,
for example) and/or special characters used for pattern matching.
When you learn more about regular expressions, you can use them to
specify complex patterns of text.
grep is to look for a pattern
consisting of a single word. It can be used in a pipe so only those
lines of the input files containing a given string are sent to the
standard output. But let's start with an example
reading from files: searching all files in the working directory for
a word—say,