Syntax of a Unix Command Line
Unix
command lines can be simple, one-word entries such as the
date
command. They can also be more complex; you
may need to type more than the command or program name.[1]
A Unix command can have arguments. An argument can be an option or a filename. The general format for a Unix command line is:
command option(s) filename(s)
There isn’t a single set of rules for writing Unix commands and arguments, but these general rules work in most cases:
Enter commands in lowercase.
Options modify the way in which a command works. Options are often single letters prefixed with a dash (
-
, 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 most 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.Some commands also have options made from complete words or phrases and starting with two dashes, such as
--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.The argument
filename
is the name of a file you want to use. Most Unix programs also accept multiple filenames, separated by spaces or specified with wildcards (see Chapter 8). If you don’t enter a filename correctly, you may get a response such as "filename: no such file or directory” ...
Get Learning Unix for Mac OS X Panther now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.