Learning the Unix Operating System

Learning the Unix Operating SystemSearch this book
Previous: 1.1 Working in the UNIX EnvironmentChapter 1
Getting Started
Next: 1.3 Types of Commands
 

1.2 Syntax of UNIX Command Lines

UNIX command lines can be simple, one-word entries like the date command. 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:

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.

Let's look at a sample UNIX command. The ls command displays a list of files. It can be used with or without options and arguments. If you enter:

% ls

a list of filenames will be displayed on the screen. But if you enter:

% ls -l

there will be an entire line of information for each file. The -l 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, 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 in 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.


Previous: 1.1 Working in the UNIX EnvironmentLearning the Unix Operating SystemNext: 1.3 Types of Commands
1.1 Working in the UNIX EnvironmentBook Index1.3 Types of Commands

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System