[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

System User's Guide: Operating System and Devices


Commands Overview

Some commands can be entered simply by typing one word. It is also possible to combine commands so that the output from one command becomes the input for another command. This is known as piping.

Flags further define the actions of commands. A flag is a modifier used with the command name on the command line, usually preceded by a dash.

Commands can also be grouped together and stored in a file. These are known as shell procedures or shell scripts. Instead of executing the commands individually, you execute the file that contains the commands. More information on scripts and procesures can be found in Creating and Running a Shell Script

To enter a command, type in the command name at the prompt, and press Enter.

$ CommandName

This section discusses:

Command Syntax

Although some commands can be entered by simply typing one word, other commands use flags and parameters. Each command has a syntax that designates the required and optional flags and parameters. The general format for a command is:

CommandName flag(s) parameter(s)

Some general rules about commands are:

Command Name

The first word of every command is the command name. Some commands only have a command name.

Command Flags

After the command name, there might be a number of flags. Flags are sometimes called options. A flag is set off by spaces or tabs and usually starts with a dash (-). Exceptions are ps, tar, and ar, which do not require a dash in front of some of the flags. Flags modify the operation of a command. For example, in the following command:

ls -a -F

ls is the command name and -a -F are the flags.

When a command uses flags, they come directly after the command name. Single-character flags in a command can be combined with one dash. For example, the previous command can also be written as:

ls -aF

There are some circumstances when a parameter actually begins with a dash (-). In this case, use the delimiter dash dash (--) before the parameter. The -- tells the command that whatever follows is not a flag but a parameter.

For example, if you wanted to create a directory named -tmp and you entered the following command:

mkdir -tmp

The system would display an error message similar to the following:

mkdir: Not a recognized flag: t
Usage: mkdir [-p] [-m mode] Directory ...

The correct way of entering the command is:

mkdir -- -tmp

Your new directory, -tmp, is now created.

Command Parameters

After the command name, there might be a number of flags, followed by parameters. Parameters are sometimes called arguments or operands. Parameters specify information the command needs in order to run. If you don't specify a parameter, the command might assume a default value. For example, in the following command:

ls -a temp

ls is the command name, -a is the flag, and temp is the parameter. This command displays all (-a) the files in the directory temp. In the following example:

ls -a

because no parameter is given, the default value is the current directory. In the following example:

ls temp mail

no flags are given, and temp and mail are parameters. In this case, temp and mail are two different directory names. The ls command will display all but the hidden files in each of these directories.

Whenever a parameter or option-argument is, or contains, a numeric value, the number is interpreted as a decimal integer, unless otherwise specified. Numerals in the range 0 to INT_MAX, as defined in /usr/include/sys/limits.h, are syntactically recognized as numeric values.

If a command you want to use accepts negative numbers as parameters or option-arguments, you can use numerals in the range INT_MIN to INT_MAX, both as defined in /usr/include/sys/limits.h. This does not necessarily mean that all numbers within that range are semantically correct. Some commands have a built-in specification permitting a smaller range of numbers, for example, some of the print commands. If an error is generated, the error message lets you know the value is out of the supported range, not that the command is syntactically incorrect.

Reading Usage Statements

Usage statements are another way to represent command syntax. Like syntax diagrams, usage statements tell you how to enter commands from the command line. Although usage statements provide the same type of syntax information as diagrams, they are not in diagram format. Rather, they consist of symbols such as brackets ([ ]), braces ({ }), and vertical bars (|). The following is a sample of a usage statement for the unget command:

unget-rSID ] [ -s ] [ -n ]  File ...

The conventions for bold and italics are the same as for syntax diagrams. The following additional conventions are used in the command usage statements:

Using Web-based System Manager

Web-based System Manager is a graphical user interface for managing the system, either from a locally attached display or remotely from another system or personal computer equipped with a web browser. You can start Web-based System Manager in a variety of ways:

Using the smit Command

The smit command is a tool you can use to run other commands. Command names entered as a parameter to the smit command might take you to a submenu or panel for that command. For example, smit lsuser takes you directly to List All Users, which lists the attributes of users on your system.

See the smit command in the AIX 5L Version 5.1 Commands Reference for the exact syntax.

Locating a Command or Program (whereis Command)

The whereis command locates the source, binary, and manuals sections for specified files. The command attempts to find the desired program from a list of standard locations.

To find files in the current directory that have no documentation, type:

whereis -m -u *

Press Enter.

To find all of the files that contain the name Mail, type:

whereis Mail

Press Enter.

The system displays information similar to the following:

Mail: /usr/bin/Mail /usr/lib/Mail.rc

See the whereis command in the AIX 5L Version 5.1 Commands Reference for the exact syntax.

Displaying Information about a Command (man Command)

The man command displays information on commands, subroutines, and files. The general format for the man command is:

man CommandName

To obtain information about the pg command, type:

man pg

Press Enter.

The system displays information similar to the following:

  pg Command
 
  Purpose
 
  Formats files to the display.
 
  Syntax
 
  pg [ - Number ] [ -c ] [ -e ] [ -f ] [ -n ] [ -p String ]
  [ -s ] [ +LineNumber | +/Pattern/ ] [ File ... ]
 
  Description
 
  The pg command reads a file name from the File parameter and
  writes the file to standard output one screen at a time. If you
  specify a - (dash) as the File parameter, or run the pg command
  without options, the pg command reads standard input. Each
  screen is followed by a prompt. If you press the Enter key,
  another page is displayed. Subcommands used with the pg command
  let you review or search in the file.

The information the man command provides can also be obtained using the InfoExplorer program.

See the man command in the AIX 5L Version 5.1 Commands Reference for the exact syntax.

Displaying the Function of a Command (whatis Command)

The whatis command looks up a given command, system call, library function, or special file name, as specified by the Command parameter, from a database you create using the catman -w command. The whatis command displays the header line from the manual section. You can then issue the man command to obtain additional information.

The whatis command is equivalent to using the man -f command.

To find out what the ls command does, type:

whatis ls 

Press Enter.

The system displays information similar to the following:

ls(1)  -Displays the contents of a directory.

See the whatis command in the AIX 5L Version 5.1 Commands Reference for the exact syntax.

Listing Previously Entered Commands (history Shell Command)

The history command is a Korn shell built-in that lists the last 16 commands entered. The Korn shell saves commands that you entered to a command history file, usually named $HOME/.sh_history. This saves time when you need to repeat a previous command.

By default, the Korn shell saves the text of the last 128 commands. The history file size (specified by the HISTSIZE environment variable) is not limited, although a very large history file size can cause the Korn shell to start up slowly.

Note: The history shell command is not the same history command used with the INed editor. Also note that the Bourne shell does not support command history.

For detailed information about shells, see "Chapter 11, Shells"

To list the previous commands you entered, at the prompt, type:

history

Press Enter.

The history command entered by itself lists the previous 16 commands entered. The system displays information similar to the following:

928   ls
929   mail
930   printenv MAILMSG
931   whereis Mail
932   whatis ls
933   cd /usr/include/sys
934   ls
935   man pg
936   cd
937   ls | pg
938   lscons
939   tty
940   ls *.txt
941   printenv MAILMSG
942   pwd
943   history

The listing first displays the position of the command in the $HOME/.sh_history file followed by the command.

To list the previous five commands, at the prompt, type:

history -5

Press Enter.

A listing similar to the following appears:

939   tty
940   ls *.txt
941   printenv MAILMSG
942   pwd
943   history
944   history -5

The history command followed by a number lists all the previous commands entered starting at that number.

To list the commands since 938, at the prompt, type:

history 938

Press Enter.

A listing similar to the following appears:

938   lscons
939   tty
940   ls *.txt
941   printenv MAILMSG
942   pwd
943   history
944   history -5
945   history 938

Repeating Commands Using the Shell history Command

Use the r Korn shell alias to repeat previous commands. Type r and press Enter, and you can specify the number or the first character or characters of the command.

If you want to list the displays currently available on the system, you would type lsdisp and press Enter at the prompt. The system returns the information to you on the screen. If you want the same information returned to you again, at the prompt, type:

r

Press Enter.

The system runs the most recently entered command again. In this example, the lsdisp command would run.

To repeat the ls *.txt command, at the prompt, type:

r ls

Press Enter.

The r Korn shell alias locates the most recent command that begins with the character or characters specified.

Substituting Strings Using the Shell history Command

You can also use the r Korn shell alias to modify a command before it is run. In this case, a substitution parameter of the form Old=New can be used to modify the command before it is run.

For example, if command line 940 is ls *.txt, and you want to run ls *.exe, at the prompt, type:

r txt=exe 940

Press Enter.

This runs command 940, substituting exe for txt.

For example, if the command on line 940 is the most recent command that starts with a lower-case letter l, you can also type:

r txt=exe l

Press Enter.

Note: Only the first occurrence of the Old string is replaced by the New string. Entering the r Korn shell alias without a specific command number or character does the substitution to the previous command entered.

Editing the Command History

Use the fc Korn shell built-in command to list or edit portions of the command history file. To select a portion of the file to edit or list, specify the number or the first character or characters of the command. You can specify a single command or range of commands.

If you do not specify an editor program as an argument to the fc Korn shell built-in command, the editor specified by the FCEDIT variable is used. If the FCEDIT variable is not defined, then the /usr/bin/ed editor is used. The edited command or commands are printed and run when you exit the editor. Use the printenv command to display the value of the FCEDIT variable.

For example, if you want to run the command:

cd /usr/tmp

which is very similar to command line 933, at the prompt type:

fc 933

Press Enter.

At this point, your default editor appears with the command line 933. You would change include/sys to tmp, and when you exit your editor, the edited command is run.

You can also specify the editor you want to use in the fc command.

For example, if you want to edit a command using the /usr/bin/vi editor, at the prompt, type:

fc -e vi 933

Press Enter.

At this point, the vi editor appears with the command line 933.

You can also specify a range of commands to edit.

For example, if you want to edit the commands 930 through 940, at the prompt, type:

fc 930 940

Press Enter.

At this point, your default editor appears with the command lines 930 through 940. When you exit the editor, all the commands that appear in your editor are run sequentially.

Creating a Command Alias (alias Shell Command)

An alias lets you create a shortcut name for a command, a file name, or any shell text. By using aliases, you save a lot of time when doing tasks you do frequently. The alias Korn shell built-in command defines a word as an alias for some command. You can use aliases to redefine built-in commands but not to redefine reserved words.

The first character of an alias name can be any printable character except the metacharacters. Any remaining characters must be the same as for a valid file name.

The format for creating an alias is:

alias Name=String

in which the Name parameter specifies the name of the alias and the String parameter specifies a string of characters. If String contains blank spaces, enclose it in quotation marks.

To create an alias for the command rm -i (prompts you before deleting files), at the prompt, type:

alias rm="/usr/bin/rm -i"

Press Enter.

In this example, whenever you type the command rm and press Enter, the actual command performed is /usr/bin/rm -i.

To create an alias for the command ls -alF | pg (displays detailed information of all the files in the current directory, including the invisible files; marks executable files with an * and directories with a /; and scrolls per screen), at the prompt, type:

alias dir="/usr/bin/ls -alF | pg"

Press Enter.

In this example, whenever you type the command dir and press Enter, the actual command performed is /usr/bin/ls -alF | pg.

To display all the aliases you have, at the prompt, type:

alias

Press Enter.

The system displays information similar to the following:

rm="/usr/bin/rm -i"
dir="/usr/bin/ls -alF | pg"

Working with Text-Formatting Commands

You can use text-formatting commands to work with text composed of the international extended character set used for European languages.

International Character Support in Text Formatting

The international extended character set provides the characters and symbols used in many European languages, as well as an ASCII subset composed of English-language characters, digits, and punctuation.

All characters in the European extended character set have ASCII forms. These forms can be used to represent the extended characters in input, or the characters can be entered directly with a device such as a keyboard that supports the European extended characters.

The following text-formatting commands support all international languages that use single-byte characters. These commands are located in /usr/bin. (The commands identified with an asterisk (*) support text processing for multibyte languages. For more information on multibyte languages, see Multibyte Character Support in Text Formatting.)

addbib*         hyphen          pic*             pstext
checkmm         ibm3812         ps4014           refer*
checknr*        ibm3816         ps630            roffbib*
col*            ibm5587G*       psbanne          soelim*
colcrt          ibm5585H-T*     psdit            sortbib*
deroff*         indxbib*        psplot           tbl*
enscript        lookbib*        psrev            troff*
eqn*            makedev*        psroff           vgrind
grap*           neqn*           psrv             xpreview*
hplj            nroff*

Text-formatting commands and macro packages not in the preceding list have not been enabled to process international characters.

Entering Extended Single-Byte Characters

If your input device supports characters from the European-language extended character set, you can enter them directly. Otherwise, use the following ASCII escape sequence form to represent these characters:

The form \[N], where N is the 2- or 4-digit hexadecimal code for the character.

Note: The NCesc form \<xx> is no longer supported.

Text containing extended characters is output according to the formatting conventions of the language in use. Characters that are not defined for the interface to a specific output device produce no output or error indication.

Although the names of the requests, macro packages, and commands are based on English, most of them can accept input (such as file names and parameters) containing characters in the European extended character set.

For the nroff and troff commands and their preprocessors, the command input must be ASCII, or an irrecoverable syntax error will result. International characters, either single-byte or multibyte, can be entered when enclosed within quotation marks and without other text to be formatted. For example, using macros from the pic command:

define foobar % SomeText %

After the define directive, the first name, foobar, must be ASCII. However, the replacement text, SomeText, can contain non-ASCII characters.

Multibyte Character Support in Text Formatting

Certain text-formatting commands can be used to process text for multibyte languages. These commands are identified with an asterisk (*) in the list under International Character Support in Text Formatting. Text-formatting commands not in the list have not been enabled to process international characters.

Entering Multibyte Characters

If supported by your input device, multibyte characters can be entered directly. Otherwise, you can enter any multibyte character in the ASCII form \[N], where N is the 2-, 4-, 6-, 7-, or 8-digit hexadecimal encoding for the character.

Although the names of the requests, macros, and commands are based on English, most of them can accept input (such as file names and parameters) containing any type of multibyte character.

If you are already familiar with using text-formatting commands with single-byte text, the following list summarizes characteristics that are noteworthy or unique to the multibyte locales:

As for the nroff and troff commands and their preprocessors, the command input must be ASCII, or a syntax error will result. International characters, either single-byte or multibyte, can be entered when enclosed within quotation marks and within other text to be formatted. For example, using macros from the pic command:

define foobar % SomeText %

After the define directive, the first name, foobar, must be ASCII. However, the replacement text, SomeText, can contain non-ASCII characters.

Related Information

Chapter 3, Commands and Processes

Processes Overview

Chapter 11, Shells

Korn Shell or POSIX Shell Commands

Bourne Shell


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]