start page | rating of books | rating of authors | reviews | copyrights

Book HomeLearning UnixSearch this book

1.2. Syntax of Unix Command Lines

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.[4]

[4] The command can be the name of a Unix program (such as date), or it can be a command that's built into the shell (such as exit). You probably don't need to worry about this! You can read more precise definitions of these terms and others in Glossary.

A Unix command may or may not have arguments. An argument can be an option or a filename. The general format for Unix command lines is:

command option(s) filename(s)

There isn't a single set of rules for writing Unix commands and arguments, but you can use these general rules in most cases:

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 later chapters. This book's quick reference card has quick reminders.

Let's look at a sample Unix command. The ls program displays a list of files. You can use it with or without options and arguments. If you enter:

$ ls

you'll see a list of filenames. But if you enter:

$ ls -l

there'll be an entire line of information for each file. The –l option (a dash and a lowercase letter "L") changes the normal ls output to a 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, enter:

$ ls -l chap1

Many Unix commands have more than one option. For instance, ls has the –a (all) option for listing hidden files. You can use multiple options in either of these ways:

$ ls -a -l
$ ls -al

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."

1.2.1. Exercise: entering a few commands

The best way to get used to Unix is to enter some commands. To run a command, type the command and then press the RETURN key. Remember that almost all Unix commands are typed in lowercase.

Get today's date.

Enter date

List logged-in users.

Enter who

Obtain more information about users.

Enter who -u or finger or w

Find out who is at your terminal.

Enter who am i

Enter two commands in the same line.

Enter who am i;date

Mistype a command.

Enter woh

In this session, you've tried several simple commands and seen the results on the screen.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.