-->
Previous Table of Contents Next


Flags

If a command is to execute properly, you must present it to your shell in the proper fashion. The command name itself must be the first item on the line; it’s followed by any flags and parameters. Flags (sometimes called options) are single letters preceded by a hyphen (-) that modify the behavior of a command. For example, the list command, ls, simply lists the names of the files in the current directory in alphabetical order. By adding various flags, you can list the contents of a directory in many different ways. You can list files and all their attributes with the “long” flag, -l. This command takes the following form:


ls -l


See “Listing Files,” p. 318

-l is the flag. When you want to use more than one flag, simply string the flags together, as in ls -lF. The -F flag displays an asterisk (*) if the file is executable, an at sign (@) if the file is a symbolic link, and a slash (/) if the file is a subdirectory. The man page for every command usually lists all the modifying flags and their meanings before describing any parameters. Flags can also be listed separately; the shell parses them before passing them on to the program. For example, you can write the ls -lF command as ls -l -F.


NOTE:  Linux provides a popular feature—color highlighting. When you issue the ls command, Slackware Linux displays files in different colors depending on the file’s type. This allows you to quickly identify files that are executable, directories, or linked to other files located in other directories. Also, if you redirect the output from ls to a file, this file contains the control codes used to indicate color. The control codes’ information may cause problems with other programs, such as less, when used with this file. For Red Hat Linux, you must provide the —color flag to ls to get the same effect:

ls —color

One type of flag signals that the next parameter has some special meaning. For example, the -t flag in the sort command is used to indicate that the next character is a field separator. If you want to sort the /etc/passwd file, whose fields are separated by a colon (:), you can enter


sort -t: /etc/passwd

In the case of the sort command, the -t flag is needed only if the file uses a field separator other than the default. The default field separator is defined in the IFS (Inter Field Separator) environment variable. The shell uses the IFS variable to parse the command line so that the shell knows to use the standard field separator unless the -t flag indicates otherwise.

Parameters

Flags must be presented to the command before any other parameters. Parameters are strings separated by any of the characters defined in the IFS environment variable. The default string in IFS is a space, a tab, and a newline character. You can place any number of field-separator characters between parameters; when the shell parses the command line, it reduces these characters to one character before proceeding. For example, if a command is followed by three spaces, a tab character, and then the first parameter, the shell automatically reduces the three spaces and a tab to one tab character. Thus, the following line


command<space bar><space bar><space bar><Tab> parameter

becomes


command<Tab> parameter

Parameters are usually filenames or strings that tell the command to perform some function. If a parameter contains an embedded space, the string must be placed in quotation marks to prevent the shell from expanding it. The following command line contains two parameters; the shell attempts to find the word New in a file named York:


grep New York

If the intent is to find the string “New York” in the standard input, the command must be entered as


grep “New York”

In this case, the string “New York” is passed to the grep command as one parameter.

Performing Filename Matching

Most modern operating systems (including all versions of Linux and DOS) support the use of wild cards for file and string searches. Table 18.4 summarizes the filename completion characters, see wild cards otherwise known as wild cards.

Table 18.4 Filename Completion Characters

Character Meaning

* Represents any collection of characters except a period when it’s the first character in a filename. For example, the command cat sales* > allsales combines all files whose names begin with sales into a file named allsales.
? Represents a single character. For example, the command lp sales.9? prints a collection of files with names in the form of sales.yy, where yy represents a year in the nineties (such as sales.90, sales.91, and so on).
[] Represents a single character in a range. For example, the command rm sales.9[0-3] removes the collection of files with the names sales.90, sales.91, sales.92, and sales.93.


NOTE:  If you place a filename wild card or expression inside quotation marks, the filename expansion is suppressed during command-line parsing. For example, if you type ls *, you will get all files in the current directory. On the other hand, if you type ls “*”, you probably will get the file not found error message because you’re instructing ls to search for a file named *.


Previous Table of Contents Next