UNIX command lines can be simple, one-word entries like the date
They can also be more complex: you may need to type more than the command name.
A UNIX command may or may not have arguments
An argument can be an option or a filename.
The general format for UNIX commands is:
There isn't a single set of rules for writing UNIX commands and
arguments, but you can use these general rules in most cases:
Enter commands in lowercase.
modify the way in which a command works. Options are
often single letters prefixed with a dash (-) and set off by any
number of spaces or tabs. Multiple options in one command line can be
set off individually (like -a -b
), or, in some cases, you can
combine them after a single dash (like -ab
Some commands, including those on Linux systems, also have options
made from complete words or phrases, like --delete
. When you enter a command, you can
use this option style, the single-letter options (which all start
with a single dash), or both.
The argument filename
is the name of a file that you want to
use. If you don't enter a filename correctly, you may get the
: no such file or directory" or
: cannot open."
Some commands, like telnet
(shown earlier in this
chapter), have arguments that aren't filenames.
You must type spaces between commands, options, and filenames.
Options come before filenames.
Two or more commands can be written on the same command line, each separated by
a semicolon (
Commands entered this way are executed one after another by the shell.
UNIX has a lot of commands! Don't try to memorize all of them. In
fact, you'll probably need to know just a few commands and their
options. As time goes on, you'll learn these commands and the best
way to use them for your job. We cover some useful UNIX commands in
Let's look at a sample UNIX command.
command displays a list of files.
It can be used with or without options and arguments.
If you enter:
a list of filenames will be displayed on the screen.
But if you enter:
there will be an entire line of information for each file.
option (a dash and a lowercase letter "l") modifies the normal
output of the ls
command and lists files in the long format.
You can also get information about a particular file by using its name
as the second argument.
For example, to find out about a file called chap1
ls -l chap1
Many UNIX commands have more than one option. For instance, ls
has the -a
) option for listing hidden files. You
can use multiple options in either of these ways:
ls -a -l
You must type one space between the command name and the dash that
introduces the options.
If you enter ls-al
, the shell will say "ls-al: command not found."
The best way to get used to UNIX is to enter some commands.
To run a command, type in the command and then press the
Remember that almost all UNIX commands are typed in lowercase.
|Get today's date.
|List logged-in users.
|Obtain more information about users.
|Find out who is at your terminal.
who am i
|Enter two commands in the same line.
who am i;date
|Mistype a command.
In this session, you've tried several simple commands and seen the
results on the screen.