• Aucun résultat trouvé

slc Utilities

Dans le document The UNIX (Page 47-72)

Basic Utilities

B. slc Utilities

Local vertical motions that would result in backing up over the first line of the document are ignored, As a result, the first line must not have any super-scripts.

Basic Utilities

NAME

comm - select or reject lines common to two sorted files

SYNOPSIS

comm[ -[123] Ifilelfile2 DESCRIPTION

The command comm reads filel and file2, which should be ordered in ASCII collating sequence [see SORT(BU_CMD)]. and produces a three-column output:

lines only in filel; lines only in file2; and lines in both files. The file name -means the standard input.

Flags 1. 2. or 3 suppress printing of the corresponding column. Thus comm -12 prints only the lines common to the two files; comm -23 prints only lines in the first file but not in the second; comm -123 is a no-op.

SEE ALSO

CMP(BU_CMD). DIFF(BU_CMD). SORT(BU_CMD). UNIQ(BU_CMD).

USAGE

General.

Basic Utilities specified files are respectively copied, linked, or moved to that directory.

cp

Basic Utilities

SEE ALSO

If target is a file, and its mode forbids writing, the mode is printed, and the user asked for a response; if the response begins with a y, (and the user is permitted) then the mv occurs. No questions are asked and the mv is done where permitted when the - f option is used or if the stan-dard input is not a terminal.

CPIO(BU_CMD), RM(BU_CMD), CHMOD(BU_CMD).

USAGE

General.

If filel and target lie on different file systems, mv may achieve the move by copying the file and deleting the original. In this case any linking relationship with other files is lost.

In will not link across file systems.

NAME destina-tion directory tree based upon the options described below.

Archives of text files created by c p i 0 are portable between implementations of UNIX System V.

The meanings of the available options are:

a Reset access times of input files after they have been copied. [When

c Write header information in ASCII character form for portability.

r Interactively rename files. If the user types a null line, the file is

Basic Utilities

1 Whenever possible, link files rather than copying them. Usable only with the -p option.

m Retain previous file modification ~ime. This option is ineffective on directories that are being copied.

f Copy in all files except those in patterns.

EXAMPLES

The first example below copies the contents of a directory into an archive; the second duplicates a directory hierarchy:

SEE ALSO

ls

I

cpio -oc >/dev/mt/Om cd olddir

find. -depth -print

I

cpio -pd1 newdir

AR(BU_CMD), FIND(BU_CMD), LS(BU_CMD), TAR(AU_CMD).

USAGE

General.

Only the super-user can copy special files.

Basic Utilities characters with special meaning to the command interpreter must be quoted.

Basic Utilities

specifies the local time-zone; therefore its value affects the conversion between the internal GMT clock and the local time.)

In the second form, if no argument is given, the current date and time are printed. (As above, the environment variable TZ specifies the local time-zone, and therefore its value affects the output.) If an argument beginning with + is given, the output of date is under the control of the user. The format for the output is similar to that .of the first argument to the printf routine [see PRINTF(BA_LIB»). All output fields are of fixed size (zero padded if necessary). Each field descriptor is preceded by "and will be replaced in the output by its corresponding value. A single "is encoded by"". All other characters are copied to the output without change. The string is always ter-minated with a newline character.

Field Descriptors:

n insert a newline character

t insert a tab character

EXAMPLE

date '+DATE: %m/%d/%y%nTIME: %H:%M:%S' generates the output:

DATE: 08/01/76 TIME: 14:45:05

SEE ALSO

PRINTF(BA_LlB).

USAGE

General.

Basic Utilities

It is a bad practice to change the date while the system is running multi-user.

Basic Utilities

NAME

df - report free disk space

SYNOPSIS

df I - t ) I file-system ••• )

DESCRIPTION

The command df prints out the free space (in 512-byte units) and the number of free file slots ("inodes") available for on-line file systems. The argument file-system may be specified either by device name (e.g., /dev/dsk/Os1) or by mounted directory name (e.g., /usr). If no file-system is specified, the free space on all of the mounted file file-systems is printed.

The - t option causes the total allocated space figures to be reported as well.

USAGE

General.

Basic Utilities

NAME

diff - differential file comparator

SYNOPSIS

d i f f ! -efbh !filel file2

DESCRIPTION

The command d i f f tells what lines must be changed in two files to bring them into agreement. If file! (file2) is -, the standard input is used. If file! (file2) is a directory, then a file in that directory with the name file2

(file]) is used. The normal output contains lines of these forms:

n 1 a n3, n4 n 1, n2 d n3 n1,n2c n3,n4

These lines resemble ed commands to convert file! into file2. The numbers after the letters pertain to file2. In fact, by exchanging a for d and reading backward one may ascertain equally how to convert file2 into file!. As in ed, identical pairs, where n 1 - n2 or n3 - n4, are abbreviated as a single number.

Following each of these lines come all the lines that are affected in the first file flagged by

<,

then all the lines that are affected in the second file ftagged by>.

The -b option causes trailing blanks (spaces and tabs) to be ignored and other strings of blanks to compare equal.

The -e option produces a script of a, c, and d commands for the editor ed, which will recreate file2 from file!.

The - f option produces a similar script, not useful with ed, in the opposite order.

Option -h does a fast, half-hearted job. It works only when changed stretches are short and well separated, but does work on files of unlimited length.

Options -e and - f are unavailable with the -h option.

SEE ALSO

CMP(BU _ CMD), COMM(BU _ CMD), ED(BU _ CMD).

ERRORS

Exit status is:

o

no differences some differences 2 errors

Basic Utilities

USAGE

General.

DIFF(BU _ CMD)

Editing scripts produced under the -e or - f option may be incorrect when dealing with lines consisting of a single period.

Basic Utilities

NAME

du - estimate file space usage

SYNOPSIS

du [ -ars I [file ••• I

DESCRIPTION

The command du gives an estimate, in 512-byte units, of the file space con-tained in all the specified files. Whenever a directory is named, all files within it are reported; sub-directories are traversed recursively. If no file is specified, the current directory is used.

The option -s causes only the grand total (for each of the specified files) to be given. The option -a causes a report to be generated for each file. With no options, a report is given for each directory only.

du is normally silent about directories that cannot be read, files that cannot be opened, etc. The - r option will cause d u to generate messages in such instances.

A file with two or more links is only counted once.

USAGE

General.

If the -a option is not used, non-directories given as arguments are not listed.

Files with holes in them may get an incorrect (high) estimate.

Basic Utllltle'

NAME

echo - echo arguments

SYNOPSIS

echo (arg I

DESCRIPTION

The command echo writes its arguments separated by blanks and ter-minated by a newline on the standard output. It also understands the follow-ing escape conventions.

'\b backspace

'\ c print arguments up to this point, without newline; ignore remainder of command line

,\f form-feed '\n newline '\ r carriage return

'\ t tab '\ v vertical tab '\ '\ backslash

'\On n must be a 1-, 2- or 3-digit octal number; specifies the corresponding ASCII character

SEE ALSO SH(BU_CMD).

USAGE

General.

The command echo is useful for producing diagnostics in command scripts and for sending known data into a pipe.

Arguments containing blanks and escape sequences must be enclosed in double quotes.

Basic Utilities of files in the current directory, and prohibits executing commands via I com-mand. Attempts to bypass these restrictions result in an error message.

Commands to e d have a simple and regular structure: zero, one, or two addresses followed by a single-character command, possibly followed by parameters to that command. These addresses specify one or more lines in the buffer. Every command that requires addresses has default addresses, so that the addresses can very often be omitted.

In general, only one command may appear on a line. Certain commands allow the input of text. This text is placed in the appropriate place in the buffer.

While ed is accepting text, it is said to be in input mode. In this mode, no commands are recognized; all input is merely collected. Input mode is left by typing a period ( • ) alone at the beginning of a line.

e d supports a limited form of regular-expression notation; regular expressions are used in addresses to specify lines and in some commands (e.g., s) to specify portions of a line that are to be substituted. A regular-expression (RE) specifies a set of character strings. A member of this set of strings is said to be matched by the RE. The REs allowed by ed are constructed as follows:

The following one-character-REs match a single character:

1.1 An ordinary character (not one of those discussed in 1.2 below) is a one-character-RE that matches itself.

1.2 A backslash (,\) followed by any special character is a one-character-RE that matches the special character itself. The special characters are:

The UNIX System User's Manual 53

Basic Utilities backslash, respectively), which are always special, except within square brackets ([ ]; see 1.4 below). one-character-RE that matches anyone character in that string. If, however, the first character of the string is a caret (A), the one-character-RE matches any character except newline and the remaining characters in the string. The A has this special meaning only if it

Basic Utilities

2.5 A RE enclosed between the character sequences \. ( and \.) is a RE that matches whatever the unadorned RE matches.

2.6 The expression \.n matches the same string of characters as was matched by an expression enclosed between \. ( and \.) earlier in the same RE. Here n is a digit; the sub-expression specified is that begin-ning with the n-th occurrence of \. ( counting from the left. For exam-ple, the expression A\.(.

* \. ) \.

1 $ matches a line consisting of two repeated appearances of the same string.

Finally, an entire-RE may be constrained to match only an initial segment or

The form Aentire-RE$ constrains the entire-RE to match the entire line.

The null RE (e.g., / /) is equivalent to the last RE encountered.

To understand addressing in ed it is necessary to know that at any time there is a current line. Generally speaking, the current line is the last line affected by a command; the exact effect on the current line is discussed under the description of each command. Addresses are constructed as follows:

1. The character . addresses the current line. continues up to and including the current line.

7. An address followed by a plus sign (+) or a minus sign (-) followed by a decimal number specifies that address plus (respectively minus) the indicated number of lines. The plus sign may be omitted.

Basic Utilities corresponding to the first address.

In the following list of ed commands, the default addresses are shown in

The change command deletes the addressed lines, then accepts input text that replaces these lines; • is left at the last line input, or, if there were none, at the first line that was not deleted.

Basic Utilities currently-remembered file-name to file; otherwise, it prints the currently-remembered file-name. invocation of G. Note that the commands input as part of the execution of the G command may address and affect any lines in the buffer. The G command can be terminated by an interrupt signal (ASCII DEL or BREAK).

Basic Utilities per line (including the newline character).

1.,.+1Ij few non-printing characters (e.g., tab, backspace) are represented by (hopefully) mnemonic overstrikes. All other non-printing characters are printed in octal, and long lines are folded. An 1 command may be

Basic Utilities command alternately turns this mode on and off; it is initially off.

The quit command causes ed to exit. read. Such a command is not remembered as the current file-name.

I. , .lslRElreplacementl or

I. ,.lsIRElreplacementlg or

I. ,.lsIRElreplacementln n - 1-512

The substitute command searches each addressed line for an occurrence of the specified RE. In each line in which a match is found, all (non-overlapped) matched strings are replaced by the replacement if the glo-bal replacement indicator 9 appears after the command. If the global indicator does not appear, only the first occurrence of the matched string is replaced. If a number n follows the command, only the n-th

Basic Utilities

replacement, the replacement used in the most recent substitute com-mand is used as the replacement in the current substitute comcom-mand.

Basic Utilities

I. + 11

An address alone on a line causes the addressed line to be printed. A newline alone is equivalent to . + 1 p; it is useful for stepping forward through the buffer.

If an interrupt signal (BREAK) is sent, e d prints a ? and returns to its com-mand level.

If the closing delimiter of a RE or of a replacement string (e.g., /) would be the last character before a newline, that delimiter may be omitted, in which case the addressed line is printed. The following pairs of commands are equivalent:

6/61/62 s/s1/s2/p g/s1 g/s1/p

?s1 ?61?

If changes have been made in the buffer since the last w command that wrote the entire buffer, ed warns the user if an attempt is made to destroy the edi-tor buffer via the e or q commands. It prints ? and allows the user to con-tinue editing. A second e or q command at this point will take effect. The - command-line option inhibits this feature.

ERRORS

? for command errors.

? file for an inaccessible file.

[see the hand H (help) commands for detailed explanations).

FILES

ed. hup work is saved here if the terminal is hung up.

SEE ALSO

GREP(BU _ CMD), SED(BU _ CMD), SH(BU _ CMD).

USAGE General.

A I command cannot be subject to a g or a v command.

The sequence 'n in a RE does not match a newline character.

If the editor input comes from a command file, for example:

ed file < ed-cmd-file

the editor exits at the first failure of a command in the command file.

Basic Utilities

CAVEATS

The option - will be replaced by -s, in order to conform to the syntax stan-dard. The old form of the option will continue to be accepted for some time.

Basic Utilities standard output. Terms of the expression must be separated by blanks. Char-acters special to the command interpreter must be escaped. Note that 0 is returned to indicate a zero value, rather than the null string. Strings contain-ing blanks or other special characters should be quoted. Integer-valued argu-ments may be preceded by a unary minus sign. integers, otherwise returns the result of a lexical comparison.

arg { +, - } arg

addition or subtraction of integer-valued arguments.

arg { \*, I, % } arg

multiplication, division, or remainder of the integer-valued arguments.

arg: arg

The matching operator: compares the first argument with the second argument which must be a regular expression. Regular expression syn-tax is the same as that of ed, except that all patterns are "anchored"

(i.e., begin with ") and, therefore, " is not a special character, in that context. Normally, the matching operator returns the number of charac-ters matched (0 on failure). Alternatively, the \ (. •• \) pattern symbols

Basic Utilities

expr Sa: ',*/\(,*\)'

\1

Sa

returns the last segment of a path name (i.e., file). Watch out for / alone as an argument: expr will take it as the division operator.

3. A better representation of example 2.

expr liSa : ',*1\(,*\)'

4.

Dans le document The UNIX (Page 47-72)

Documents relatifs