.
[coreutils.git] / doc / sh-utils.texi
blob82029e473adcd1fc71842a5d52adf2c6c371e021
1 \input texinfo
2 @c %**start of header
3 @setfilename sh-utils.info
4 @settitle GNU shell utilities
5 @c %**end of header
7 @include version.texi
9 @c Define new indices for file names and options.
10 @defcodeindex fl
11 @defcodeindex op
13 @c Put everything in one index (arbitrarily chosen to be the concept index).
14 @syncodeindex fl cp
15 @syncodeindex fn cp
16 @syncodeindex ky cp
17 @syncodeindex op cp
18 @syncodeindex pg cp
19 @syncodeindex vr cp
21 @set Francois Fran@,{c}ois
23 @ifinfo
24 @format
25 START-INFO-DIR-ENTRY
26 * Shell utilities: (sh-utils).          GNU shell utilities.
27 * basename: (sh-utils)basename invocation.      Strip directory and suffix.
28 * chroot: (sh-utils)chroot invocation.          Specify the root directory.
29 * date: (sh-utils)date invocation.              Print/set system date and time.
30 * dirname: (sh-utils)dirname invocation.        Strip non-directory suffix.
31 * echo: (sh-utils)echo invocation.              Print a line of text.
32 * env: (sh-utils)env invocation.                Modify the environment.
33 * expr: (sh-utils)expr invocation.              Evaluate expressions.
34 * factor: (sh-utils)factor invocation.          Print prime factors
35 * false: (sh-utils)false invocation.            Do nothing, unsuccessfully.
36 * groups: (sh-utils)groups invocation.          Print group names a user is in.
37 * hostname: (sh-utils)hostname invocation.      Print or set system name.
38 * id: (sh-utils)id invocation.                  Print real/effective uid/gid.
39 * logname: (sh-utils)logname invocation.        Print current login name.
40 * nice: (sh-utils)nice invocation.              Modify scheduling priority.
41 * nohup: (sh-utils)nohup invocation.            Immunize to hangups.
42 * pathchk: (sh-utils)pathchk invocation.        Check file name portability.
43 * printenv: (sh-utils)printenv invocation.      Print environment variables.
44 * printf: (sh-utils)printf invocation.          Format and print data.
45 * pwd: (sh-utils)pwd invocation.                Print working directory.
46 * seq: (sh-utils)seq invocation.                Print numeric sequences
47 * sleep: (sh-utils)sleep invocation.            Delay for a specified time.
48 * stty: (sh-utils)stty invocation.              Print/change terminal settings.
49 * su: (sh-utils)su invocation.                  Modify user and group id.
50 * tee: (sh-utils)tee invocation.                Redirect to multiple files.
51 * test: (sh-utils)test invocation.              File/string tests.
52 * true: (sh-utils)true invocation.              Do nothing, successfully.
53 * tty: (sh-utils)tty invocation.                Print terminal name.
54 * uname: (sh-utils)uname invocation.            Print system information.
55 * users: (sh-utils)users invocation.            Print current user names.
56 * who: (sh-utils)who invocation.                Print who is logged in.
57 * whoami: (sh-utils)whoami invocation.          Print effective user id.
58 * yes: (sh-utils)yes invocation.                Print a string indefinitely.
59 END-INFO-DIR-ENTRY
60 @end format
61 @end ifinfo
63 @ifinfo
64 This file documents the GNU shell utilities.
66 Copyright (C) 1994, 95, 96 Free Software Foundation, Inc.
68 Permission is granted to make and distribute verbatim copies of
69 this manual provided the copyright notice and this permission notice
70 are preserved on all copies.
72 @ignore
73 Permission is granted to process this file through TeX and print the
74 results, provided the printed document carries copying permission
75 notice identical to this one except for the removal of this paragraph
76 (this paragraph not being relevant to the printed manual).
78 @end ignore
79 Permission is granted to copy and distribute modified versions of this
80 manual under the conditions for verbatim copying, provided that the entire
81 resulting derived work is distributed under the terms of a permission
82 notice identical to this one.
84 Permission is granted to copy and distribute translations of this manual
85 into another language, under the above conditions for modified versions,
86 except that this permission notice may be stated in a translation approved
87 by the Foundation.
88 @end ifinfo
90 @titlepage
91 @title GNU @code{sh-utils}
92 @subtitle A set of shell utilities
93 @subtitle for version @value{VERSION}, @value{UPDATED}
94 @author David MacKenzie et al.
96 @page
97 @vskip 0pt plus 1filll
98 Copyright @copyright{} 1994, 95, 96 Free Software Foundation, Inc.
100 Permission is granted to make and distribute verbatim copies of
101 this manual provided the copyright notice and this permission notice
102 are preserved on all copies.
104 Permission is granted to copy and distribute modified versions of this
105 manual under the conditions for verbatim copying, provided that the entire
106 resulting derived work is distributed under the terms of a permission
107 notice identical to this one.
109 Permission is granted to copy and distribute translations of this manual
110 into another language, under the above conditions for modified versions,
111 except that this permission notice may be stated in a translation approved
112 by the Foundation.
113 @end titlepage
116 @ifinfo
117 @node Top
118 @top GNU shell utilities
120 @cindex shell utilities
121 @cindex utilities for shell programming
123 This manual documents version @value{VERSION} of the GNU shell utilities.
125 @menu
126 * Introduction::                Caveats, overview, and authors.
127 * Common options::              Common options.
129 * Date input formats::          Specifying date strings.
130 * Printing text::               echo printf yes
131 * Conditions::                  false true test expr
132 * Redirection::                 tee
133 * File name manipulation::      dirname basename pathchk
134 * Working context::             pwd stty printenv tty
135 * User information::            id logname whoami groups users who
136 * System context::              date uname hostname
137 * Modified command invocation:: chroot env nice nohup su
138 * Delaying::                    sleep
139 * Numeric operations::          factor seq
141 * Index::                       General index.
142 @end menu
143 @end ifinfo
146 @node Introduction
147 @chapter Introduction
149 @cindex introduction
151 First of all, this manual is incomplete.  The @code{stty} section, in
152 particular, needs substantial reorganization and additional explanatory
153 text before it will be up to the standard of other GNU manuals.
154 Explanatory text in general is lacking; the manual presently assumes you
155 pretty much know what to do, and just need to be reminded of how.  Thus,
156 if you are interested, please get involved in improving this manual.
157 The entire GNU community will benefit.
159 Some of these programs are useful only when writing shell scripts;
160 utilities like these are, in fact, the ``language'' of shell scripts (to
161 a great extent).  Others are occasionally useful interactively.
163 @cindex POSIX.2
164 The GNU shell utilities are mostly compatible with the POSIX.2 standard.
166 @c This paragraph appears in all of fileutils.texi, textutils.texi, and
167 @c sh-utils.texi too -- so be sure to keep them consistent.
168 @cindex bugs, reporting
169 Please report bugs to @samp{sh-utils-bugs@@gnu.ai.mit.edu}.  Remember
170 to include the version number, machine architecture, input files, and
171 any other information needed to reproduce the bug: your input, what you
172 expected, what you got, and why it is wrong.  Diffs are welcome, but
173 please include a description of the problem as well, since this is
174 sometimes difficult to infer. @xref{Bugs, , , gcc, GNU CC}.
176 @cindex history
177 @cindex MacKenzie, David
178 @cindex Meyering, Jim
179 @c Sorry, but the @value trick doesn't work with TeX in indexing
180 @c commands, and I don't want to fix it right now. --karl.
181 @cindex Pinard, @value{Francois}
182 @cindex Berry, Karl
183 @cindex Stallman, Richard
184 This manual was originally derived from the Unix man pages in the
185 distribution, which were written by David MacKenzie and updated by Jim
186 Meyering.  What you are reading now is the authoritative documentation
187 for these utilities;  the man pages are no longer being maintained.
188 @value{Francois} Pinard did the initial conversion to Texinfo format.
189 Karl Berry did the indexing, some reorganization, and editing of the results.
190 Richard Stallman contributed his usual invaluable insights to the
191 overall process.
194 @node Common options
195 @chapter Common options
197 @cindex common options
199 Certain options are available in all these programs.  Rather than
200 writing identical descriptions for each of the programs, they are
201 described here.  (In fact, every GNU program accepts (or should accept)
202 these options.)
204 Many of these programs take arbitrary strings as arguments.  In those
205 cases, @samp{--help} and @samp{--version} are taken as these options
206 only if there is one and exactly one command line argument.
208 @table @samp
210 @item --help
211 @opindex --help
212 @cindex help, online
213 Print a usage message listing all available options, then exit successfully.
215 @item --version
216 @opindex --version
217 @cindex version number, finding
218 Print the version number, then exit successfully.
220 @end table
223 @include getdate.texi
226 @node Printing text
227 @chapter Printing text
229 @cindex printing text, commands for
230 @cindex commands for printing text
232 This section describes commands that display text strings.
234 @menu
235 * echo invocation::             Print a line of text.
236 * printf invocation::           Format and print data.
237 * yes invocation::              Print a string until interrupted.
238 @end menu
241 @node echo invocation
242 @section @code{echo}: Print a line of text
244 @pindex echo
245 @cindex displaying text
246 @cindex printing text
247 @cindex text, displaying
248 @cindex arbitrary text, displaying
250 @code{echo} writes each given @var{string} to standard output, with a
251 space between each and a newline after the last one.  Synopsis:
253 @example
254 echo [@var{option}]@dots{} [@var{string}]@dots{}
255 @end example
257 The program accepts the following options.  Also see @ref{Common options}.
259 @table @samp
260 @item -n
261 @opindex -n
262 Do not output the trailing newline.
264 @item -e
265 @opindex -e
266 @cindex backslash escapes
267 Enable interpretation of the following backslash-escaped characters in
268 each @var{string}:
270 @table @samp
271 @item \a
272 alert (bell)
273 @item \b
274 backspace
275 @item \c
276 suppress trailing newline
277 @item \f
278 form feed
279 @item \n
280 new line
281 @item \r
282 carriage return
283 @item \t
284 horizontal tab
285 @item \v
286 vertical tab
287 @item \\
288 backslash
289 @item \@var{nnn}
290 the character whose ASCII code is @var{nnn} (octal); if @var{nnn} is not
291 a valid octal number, it is printed literally.
292 @end table
294 @end table
297 @node printf invocation
298 @section @code{printf}: Format and print data
300 @pindex printf
301 @code{printf} does formatted printing of text. Synopsis:
303 @example
304 printf @var{format} [@var{argument}]@dots{}
305 @end example
307 @code{printf} prints the @var{format} string, interpreting @samp{%}
308 directives and @samp{\} escapes in the same way as the C @code{printf}
309 function.  The @var{format} argument is re-used as necessary to convert
310 all of the given @var{argument}s.
312 @code{printf} has one additional directive, @samp{%b}, which prints its
313 argument string with @samp{\} escapes interpreted in the same way as in
314 the @var{format} string.
316 @kindex \0ooo
317 @kindex \0xhhh
318 @code{printf} interprets @samp{\0ooo} in @var{format} as an octal number
319 (if @var{ooo} is 0 to 3 octal digits) specifying a character to print,
320 and @samp{\xhhh} as a hexadecimal number (if @var{hhh} is 1 to 3 hex
321 digits) specifying a character to print.
323 @kindex \c
324 An additional escape, @samp{\c}, causes @code{printf} to produce no
325 further output.
327 The only options are a lone @samp{--help} or
328 @samp{--version}.  @xref{Common options}.
331 @node yes invocation
332 @section @code{yes}: Print a string until interrupted
334 @pindex yes
335 @cindex repeated output of a string
337 @code{yes} prints the command line arguments, separated by spaces and
338 followed by a newline, forever until it is killed.  If no arguments are
339 given, it prints @samp{y} followed by a newline forever until killed.
341 The only options are a lone @samp{--help} or @samp{--version}.
342 @xref{Common options}.
345 @node Conditions
346 @chapter Conditions
348 @cindex conditions
349 @cindex commands for exit status
350 @cindex exit status commands
352 This section describes commands that are primarily useful for their exit
353 status, rather than their output.  Thus, they are often used as the
354 condition of shell @code{if} statements, or as the last command in a
355 pipeline.
357 @menu
358 * false invocation::            Do nothing, unsuccessfully.
359 * true invocation::             Do nothing, successfully.
360 * test invocation::             Check file types and compare values.
361 * expr invocation::             Evaluate expressions.
362 @end menu
365 @node false invocation
366 @section @code{false}: Do nothing, unsuccessfully
368 @pindex false
370 @cindex exit status of @code{true}
371 @cindex failure exit status
372 @code{false} does nothing except return an exit status of 1, meaning
373 @dfn{failure}.  It can be used as a place holder in shell scripts
374 where an unsuccessful command is needed.
376 Any arguments are ignored, except for a lone @samp{--help} or
377 @samp{--version} (@pxref{Common options}).
380 @node true invocation
381 @section @code{true}: Do nothing, successfully
383 @pindex true
384 @cindex do nothing, successfully
385 @cindex no-op
386 @cindex successful exit
388 @cindex exit status of @code{true}
389 @code{true} does nothing except return an exit status of 0, meaning
390 @dfn{success}.  It can be used as a place holder in shell scripts
391 where a successful command is needed, although the shell built-in
392 command @code{:} (colon) may be faster.
394 Any arguments are ignored, except for a lone @samp{--help} or
395 @samp{--version} (@pxref{Common options}).
398 @node test invocation
399 @section @code{test}: Check file types and compare values
401 @pindex test
402 @cindex check file types
403 @cindex compare values
404 @cindex expression evaluation
406 @code{test} returns a status of 0 (true) or 1 (false) depending on the
407 evaluation of the conditional expression @var{expr}.  Each part of the
408 expression must be a separate argument.
410 @code{test} has file status checks, string operators, and numeric
411 comparison operators.
413 @cindex conflicts with shell built-ins
414 @cindex built-in shell commands, conflicts with
415 Because most shells have a built-in command by the same name, using the
416 unadorned command name in a script or interactively may get you
417 different functionality than that described here.
419 Besides the options below, @code{test} accepts a lone @samp{--help} or
420 @samp{--version}.  @xref{Common options}.  A single non-option argument
421 is also allowed: @code{test} returns true if the argument is not null.
423 @menu
424 * File type tests::             -[bcdfhLpSt]
425 * Access permission tests::     -[gkruwxOG]
426 * File characteristics tests::  -e -s -nt -ot -ef
427 * String tests::                -z -n = !=
428 * Numeric tests::               -eq -ne -lt -le -gt -ge
429 * Connectives for test::        ! -a -o
430 @end menu
433 @node File type tests
434 @subsection File type tests
436 @cindex file type tests
438 These options test for particular types of files.  (Everything's a file,
439 but not all files are the same!)
441 @table @samp
443 @item -b @var{file}
444 @opindex -b
445 @cindex block special check
446 True if @var{file} exists and is a block special device.
448 @item -c @var{file}
449 @opindex -c
450 @cindex character special check
451 True if @var{file} exists and is a character special device.
453 @item -d @var{file}
454 @opindex -d
455 @cindex directory check
456 True if @var{file} exists and is a directory.
458 @item -f @var{file}
459 @opindex -f
460 @cindex regular file check
461 True if @var{file} exists and is a regular file.
463 @item -h @var{file}
464 @itemx -L @var{file}
465 @opindex -L
466 @opindex -h
467 @cindex symbolic link check
468 True if @var{file} exists and is a symbolic link.
470 @item -p @var{file}
471 @opindex -p
472 @cindex named pipe check
473 True if @var{file} exists and is a named pipe.
475 @item -S @var{file}
476 @opindex -S
477 @cindex socket check
478 True if @var{file} exists and is a socket.
480 @item -t [@var{fd}]
481 @opindex -t
482 @cindex terminal check
483 True if @var{fd} is opened on a terminal.  If @var{fd} is omitted, it
484 defaults to 1 (standard output).
486 @end table
489 @node Access permission tests
490 @subsection Access permission tests
492 @cindex access permission tests
493 @cindex permission tests
495 These options test for particular access permissions.
497 @table @samp
499 @item -g @var{file}
500 @opindex -g
501 @cindex set-group-id check
502 True if @var{file} exists and has its set-group-id bit set.
504 @item -k @var{file}
505 @opindex -k
506 @cindex sticky bit check
507 True if @var{file} has its @dfn{sticky} bit set.
509 @item -r @var{file}
510 @opindex -r
511 @cindex readable file check
512 True if @var{file} exists and is readable.
514 @item -u @var{file}
515 @opindex -u
516 @cindex set-user-id check
517 True if @var{file} exists and has its set-user-id bit set.
519 @item -w @var{file}
520 @opindex -w
521 @cindex writable file check
522 True if @var{file} exists and is writable.
524 @item -x @var{file}
525 @opindex -x
526 @cindex executable file check
527 True if @var{file} exists and is executable.
529 @item -O @var{file}
530 @opindex -O
531 @cindex owned by effective uid check
532 True if @var{file} exists and is owned by the current effective user id.
534 @item -G @var{file}
535 @opindex -G
536 @cindex owned by effective gid check
537 True if @var{file} exists and is owned by the current effective group id.
539 @end table
541 @node File characteristics tests
542 @subsection File characteristics tests
544 @cindex file characteristics tests
546 These options test other file characteristics.
548 @table @samp
550 @item -e @var{file}
551 @opindex -e
552 @cindex existence-of-file check
553 True if @var{file} exists.
555 @item -s @var{file}
556 @opindex -s
557 @cindex nonempty file check
558 True if @var{file} exists and has a size greater than zero.
560 @item @var{file1} -nt @var{file2}
561 @opindex -nt
562 @cindex newer-than file check
563 True if @var{file1} is newer (according to modification date) than
564 @var{file2}.
566 @item @var{file1} -ot @var{file2}
567 @opindex -ot
568 @cindex older-than file check
569 True if @var{file1} is older (according to modification date) than
570 @var{file2}.
572 @item @var{file1} -ef @var{file2}
573 @opindex -ef
574 @cindex same file check
575 @cindex hard link check
576 True if @var{file1} and @var{file2} have the same device and inode
577 numbers, i.e., if they are hard links to each other.
579 @end table
582 @node String tests
583 @subsection String tests
585 @cindex string tests
587 These options test string characteristics.  Strings are not quoted for
588 @code{test}, though you may need to quote them to protect characters
589 with special meaning to the shell, e.g., spaces.
591 @table @samp
593 @item -z @var{string}
594 @opindex -z
595 @cindex zero-length string check
596 True if the length of @var{string} is zero.
598 @item -n @var{string}
599 @itemx @var{string}
600 @opindex -n
601 @cindex nonzero-length string check
602 True if the length of @var{string} is nonzero.
604 @item @var{string1} = @var{string2}
605 @opindex =
606 @cindex equal string check
607 True if the strings are equal.
609 @item @var{string1} != @var{string2}
610 @opindex !=
611 @cindex not-equal string check
612 True if the strings are not equal.
614 @end table
617 @node Numeric tests
618 @subsection Numeric tests
620 @cindex numeric tests
621 @cindex arithmetic tests
623 Numeric relationals.  The arguments must be entirely numeric (possibly
624 negative), or the special expression @w{@code{-l @var{string}}}, which
625 evaluates to the length of @var{string}.
627 @table @samp
629 @item @var{arg1} -eq @var{arg2}
630 @itemx @var{arg1} -ne @var{arg2}
631 @itemx @var{arg1} -lt @var{arg2}
632 @itemx @var{arg1} -le @var{arg2}
633 @itemx @var{arg1} -gt @var{arg2}
634 @itemx @var{arg1} -ge @var{arg2}
635 @opindex -eq
636 @opindex -ne
637 @opindex -lt
638 @opindex -le
639 @opindex -gt
640 @opindex -ge
641 These arithmetic binary operators return true if @var{arg1} is equal,
642 not-equal, less-than, less-than-or-equal, greater-than, or
643 greater-than-or-equal than @var{arg2}, respectively.
645 @end table
647 For example:
649 @example
650 test -1 -gt -2 && echo yes
651 @result{} yes
652 test -l abc -gt 1 && echo yes
653 @result{} yes
654 test 0x100 -eq 1
655 @error{} test: integer expression expected before -eq
656 @end example
659 @node Connectives for test
660 @subsection Connectives for @code{test}
662 @cindex logical connectives
663 @cindex connectives, logical
665 The usual logical connectives.
667 @table @samp
669 @item ! @var{expr}
670 @opindex !
671 True if @var{expr} is false.
673 @item @var{expr1} -a @var{expr2}
674 @opindex -a
675 @cindex logical and operator
676 @cindex and operator
677 True if both @var{expr1} and @var{expr2} are true.
679 @item @var{expr1} -o @var{expr2}
680 @opindex -o
681 @cindex logical or operator
682 @cindex or operator
683 True if either @var{expr1} or @var{expr2} is true.
685 @end table
688 @node expr invocation
689 @section @code{expr}: Evaluate expressions
691 @pindex expr
692 @cindex expression evaluation
693 @cindex evaluation of expressions
695 @code{expr} evaluates an expression and writes the result on standard
696 output.  Each token of the expression must be a separate argument.
698 Operands are either numbers or strings.  @code{expr} coerces
699 anything appearing in an operand position to an integer or a string
700 depending on the operation being applied to it.
702 Strings are not quoted for @code{expr} itself, though you may need to
703 quote them to protect characters with special meaning to the shell,
704 e.g., spaces.
706 @cindex parentheses for grouping
707 Operators may given as infix symbols or prefix keywords.  Parentheses
708 may be used for grouping in the usual manner (you must quote parentheses
709 to avoid the shell evaluating them, however).
711 @cindex exit status of @code{expr}
712 Exit status:
714 @display
715 0 if the expression is neither null nor 0,
716 1 if the expression is null or 0,
717 2 for invalid expressions.
718 @end display
720 @menu
721 * String expressions::          <colon> match substr index length quote
722 * Numeric expressions::         + - * / %
723 * Relations for expr::          | & < <= = == != >= >
724 * Examples of expr::            Examples.
725 @end menu
728 @node String expressions
729 @subsection String expressions
731 @cindex string expressions
732 @cindex expressions, string
734 @code{expr} supports pattern matching and other string operators.  These
735 have lower precedence than both the numeric and relational operators (in
736 the next sections).
738 @table @samp
740 @item @var{string} : @var{regex}
741 @cindex pattern matching
742 @cindex regular expression matching
743 @cindex matching patterns
744 Perform pattern matching.  The arguments are coerced to strings and the
745 second is considered to be a (basic, a la GNU @code{grep}) regular
746 expression, with a @code{^} implicitly prepended.  The first argument is
747 then matched against this regular expression.
749 If the match succeeds and @var{regex} uses @samp{\(} and @samp{\)}, the
750 @code{:} expression returns the part of @var{string} that matched the
751 subexpression; otherwise, it returns the number of characters matched.
753 If the match fails, the @code{:} operator returns the null string if
754 @samp{\(} and @samp{\)} are used in @var{regex}, otherwise 0.
756 @kindex \( @r{regexp operator}
757 Only the first @samp{\( @dots{} \)} pair is relevant to the return
758 value; additional pairs are meaningful only for grouping the regular
759 expression operators.
761 @kindex \+ @r{regexp operator}
762 @kindex \? @r{regexp operator}
763 @kindex \| @r{regexp operator}
764 In the regular expression, @code{\+}, @code{\?}, and @code{\|} are
765 operators which respectively match one or more, zero or one, or separate
766 alternatives.  SunOS and other @code{expr}'s treat these as regular
767 characters.  (POSIX allows either behavior.)
768 @xref{Top, , Regular Expression Library, regex, Regex}, for details of
769 regular expression syntax.  Some examples are in @ref{Examples of expr}.
771 @item match @var{string} @var{regex}
772 @findex match
773 An alternative way to do pattern matching.  This is the same as
774 @w{@samp{@var{string} : @var{regex}}}.
776 @item substr @var{string} @var{position} @var{length}
777 @findex substr
778 Returns the substring of @var{string} beginning at @var{position}
779 with length at most @var{length}.  If either @var{position} or
780 @var{length} is negative, zero, or non-numeric, returns the null string.
782 @item index @var{string} @var{charset}
783 @findex index
784 Returns the first position in @var{string} where the first character in
785 @var{charset} was found.  If no character in @var{charset} is found in
786 @var{string}, return 0.
788 @item length @var{string}
789 @findex length
790 Returns the length of @var{string}.
792 @item quote @var{token}
793 @findex quote
794 Interpret @var{token} as a string, even if it is a keyword like @var{match}
795 or an operator like @code{/}.
796 This makes it possible to test @code{expr length quote "$x"} or
797 @code{expr quote "$x" : '.*/\(.\)'} and have it do the right thing even if
798 the value of @var{$x} happens to be (for example) @code{/} or @code{index}.
799 This operator is a GNU extension.  It is disabled when
800 the environment variable @var{POSIXLY_CORRECT} is set.
802 @end table
804 To make @code{expr} interpret keywords as strings, you must use the
805 @code{quote} operator.
808 @node Numeric expressions
809 @subsection Numeric expressions
811 @cindex numeric expressions
812 @cindex expressions, numeric
814 @code{expr} supports the usual numeric operators, in order of increasing
815 precedence.  The string operators (previous section) have lower precedence,
816 the connectives (next section) have higher.
818 @table @samp
820 @item + -
821 @kindex +
822 @kindex -
823 @cindex addition
824 @cindex subtraction
825 Addition and subtraction.  Both arguments are coerced to numbers;
826 an error occurs if this cannot be done.
828 @item * / %
829 @kindex *
830 @kindex /
831 @kindex %
832 @cindex multiplication
833 @cindex division
834 @cindex remainder
835 Multiplication, division, remainder.  Both arguments are coerced to
836 numbers; an error occurs if this cannot be done.
838 @end table
841 @node Relations for expr
842 @subsection Relations for @code{expr}
844 @cindex connectives, logical
845 @cindex logical connectives
846 @cindex relations, numeric or string
848 @code{expr} supports the usual logical connectives and relations.  These
849 are higher precedence than either the string or numeric operators
850 (previous sections).  Here is the list, lowest-precedence operator first.
852 @table @samp
854 @item |
855 @kindex |
856 @cindex logical or operator
857 @cindex or operator
858 Returns its first argument if that is neither null nor 0, otherwise its
859 second argument.
861 @item &
862 @kindex &
863 @cindex logical and operator
864 @cindex and operator
865 Return its first argument if neither argument is null or 0, otherwise
868 @item < <= = == != >= >
869 @kindex <
870 @kindex <=
871 @kindex =
872 @kindex ==
873 @kindex >
874 @kindex >=
875 @cindex comparison operators
876 Compare the arguments and return 1 if the relation is true, 0 otherwise.
877 @code{==} is a synonym for @code{=}.  @code{expr} first tries to coerce
878 both arguments to numbers and do a numeric comparison; if either
879 coercion fails, it does a lexicographic comparison.
881 @end table
884 @node Examples of expr
885 @subsection Examples of using @code{expr}
887 @cindex examples of @code{expr}
888 Here are a few examples, including quoting for shell metacharacters.
890 To add 1 to the shell variable @code{foo}, in Bourne-compatible shells:
891 @example
892 foo=`expr $foo + 1`
893 @end example
895 To print the non-directory part of the file name stored in
896 @code{$fname}, which need not contain a @code{/}.
897 @example
898 expr $fname : '.*/\(^.*\)' '^|' $fname
899 @end example
901 An example showing that @code{\+} is an operator:
902 @example
903 expr aaa : 'a\+'
904 @result{} 3
905 @end example
907 @example
908 expr abc : 'a\(.\)c'
909 @result{} b
910 expr index abcdef cz
911 @result{} 3
912 expr index index a
913 @error{} expr: syntax error
914 expr index quote index a
915 @result{} 0
916 @end example
919 @node Redirection
920 @chapter Redirection
922 @cindex redirection
923 @cindex commands for redirection
925 Unix shells commonly provide several forms of @dfn{redirection}---ways
926 to change the input source or output destination of a command.  But one
927 useful redirection is performed by a separate command, not by the shell;
928 it's described here.
930 @menu
931 * tee invocation::              Redirect output to multiple files.
932 @end menu
935 @node tee invocation
936 @section @code{tee}: Redirect output to multiple files
938 @pindex tee
939 @cindex pipe fitting
940 @cindex destinations, multiple output
941 @cindex read from stdin and write to stdout and files
943 The @code{tee} command copies standard input to standard output and also
944 to any files given as arguments.  This is useful when you want not only
945 to send some data down a pipe, but also to save a copy.  Synopsis:
947 @example
948 tee [@var{option}]@dots{} [@var{file}]@dots{}
949 @end example
951 If a file being written to does not already exist, it is created.  If a
952 file being written to already exists, the data it previously contained
953 is overwritten unless the @code{-a} option is used.
955 The program accepts the following options.  Also see @ref{Common options}.
957 @table @samp
958 @item -a
959 @itemx --append
960 @opindex -a
961 @opindex --append
962 Append standard input to the given files rather than overwriting
963 them.
965 @item -i
966 @itemx --ignore-interrupts
967 @opindex -i
968 @opindex --ignore-interrupts
969 Ignore interrupt signals.
971 @end table
974 @node File name manipulation
975 @chapter File name manipulation
977 @cindex file name manipulation
978 @cindex manipulation of file names
979 @cindex commands for file name manipulation
981 This section describes commands that manipulate file names.
983 @menu
984 * basename invocation::         Strip directory and suffix from a file name.
985 * dirname invocation::          Strip non-directory suffix from a file name.
986 * pathchk invocation::          Check file name portability.
987 @end menu
990 @node basename invocation
991 @section @code{basename}: Strip directory and suffix from a file name
993 @pindex basename
994 @cindex strip directory and suffix from file names
995 @cindex directory, stripping from file names
996 @cindex suffix, stripping from file names
997 @cindex file names, stripping directory and suffix
998 @cindex leading directory components, stripping
1000 @code{basename} removes any leading directory components from
1001 @var{name}.  Synopsis:
1003 @example
1004 basename @var{name} [@var{suffix}]
1005 @end example
1007 If @var{suffix} is specified and is identical to the end of @var{name},
1008 it is removed from @var{name} as well.  @code{basename} prints the
1009 result on standard output.
1011 The only options are @samp{--help} and @samp{--version}.  @xref{Common
1012 options}.
1015 @node dirname invocation
1016 @section @code{dirname}: Strip non-directory suffix from a file name
1018 @pindex dirname
1019 @cindex directory components, printing
1020 @cindex stripping non-directory suffix
1021 @cindex non-directory suffix, stripping
1023 @code{dirname} prints all but the final slash-delimited component of
1024 a string (presumably a filename).  Synopsis:
1026 @example
1027 dirname @var{name}
1028 @end example
1030 If @var{name} is a single component, @code{dirname} prints @samp{.}
1031 (meaning the current directory).
1033 The only options are @samp{--help} and @samp{--version}.  @xref{Common
1034 options}.
1037 @node pathchk invocation
1038 @section @code{pathchk}: Check file name portability
1040 @pindex pathchk
1041 @cindex file names, checking validity and portability
1042 @cindex valid file names, checking for
1043 @cindex portable file names, checking for
1045 @code{pathchk} checks portability of filenames.  Synopsis:
1047 @example
1048 pathchk [@var{option}]@dots{} @var{name}@dots{}
1049 @end example
1051 For each @var{name}, @code{pathchk} prints a message if any of
1052 these conditions is true:
1053 @enumerate
1054 @item
1055 one of the existing directories in @var{name} does not have search
1056 (execute) permission,
1057 @item
1058 the length of @var{name} is larger than its filesystem's maximum
1059 file name length,
1060 @item
1061 the length of one component of @var{name}, corresponding to an
1062 existing directory name, is larger than its filesystem's maximum
1063 length for a file name component.
1064 @end enumerate
1066 The program accepts the following option.  Also see @ref{Common options}.
1068 @table @samp
1070 @item -p
1071 @itemx --portability
1072 @opindex -p
1073 @opindex --portability
1074 Instead of performing length checks on the underlying filesystem,
1075 test the length of each file name and its components against the
1076 POSIX.1 minimum limits for portability.  Also check that the file
1077 name contains no characters not in the portable file name character set.
1079 @end table
1081 @cindex exit status of @code{pathchk}
1082 Exit status:
1084 @display
1085 0 if all specified file names passed all of the tests,
1086 1 otherwise.
1087 @end display
1090 @node Working context
1091 @chapter Working context
1093 @cindex working context
1094 @cindex commands for printing the working context
1096 This section describes commands that display or alter the context in
1097 which you are working: the current directory, the terminal settings, and
1098 so forth.  See also the user-related commands in the next section.
1100 @menu
1101 * pwd invocation::              Print working directory.
1102 * stty invocation::             Print or change terminal characteristics.
1103 * printenv invocation::         Print environment variables.
1104 * tty invocation::              Print file name of terminal on standard input.
1105 @end menu
1108 @node pwd invocation
1109 @section @code{pwd}: Print working directory
1111 @pindex pwd
1112 @cindex print name of current directory
1113 @cindex current working directory, printing
1114 @cindex working directory, printing
1116 @cindex symbolic links and @code{pwd}
1117 @code{pwd} prints the fully resolved name of the current directory.
1118 That is, all components of the printed name will be actual directory
1119 names---none will be symbolic links.
1121 @cindex conflicts with shell built-ins
1122 @cindex built-in shell commands, conflicts with
1123 Because most shells have a built-in command by the same name, using the
1124 unadorned command name in a script or interactively may get you
1125 different functionality than that described here.
1127 The only options are a lone @samp{--help} or
1128 @samp{--version}.  @xref{Common options}.
1131 @node stty invocation
1132 @section @code{stty}: Print or change terminal characteristics
1134 @pindex stty
1135 @cindex change or print terminal settings
1136 @cindex terminal settings
1137 @cindex line settings of terminal
1139 @code{stty} prints or changes terminal characteristics, such as baud rate.
1140 Synopses:
1142 @example
1143 stty [@var{setting}]@dots{}
1144 stty [@var{option}]
1145 @end example
1147 If given no arguments, @code{stty} prints the baud rate, line
1148 discipline number (on systems that support it), and line settings
1149 that have been changed from the values set by @samp{stty sane}.
1150 Mode reading and setting are performed on the tty line connected to
1151 standard input.
1153 @code{stty} accepts many non-option arguments that change aspects of
1154 the terminal line operation, as described below.
1156 The program accepts the following options.  Also see @ref{Common options}.
1158 @table @samp
1159 @item -a
1160 @itemx --all
1161 @opindex -a
1162 @opindex --all
1163 Print all current settings in human-readable form.
1165 @item -g
1166 @itemx --save
1167 @opindex -g
1168 @opindex --save
1169 @cindex machine-readable @code{stty} output
1170 Print all current settings in a form that can be used as an argument to
1171 another @code{stty} command to restore the current settings.
1173 @end table
1175 Many settings can be turned off by preceding them with a @samp{-}.
1176 Such arguments are marked below with ``May be negated'' in their
1177 description.  The descriptions themselves refer to the positive
1178 case, that is, when @emph{not} negated (unless stated otherwise,
1179 of course).
1181 Some settings are not available on all POSIX systems, since they use
1182 extensions.  Such arguments are marked below with ``Non-POSIX'' in their
1183 description.  On non-POSIX systems, those or other settings also may not
1184 be available, but it's not feasible to document all the variations: just
1185 try it and see.
1187 @menu
1188 * Control::                     Control settings
1189 * Input::                       Input settings
1190 * Output::                      Output settings
1191 * Local::                       Local settings
1192 * Combination::                 Combination settings
1193 * Characters::                  Special characters
1194 * Special::                     Special settings
1195 @end menu
1198 @node Control
1199 @subsection Control settings
1201 @cindex control settings
1202 Control settings:
1204 @table @samp
1205 @item parenb
1206 @opindex parenb
1207 @cindex two-way parity
1208 Generate parity bit in output and expect parity bit in input.
1209 May be negated.
1211 @item parodd
1212 @opindex parodd
1213 @cindex odd parity
1214 @cindex even parity
1215 Set odd parity (even if negated).  May be negated.
1217 @item cs5
1218 @itemx cs6
1219 @itemx cs7
1220 @itemx cs8
1221 @opindex cs@var{n}
1222 @cindex character size
1223 @cindex eight-bit characters
1224 Set character size to 5, 6, 7, or 8 bits.
1226 @item hup
1227 @itemx hupcl
1228 @opindex hup[cl]
1229 Send a hangup signal when the last process closes the tty.  May be
1230 negated.
1232 @item cstopb
1233 @opindex cstopb
1234 @cindex stop bits
1235 Use two stop bits per character (one if negated).  May be negated.
1237 @item cread
1238 @opindex cread
1239 Allow input to be received.  May be negated.
1241 @item clocal
1242 @opindex clocal
1243 @cindex modem control
1244 Disable modem control signals.  May be negated.
1246 @item crtscts
1247 @opindex crtscts
1248 @cindex hardware flow control
1249 @cindex flow control, hardware
1250 @cindex RTS/CTS flow control
1251 Enable RTS/CTS flow control.  Non-POSIX.  May be negated.
1252 @end table
1255 @node Input
1256 @subsection Input settings
1258 @cindex input settings
1260 @table @samp
1261 @item ignbrk
1262 @opindex ignbrk
1263 @cindex breaks, ignoring
1264 Ignore break characters.  May be negated.
1266 @item brkint
1267 @opindex brkint
1268 @cindex breaks, cause interrupts
1269 Make breaks cause an interrupt signal.  May be negated.
1271 @item ignpar
1272 @opindex ignpar
1273 @cindex parity, ignoring
1274 Ignore characters with parity errors.  May be negated.
1276 @item parmrk
1277 @opindex parmrk
1278 @cindex parity errors, marking
1279 Mark parity errors (with a 255-0-character sequence).  May be negated.
1281 @item inpck
1282 @opindex inpck
1283 Enable input parity checking.  May be negated.
1285 @item istrip
1286 @opindex istrip
1287 @cindex eight-bit input
1288 Clear high (8th) bit of input characters.  May be negated.
1290 @item inlcr
1291 @opindex inlcr
1292 @cindex newline, translating to return
1293 Translate newline to carriage return.  May be negated.
1295 @item igncr
1296 @opindex igncr
1297 @cindex return, ignoring
1298 Ignore carriage return.  May be negated.
1300 @item icrnl
1301 @opindex icrnl
1302 @cindex return, translating to newline
1303 Translate carriage return to newline.  May be negated.
1305 @item ixon
1306 @opindex ixon
1307 @kindex C-s/C-q flow control
1308 @cindex XON/XOFF flow control
1309 Enable XON/XOFF flow control (that is, @kbd{CTRL-S}/@kbd{CTRL-Q}).  May
1310 be negated.
1312 @item ixoff
1313 @itemx tandem
1314 @opindex ixoff
1315 @opindex tandem
1316 @cindex software flow control
1317 @cindex flow control, software
1318 Enable sending of @code{stop} character when the system input buffer
1319 is almost full, and @code{start} character when it becomes almost
1320 empty again.  May be negated.
1322 @item iuclc
1323 @opindex iuclc
1324 @cindex uppercase, translating to lowercase
1325 Translate uppercase characters to lowercase.  Non-POSIX.  May be
1326 negated.
1328 @item ixany
1329 @opindex ixany
1330 Allow any character to restart output (only the start character
1331 if negated).  Non-POSIX.  May be negated.
1333 @item imaxbel
1334 @opindex imaxbel
1335 @cindex beeping at input buffer full
1336 Enable beeping and not flushing input buffer if a character arrives
1337 when the input buffer is full.  Non-POSIX.  May be negated.
1338 @end table
1341 @node Output
1342 @subsection Output settings
1344 @cindex output settings
1345 These arguments specify output-related operations.
1347 @table @samp
1348 @item opost
1349 @opindex opost
1350 Postprocess output.  May be negated.
1352 @item olcuc
1353 @opindex olcuc
1354 @cindex lowercase, translating to output
1355 Translate lowercase characters to uppercase.  Non-POSIX.  May be
1356 negated.
1358 @item ocrnl
1359 @opindex ocrnl
1360 @cindex return, translating to newline
1361 Translate carriage return to newline.  Non-POSIX.  May be negated.
1363 @item onlcr
1364 @opindex onlcr
1365 @cindex newline, translating to crlf
1366 Translate newline to carriage return-newline.  Non-POSIX.  May be
1367 negated.
1369 @item onocr
1370 @opindex onocr
1371 Do not print carriage returns in the first column.  Non-POSIX.
1372 May be negated.
1374 @item onlret
1375 @opindex onlret
1376 Newline performs a carriage return.  Non-POSIX.  May be negated.
1378 @item ofill
1379 @opindex ofill
1380 @cindex pad instead of timing for delaying
1381 Use fill (padding) characters instead of timing for delays.  Non-POSIX.
1382 May be negated.
1384 @item ofdel
1385 @opindex ofdel
1386 @cindex pad character
1387 Use delete characters for fill instead of null characters.  Non-POSIX.
1388 May be negated.
1390 @item nl1
1391 @itemx nl0
1392 @opindex nl@var{n}
1393 Newline delay style.  Non-POSIX.
1395 @item cr3
1396 @itemx cr2
1397 @itemx cr1
1398 @itemx cr0
1399 @opindex cr@var{n}
1400 Carriage return delay style.  Non-POSIX.
1402 @item tab3
1403 @itemx tab2
1404 @itemx tab1
1405 @itemx tab0
1406 @opindex tab@var{n}
1407 Horizontal tab delay style.  Non-POSIX.
1409 @item bs1
1410 @itemx bs0
1411 @opindex bs@var{n}
1412 Backspace delay style.  Non-POSIX.
1414 @item vt1
1415 @itemx vt0
1416 @opindex vt@var{n}
1417 Vertical tab delay style.  Non-POSIX.
1419 @item ff1
1420 @itemx ff0
1421 @opindex ff@var{n}
1422 Form feed delay style.  Non-POSIX.
1423 @end table
1426 @node Local
1427 @subsection Local settings
1429 @cindex local settings
1431 @table @samp
1432 @item isig
1433 @opindex isig
1434 Enable @code{interrupt}, @code{quit}, and @code{suspend} special
1435 characters.  May be negated.
1437 @item icanon
1438 @opindex icanon
1439 Enable @code{erase}, @code{kill}, @code{werase}, and @code{rprnt}
1440 special characters.  May be negated.
1442 @item iexten
1443 @opindex iexten
1444 Enable non-POSIX special characters.  May be negated.
1446 @item echo
1447 @opindex echo
1448 Echo input characters.  May be negated.
1450 @item echoe
1451 @itemx crterase
1452 @opindex echoe
1453 @opindex crterase
1454 Echo @code{erase} characters as backspace-space-backspace.  May be
1455 negated.
1457 @item echok
1458 @opindex echok
1459 @cindex newline echoing after @code{kill}
1460 Echo a newline after a @code{kill} character.  May be negated.
1462 @item echonl
1463 @opindex echonl
1464 @cindex newline, echoing
1465 Echo newline even if not echoing other characters.  May be negated.
1467 @item noflsh
1468 @opindex noflsh
1469 @cindex flushing, disabling
1470 Disable flushing after @code{interrupt} and @code{quit} special
1471 characters.  May be negated.
1473 @item xcase
1474 @opindex xcase
1475 @cindex case translation
1476 Enable input and output of uppercase characters by preceding their
1477 lowercase equivalents with @samp{\}, when @code{icanon} is set.
1478 Non-POSIX.  May be negated.
1480 @item tostop
1481 @opindex tostop
1482 @cindex background jobs, stopping at terminal write
1483 Stop background jobs that try to write to the terminal.  Non-POSIX.
1484 May be negated.
1486 @item echoprt
1487 @itemx prterase
1488 @opindex echoprt
1489 @opindex prterase
1490 Echo erased characters backward, between @samp{\} and @samp{/}.
1491 Non-POSIX.  May be negated.
1493 @item echoctl
1494 @itemx ctlecho
1495 @opindex echoctl
1496 @opindex ctlecho
1497 @cindex control characters, using @samp{^@var{c}}
1498 @cindex hat notation for control characters
1499 Echo control characters in hat notation (@samp{^@var{c}}) instead
1500 of literally.  Non-POSIX.  May be negated.
1502 @item echoke
1503 @itemx crtkill
1504 @opindex echoke
1505 @opindex crtkill
1506 Echo the @code{kill} special character by erasing each character on
1507 the line as indicated by the @code{echoprt} and @code{echoe} settings,
1508 instead of by the @code{echoctl} and @code{echok} settings.  Non-POSIX.
1509 May be negated.
1510 @end table
1513 @node Combination
1514 @subsection Combination settings
1516 @cindex combination settings
1517 Combination settings:
1519 @table @samp
1520 @item evenp
1521 @opindex evenp
1522 @itemx parity
1523 @opindex parity
1524 Same as @code{parenb -parodd cs7}.  May be negated.  If negated, same
1525 as @code{-parenb cs8}.
1527 @item oddp
1528 @opindex oddp
1529 Same as @code{parenb parodd cs7}.  May be negated.  If negated, same
1530 as @code{-parenb cs8}.
1532 @item nl
1533 @opindex nl
1534 Same as @code{-icrnl -onlcr}.  May be negated.  If negated, same as
1535 @code{icrnl -inlcr -igncr onlcr -ocrnl -onlret}.
1537 @item ek
1538 @opindex ek
1539 Reset the @code{erase} and @code{kill} special characters to their default
1540 values.
1542 @item sane
1543 @opindex sane
1544 Same as:
1545 @c This is too long to write inline.
1546 @example
1547 cread -ignbrk brkint -inlcr -igncr icrnl -ixoff -iuclc -ixany
1548 imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel
1549 nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl
1550 -noflsh -xcase -tostop -echoprt echoctl echoke
1551 @end example
1552 @noindent and also sets all special characters to their default values.
1554 @item cooked
1555 @opindex cooked
1556 Same as @code{brkint ignpar istrip icrnl ixon opost isig icanon}, plus
1557 sets the @code{eof} and @code{eol} characters to their default values
1558 if they are the same as the @code{min} and @code{time} characters.
1559 May be negated.  If negated, same as @code{raw}.
1561 @item raw
1562 @opindex raw
1563 Same as:
1564 @example
1565 -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr
1566 -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -isig -icanon
1567 -xcase min 1 time 0
1568 @end example
1569 @noindent May be negated.  If negated, same as @code{cooked}.
1571 @item cbreak
1572 @opindex cbreak
1573 Same as @code{-icanon}.  May be negated.  If negated, same as
1574 @code{icanon}.
1576 @item pass8
1577 @opindex pass8
1578 @cindex eight-bit characters
1579 Same as @code{-parenb -istrip cs8}.  May be negated.  If negated,
1580 same as @code{parenb istrip cs7}.
1582 @item litout
1583 @opindex litout
1584 Same as @code{-parenb -istrip -opost cs8}.  May be negated.
1585 If negated, same as @code{parenb istrip opost cs7}.
1587 @item decctlq
1588 @opindex decctlq
1589 Same as @code{-ixany}.  Non-POSIX.  May be negated.
1591 @item tabs
1592 @opindex tabs
1593 Same as @code{tab0}.  Non-POSIX.  May be negated.  If negated, same
1594 as @code{tab3}.
1596 @item lcase
1597 @itemx LCASE
1598 @opindex lcase
1599 @opindex LCASE
1600 Same as @code{xcase iuclc olcuc}.  Non-POSIX.  May be negated.
1602 @item crt
1603 @opindex crt
1604 Same as @code{echoe echoctl echoke}.
1606 @item dec
1607 @opindex dec
1608 Same as @code{echoe echoctl echoke -ixany intr ^C erase ^? kill C-u}.
1609 @end table
1612 @node Characters
1613 @subsection Special characters
1615 @cindex special characters
1616 @cindex characters, special
1618 The special characters' default values vary from system to system.
1619 They are set with the syntax @samp{name value}, where the names are
1620 listed below and the value can be given either literally, in hat
1621 notation (@samp{^@var{c}}), or as an integer which may start with
1622 @samp{0x} to indicate hexadecimal, @samp{0} to indicate octal, or
1623 any other digit to indicate decimal.
1625 @cindex disabling special characters
1626 @kindex u@r{, and disabling special characters}
1627 For GNU stty, giving a value of @code{^-} or @code{undef} disables that
1628 special character.  (This is incompatible with Ultrix @code{stty},
1629 which uses  a value of @samp{u} to disable a special character.  GNU
1630 @code{stty} treats a value @samp{u} like any other, namely to set that
1631 special character to @key{U}.)
1633 @table @samp
1635 @item intr
1636 @opindex intr
1637 Send an interrupt signal.
1639 @item quit
1640 @opindex quit
1641 Send a quit signal.
1643 @item erase
1644 @opindex erase
1645 Erase the last character typed.
1647 @item kill
1648 @opindex kill
1649 Erase the current line.
1651 @item eof
1652 @opindex eof
1653 Send an end of file (terminate the input).
1655 @item eol
1656 @opindex eol
1657 End the line.
1659 @item eol2
1660 @opindex eol2
1661 Alternate character to end the line.  Non-POSIX.
1663 @item swtch
1664 @opindex swtch
1665 Switch to a different shell layer.  Non-POSIX.
1667 @item start
1668 @opindex start
1669 Restart the output after stopping it.
1671 @item stop
1672 @opindex stop
1673 Stop the output.
1675 @item susp
1676 @opindex susp
1677 Send a terminal stop signal.
1679 @item dsusp
1680 @opindex dsusp
1681 Send a terminal stop signal after flushing the input.  Non-POSIX.
1683 @item rprnt
1684 @opindex rprnt
1685 Redraw the current line.  Non-POSIX.
1687 @item werase
1688 @opindex werase
1689 Erase the last word typed.  Non-POSIX.
1691 @item lnext
1692 @opindex lnext
1693 Enter the next character typed literally, even if it is a special
1694 character.  Non-POSIX.
1695 @end table
1698 @node Special
1699 @subsection Special settings
1701 @cindex special settings
1703 @table @samp
1704 @item min @var{n}
1705 @opindex min
1706 Set the minimum number of characters that will satisfy a read until
1707 the time value has expired, when @code{-icanon} is set.
1709 @item time @var{n}
1710 @opindex time
1711 Set the number of tenths of a second before reads time out if the min
1712 number of characters have not been read, when @code{-icanon} is set.
1714 @item ispeed @var{n}
1715 @opindex ispeed
1716 Set the input speed to @var{n}.
1718 @item ospeed @var{n}
1719 @opindex ospeed
1720 Set the output speed to @var{n}.
1722 @item rows @var{n}
1723 @opindex rows
1724 Tell the tty kernel driver that the terminal has @var{n} rows.  Non-POSIX.
1726 @item cols @var{n}
1727 @itemx columns @var{n}
1728 @opindex cols
1729 @opindex columns
1730 Tell the kernel that the terminal has @var{n} columns.  Non-POSIX.
1732 @item size
1733 @opindex size
1734 @vindex LINES
1735 @vindex COLUMNS
1736 Print the number of rows and columns that the kernel thinks the
1737 terminal has.  (Systems that don't support rows and cols in the kernel
1738 typically use the environment variables @code{LINES} and @code{COLUMNS}
1739 instead; however, GNU @code{stty} does not know anything about them.)
1740 Non-POSIX.
1742 @item line @var{n}
1743 @opindex line
1744 Use line discipline @var{n}.  Non-POSIX.
1746 @item speed
1747 @opindex speed
1748 Print the terminal speed.
1750 @item @var{n}
1751 @cindex baud rate, setting
1752 Set the input and output speeds to @var{n}.  @var{n} can be one
1753 of: 0 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600
1754 19200 38400 @code{exta} @code{extb}.  @code{exta} is the same as
1755 19200; @code{extb} is the same as 38400.  0 hangs up the line if
1756 @code{-clocal} is set.
1757 @end table
1760 @node printenv invocation
1761 @section @code{printenv}: Print all or some environment variables
1763 @pindex printenv
1764 @cindex printing all or some environment variables
1765 @cindex environment variables, printing
1767 @code{printenv} prints environment variable values.  Synopsis:
1769 @example
1770 printenv [@var{option}] [@var{variable}]@dots{}
1771 @end example
1773 If no @var{variable}s are specified, @code{printenv} prints the value of
1774 every environment variable.  Otherwise, it prints the value of each
1775 @var{variable} that is set, and nothing for those that are not set.
1777 The only options are a lone @samp{--help} or @samp{--version}.
1778 @xref{Common options}.
1780 @cindex exit status of @code{printenv}
1781 Exit status:
1783 @display
1784 0 if all variables specified were found
1785 1 if at least one specified variable was not found
1786 2 if a write error occurred
1787 @end display
1790 @node tty invocation
1791 @section @code{tty}: Print file name of terminal on standard input
1793 @pindex tty
1794 @cindex print terminal file name
1795 @cindex terminal file name, printing
1797 @code{tty} prints the file name of the terminal connected to its standard
1798 input.  It prints @samp{not a tty} if standard input is not a terminal.
1799 Synopsis:
1801 @example
1802 tty [@var{option}]@dots{}
1803 @end example
1805 The program accepts the following option.  Also see @ref{Common options}.
1807 @table @samp
1809 @item -s
1810 @itemx --silent
1811 @itemx --quiet
1812 @opindex -s
1813 @opindex --silent
1814 @opindex --quiet
1815 Print nothing; only return an exit status.
1817 @end table
1819 @cindex exit status of @code{tty}
1820 Exit status:
1822 @display
1823 0 if standard input is a terminal
1824 1 if standard input is not a terminal
1825 2 if given incorrect arguments
1826 3 if a write error occurs
1827 @end display
1830 @node User information
1831 @chapter User information
1833 @cindex user information, commands for
1834 @cindex commands for printing user information
1836 This section describes commands that print user-related information:
1837 logins, groups, and so forth.
1839 @menu
1840 * id invocation::               Print real and effective uid and gid.
1841 * logname invocation::          Print current login name.
1842 * whoami invocation::           Print effective user id.
1843 * groups invocation::           Print group names a user is in.
1844 * users invocation::            Print login names of users currently logged in.
1845 * who invocation::              Print who is currently logged in.
1846 @end menu
1849 @node id invocation
1850 @section @code{id}: Print real and effective uid and gid
1852 @pindex id
1853 @cindex real uid and gid, printing
1854 @cindex effective uid and gid, printing
1855 @cindex printing real and effective uid and gid
1857 @code{id} prints information about the given user, or the process
1858 running it if no user is specified.  Synopsis:
1860 @example
1861 id [@var{option}]@dots{} [@var{username}]
1862 @end example
1864 By default, it prints the real user id, real group id, effective user id
1865 if different from the real user id, effective group id if different from
1866 the real group id, and supplemental group ids.
1868 Each of these numeric values is preceded by an identifying string and
1869 followed by the corresponding user or group name in parentheses.
1871 The options cause @code{id} to print only part of the above information.
1872 Also see @ref{Common options}.
1874 @table @samp
1875 @item -g
1876 @itemx --group
1877 @opindex -g
1878 @opindex --group
1879 Print only the group id.
1881 @item -G
1882 @itemx --groups
1883 @opindex -G
1884 @opindex --groups
1885 Print only the supplementary groups.
1887 @item -n
1888 @itemx --name
1889 @opindex -n
1890 @opindex --name
1891 Print the user or group name instead of the ID number.  Requires
1892 @code{-u}, @code{-g}, or @code{-G}.
1894 @item -r
1895 @itemx --real
1896 @opindex -r
1897 @opindex --real
1898 Print the real, instead of effective, user or group id.  Requires
1899 @code{-u}, @code{-g}, or @code{-G}.
1901 @item -u
1902 @itemx --user
1903 @opindex -u
1904 @opindex --user
1905 Print only the user id.
1907 @end table
1910 @node logname invocation
1911 @section @code{logname}: Print current login name
1913 @pindex logname
1914 @cindex printing user's login name
1915 @cindex login name, printing
1916 @cindex user name, printing
1918 @flindex /etc/utmp
1919 @flindex utmp
1921 @code{logname} prints the calling user's name, as found in the file
1922 @file{/etc/utmp}, and exits with a status of 0.  If there is no
1923 @file{/etc/utmp} entry for the calling process, @code{logname} prints
1924 an error message and exits with a status of 1.
1926 The only options are @samp{--help} and @samp{--version}.  @xref{Common
1927 options}.
1930 @node whoami invocation
1931 @section @code{whoami}: Print effective user id
1933 @pindex whoami
1934 @cindex effective UID, printing
1935 @cindex printing the effective UID
1937 @code{whoami} prints the user name associated with the current
1938 effective user id.  It is equivalent to the command @samp{id -un}.
1940 The only options are @samp{--help} and @samp{--version}.  @xref{Common
1941 options}.
1944 @node groups invocation
1945 @section @code{groups}: Print group names a user is in
1947 @pindex groups
1948 @cindex printing groups a user is in
1949 @cindex supplementary groups, printing
1951 @code{groups} prints the names of the primary and any supplementary
1952 groups for each given @var{username}, or the current process if no names
1953 are given.  If names are given, the name of each user is printed before
1954 the list of that user's groups.  Synopsis:
1956 @example
1957 groups [@var{username}]@dots{}
1958 @end example
1960 The group lists are equivalent to the output of the command @samp{id -Gn}.
1962 The only options are @samp{--help} and @samp{--version}.  @xref{Common
1963 options}.
1966 @node users invocation
1967 @section @code{users}: Print login names of users currently logged in
1969 @pindex users
1970 @cindex printing current usernames
1971 @cindex usernames, printing current
1973 @cindex login sessions, printing users with
1974 @code{users} prints on a single line a blank-separated list of user
1975 names of users currently logged in to the current host.  Each user name
1976 corresponds to a login session, so if a user has more than one login
1977 session, that user's name will appear the same number of times in the
1978 output. Synopsis:
1980 @example
1981 users [@var{file}]
1982 @end example
1984 @flindex /etc/utmp
1985 @flindex /etc/wtmp
1986 With no @var{file} argument, @code{users} extracts its information from
1987 the file @file{/etc/utmp}.  If a file argument is given, @code{users}
1988 uses that file instead.  A common choice is @file{/etc/wtmp}.
1990 The only options are @samp{--help} and @samp{--version}.  @xref{Common
1991 options}.
1994 @node who invocation
1995 @section @code{who}: Print who is currently logged in
1997 @pindex who
1998 @cindex printing current user information
1999 @cindex information, about current users
2001 @code{who} prints information about users who are currently logged on.
2002 Synopsis:
2004 @example
2005 @code{who} [@var{option}] [@var{file}] [am i]
2006 @end example
2008 @cindex terminal lines, currently used
2009 @cindex login time
2010 @cindex remote hostname
2011 If given no non-option arguments, @code{who} prints the following
2012 information for each user currently logged on: login name, terminal
2013 line, login time, and remote hostname or X display.
2015 @flindex /etc/utmp
2016 @flindex /etc/wtmp
2017 If given one non-option argument, @code{who} uses that instead of
2018 @file{/etc/utmp} as the name of the file containing the record of
2019 users logged on.  @file{/etc/wtmp} is commonly given as an argument
2020 to @code{who} to look at who has previously logged on.
2022 @opindex am i
2023 @opindex who am i
2024 If given two non-option arguments, @code{who} prints only the entry
2025 for the user running it (determined from its standard input), preceded
2026 by the hostname.  Traditionally, the two arguments given are @samp{am
2027 i}, as in @samp{who am i}.
2029 The program accepts the following options.  Also see @ref{Common options}.
2031 @table @samp
2032 @item -m
2033 @opindex -m
2034 Same as @samp{who am i}.
2036 @item -q
2037 @itemx --count
2038 @opindex -q
2039 @opindex --count
2040 Print only the login names and the number of users logged on.
2041 Overrides all other options.
2043 @item -s
2044 @opindex -s
2045 Ignored; for compatibility with other versions of @code{who}.
2047 @item -i
2048 @itemx -u
2049 @itemx --idle
2050 @opindex -i
2051 @opindex -u
2052 @opindex --idle
2053 @cindex idle time
2054 After the login time, print the number of hours and minutes that the
2055 user has been idle.  @samp{.} means the user was active in last minute.
2056 @samp{old} means the user was idle for more than 24 hours.
2058 @item -l
2059 @itemx --lookup
2060 @opindex -l
2061 @opindex --lookup
2062 Attempt to canonicalize hostnames found in utmp through a DNS lookup.  This
2063 is not the default because it can cause significant delays on systems with
2064 automatic dial-up internet access.
2066 @item -H
2067 @itemx --heading
2068 @opindex -H
2069 @opindex --heading
2070 Print a line of column headings.
2072 @item -w
2073 @itemx -T
2074 @itemx --mesg
2075 @itemx --message
2076 @itemx --writable
2077 @opindex -w
2078 @opindex -T
2079 @opindex --mesg
2080 @opindex --message
2081 @opindex --writable
2082 @cindex message status
2083 @pindex write@r{, allowed}
2084 After each login name print a character indicating the user's message status:
2086 @display
2087 @samp{+} allowing @code{write} messages
2088 @samp{-} disallowing @code{write} messages
2089 @samp{?} cannot find terminal device
2090 @end display
2092 @end table
2095 @node System context
2096 @chapter System context
2098 @cindex system context
2099 @cindex context, system
2100 @cindex commands for system context
2102 This section describes commands that print or change system-wide
2103 information.
2105 @menu
2106 * date invocation::             Print or set system date and time.
2107 * uname invocation::            Print system information.
2108 * hostname invocation::         Print or set system name.
2109 @end menu
2112 @node date invocation
2113 @section @code{date}: Print or set system date and time
2115 @pindex date
2116 @cindex time, printing or setting
2117 @cindex printing the current time
2119 @code{date} with no arguments prints the current time and date, in the
2120 format of the @samp{%c} directive (described below).  Synopses:
2122 @example
2123 date [@var{option}]@dots{} [+@var{format}]
2124 date [-u|--utc|--universal] @c this avoids a newline in the output
2125 [ @var{MMDDhhmm}[[@var{CC}]@var{YY}][.@var{ss}] ]
2126 @end example
2128 @findex strftime @r{and @code{date}}
2129 @cindex time formats
2130 @cindex formatting times
2131 If given an argument that starts with a @samp{+}, @code{date} prints the
2132 current time and date (or the time and date specified by the
2133 @code{--date} option, see below) in the format defined by that argument,
2134 which is the same as in the @code{strftime} function.  Except for
2135 directives, which start with @samp{%}, characters in the format string
2136 are printed unchanged.  The directives are described below.
2138 @menu
2139 * Time directives::             %[HIklMprsSTXzZ]
2140 * Date directives::             %[aAbBcdDhjmUwWxyY]
2141 * Literal directives::          %[%nt]
2142 * Padding::                     Pad with zeroes, spaces (%_), or nothing (%-).
2143 * Setting the time::            Changing the system clock.
2144 * Options for date::            Instead of the current time.
2145 * Examples of date::            Examples.
2146 @end menu
2148 @node Time directives
2149 @subsection Time directives
2151 @cindex time directives
2152 @cindex directives, time
2154 @code{date} directives related to times.
2156 @table @samp
2157 @item %H
2158 hour (00@dots{}23)
2159 @item %I
2160 hour (01@dots{}12)
2161 @item %k
2162 hour ( 0@dots{}23)
2163 @item %l
2164 hour ( 1@dots{}12)
2165 @item %M
2166 minute (00@dots{}59)
2167 @item %p
2168 locale's AM or PM
2169 @item %r
2170 time, 12-hour (hh:mm:ss [AP]M)
2171 @item %s
2172 @cindex epoch, seconds since
2173 @cindex seconds since the epoch
2174 @cindex beginning of time
2175 seconds since the epoch, i.e., 1 January 1970 00:00:00 UTC (a
2176 GNU extension).
2177 Note that this value is the number of seconds between the epoch
2178 and the current date as defined by the localtime system call.
2179 It isn't changed by the @samp{--date} option.
2180 @item %S
2181 second (00@dots{}61)
2182 @item %T
2183 time, 24-hour (hh:mm:ss)
2184 @item %X
2185 locale's time representation (%H:%M:%S)
2186 @item %z
2187 RFC-822 style numeric time zone (e.g., -0600 or +0100), or nothing if no
2188 time zone is determinable.  This value reflects the @emph{current} time
2189 zone.  It isn't changed by the @samp{--date} option.
2190 @item %Z
2191 time zone (e.g., EDT), or nothing if no timezone is
2192 determinable.
2193 Note that this value reflects the @emph{current} time zone.
2194 It isn't changed by the @samp{--date} option.
2195 @end table
2198 @node Date directives
2199 @subsection Date directives
2201 @cindex date directives
2202 @cindex directives, date
2204 @code{date} directives related to dates.
2206 @table @samp
2207 @item %a
2208 locale's abbreviated weekday name (Sun@dots{}Sat)
2209 @item %A
2210 locale's full weekday name, variable length (Sunday@dots{}Saturday)
2211 @item %b
2212 locale's abbreviated month name (Jan@dots{}Dec)
2213 @item %B
2214 locale's full month name, variable length (January@dots{}December)
2215 @item %c
2216 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
2217 @item %d
2218 day of month (01@dots{}31)
2219 @item %D
2220 date (mm/dd/yy)
2221 @item %h
2222 same as %b
2223 @item %j
2224 day of year (001@dots{}366)
2225 @item %m
2226 month (01@dots{}12)
2227 @item %U
2228 week number of year with Sunday as first day of week (00@dots{}53).
2229 Days in a new year preceding the first Sunday are in week zero.
2230 @item %V
2231 week number of year with Monday as first day of the week as a decimal
2232 (01@dots{}53). If the week containing January 1 has four or more days in
2233 the new year, then it is considered week 1; otherwise, it is week 53 of
2234 the previous year, and the next week is week 1. (See the ISO 8601: 1988
2235 standard.)
2236 @item %w
2237 day of week (0@dots{}6) with 0 corresponding to Sunday
2238 @item %W
2239 week number of year with Monday as first day of week (00@dots{}53).
2240 Days in a new year preceding the first Monday are in week zero.
2241 @item %x
2242 locale's date representation (mm/dd/yy)
2243 @item %y
2244 last two digits of year (00@dots{}99)
2245 @item %Y
2246 year (1970@dots{}.)
2247 @end table
2250 @node Literal directives
2251 @subsection Literal directives
2253 @cindex literal directives
2254 @cindex directives, literal
2256 @code{date} directives that produce literal strings.
2258 @table @samp
2259 @item %%
2260 a literal %
2261 @item %n
2262 a newline
2263 @item %t
2264 a horizontal tab
2265 @end table
2268 @node Padding
2269 @subsection Padding
2271 @cindex numeric field padding
2272 @cindex padding of numeric fields
2273 @cindex fields, padding numeric
2275 By default, @code{date} pads numeric fields with zeroes, so that, for
2276 example, numeric months are always output as two digits. GNU @code{date}
2277 recognizes the following numeric modifiers between the @samp{%} and the
2278 directive.
2280 @table @samp
2281 @item -
2282 (hyphen) do not pad the field; useful if the output is intended for
2283 human consumption.
2284 @item _
2285 (underscore) pad the field with spaces; useful if you need a fixed
2286 number of characters in the output, but zeroes are too distracting.
2287 @end table
2289 @noindent
2290 These are GNU extensions.
2292 Here is an example illustrating the differences:
2294 @example
2295 date +%d/%m -d "Feb 1"
2296 @result{} 01/02
2297 date +%-d/%-m -d "Feb 1"
2298 @result{} 1/2
2299 date +%_d/%_m -d "Feb 1"
2300 @result{}  1/ 2
2301 @end example
2304 @node Setting the time
2305 @subsection Setting the time
2307 @cindex setting the time
2308 @cindex time setting
2309 @cindex appropriate privileges
2311 If given an argument that does not start with @samp{+}, @code{date} sets
2312 the system clock to the time and date specified by that argument (as
2313 described below).  You must have appropriate privileges to set the
2314 system clock.  The @samp{--date} and @samp{--set} options may not be
2315 used with such an argument.  The @samp{--universal} option may be used
2316 with such an argument to indicate that the specified time and date are
2317 relative to Coordinated Universal Time rather than to the local time
2318 zone.
2320 The argument must consist entirely of digits, which have the following
2321 meaning:
2323 @table @var
2324 @item MM
2325 month
2326 @item DD
2327 day within month
2328 @item hh
2329 hour
2330 @item mm
2331 minute
2332 @item CC
2333 first two digits of year (optional)
2334 @item YY
2335 last two digits of year (optional)
2336 @item ss
2337 second (optional)
2338 @end table
2340 The @samp{--set} option also sets the system clock; see the next section.
2343 @node Options for date
2344 @subsection Options for @code{date}
2346 @cindex @code{date} options
2347 @cindex options for @code{date}
2349 The program accepts the following options.  Also see @ref{Common options}.
2351 @table @samp
2353 @item -d @var{datestr}
2354 @itemx --date=@var{datestr}
2355 @opindex -d
2356 @opindex --date
2357 @cindex parsing date strings
2358 @cindex date strings, parsing
2359 @cindex arbitrary date strings, parsing
2360 @opindex yesterday
2361 @opindex tomorrow
2362 @opindex next @var{day}
2363 @opindex last @var{day}
2364 Display the time and date specified in @var{datestr} instead of the
2365 current time and date.  @var{datestr} can be in almost any common
2366 format.  It can contain month names, timezones, @samp{am} and @samp{pm},
2367 @samp{yesterday}, @samp{ago}, @samp{next}, etc.  @xref{Date input formats}.
2369 @item -f @var{datefile}
2370 @itemx --file=@var{datefile}
2371 @opindex -f
2372 @opindex --file
2373 Parse each line in @var{datefile} as with @samp{-d} and display the
2374 resulting time and date.  If @var{datefile} is @samp{-}, use standard
2375 input.  This is useful when you have many dates to process, because the
2376 system overhead of starting up the @code{date} executable many times can
2377 be considerable.
2379 @itemx --rfc-822
2380 @opindex -R
2381 @opindex --rfc-822
2382 Display the time and date using the RFC-822-specified
2383 format, @samp{%a, %_d %b %Y %H:%M:%S %z}.
2384 If @samp{--utc} is also specified, use @samp{GMT} in place of @samp{%z}.
2386 @item -r @var{file}
2387 @itemx --reference=@var{file}
2388 @opindex -r
2389 @opindex --reference
2390 Display the time and date reference according to the last modification
2391 time of @var{file}, instead of the current time and date.
2393 @item -s @var{datestr}
2394 @itemx --set=@var{datestr}
2395 @opindex -s
2396 @opindex --set
2397 Set the time and date to @var{datestr},  See @samp{-d} above.
2399 @item -u
2400 @itemx --utc
2401 @itemx --universal
2402 @opindex -u
2403 @opindex --utc
2404 @opindex --universal
2405 @cindex coordinated universal time
2406 @cindex Greenwich Mean Time
2407 Print or set the time and date in Universal Coordinated Time instead of
2408 in local (wall clock) time.
2410 @end table
2413 @node Examples of date
2414 @subsection Examples of @code{date}
2416 @cindex examples of @code{date}
2418 Here are a few examples.  Also see the documentation for the @samp{-d}
2419 option in the previous section.
2421 @itemize @bullet
2423 @item
2424 To print the date of the day before yesterday:
2426 @example
2427 date --date='2 days ago'
2428 @end example
2430 @item
2431 To print the date of the day three months and one day hence:
2432 @example
2433 date --date='3 months 1 day'
2434 @end example
2436 @item
2437 To print the day of year of Christmas in the current year:
2438 @example
2439 date --date='25 Dec' +%j
2440 @end example
2442 @item
2443 To print the current full month name and the day of the month:
2444 @example
2445 date '+%B %d'
2446 @end example
2448 But this may not be what you want because for the first nine days of
2449 the month, the @samp{%d} expands to a zero-padded two-digit field,
2450 for example @samp{date -d 1may '+%B %d'} will print @samp{May 01}.
2452 @item
2453 To print a date without the leading zero for one-digit days
2454 of the month, you can use the (GNU extension) @code{-} modifier to suppress
2455 the padding altogether.
2456 @example
2457 date -d=1may '+%B %-d'
2458 @end example
2460 @item
2461 To print the current date and time in the format required by many
2462 non-GNU versions of @code{date} when setting the system clock:
2463 @example
2464 date +%m%d%H%M%Y.%S
2465 @end example
2467 @item
2468 To set the system clock forward by two minutes:
2469 @example
2470 date --set='+2 minutes'
2471 @end example
2473 @item
2474 To print the date in the format specified by RFC-822,
2475 use @samp{date --rfc}.  I just did and saw this:
2477 @example
2478 Mon, 25 Mar 1996 23:34:17 -0600
2479 @end example
2481 @item
2482 To convert a date string to the number of seconds since the epoch
2483 (which is 1970-01-01 00:00:00 UTC), use the @samp{--date} option with
2484 the @samp{%s} format.  That can be useful in sorting and/or graphing
2485 and/or comparing data by date.  The following command outputs the
2486 number of the seconds since the epoch for the time one second later
2487 than the epoch, but in time zone five hours later (Cambridge, Massachusetts),
2488 thus a total of five hours and one second after the epoch:
2490 @example
2491 date --date='1970-01-01 00:00:01 UTC +5 hours' +%s
2492 18001
2493 @end example
2495 Suppose you had @emph{not} specified time zone information in the example above.
2496 Then, date would have used your computer's idea of the time zone when
2497 interpreting the string.  Here's what you would get if you were in
2498 Greenwich, England:
2500 @example
2501 # local time zone used
2502 date --date='1970-01-01 00:00:01' +%s
2504 @end example
2506 @item
2507 If you're sorting or graphing dated data, your raw date values may be
2508 represented as seconds since the epoch.  But few people can look at
2509 the date @samp{946684800} and casually note ``Oh, that's the first second
2510 of the year 2000.''
2512 @example
2513 date --date='2000-01-01 UTC' +%s
2514 946684800
2515 @end example
2517 To convert such an unwieldy number of seconds back to
2518 a more readable form, use a command like this:
2520 @smallexample
2521 date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z"
2522 2000-01-01 00:00:00 +0000
2523 @end smallexample
2525 @end itemize
2528 @node uname invocation
2529 @section @code{uname}: Print system information
2531 @pindex uname
2532 @cindex print system information
2533 @cindex system information, printing
2535 @code{uname} prints information about the machine and operating system
2536 it is run on.  If no options are given, @code{uname} acts as if the
2537 @code{-s} option were given. Synopsis:
2539 @example
2540 uname [@var{option}]@dots{}
2541 @end example
2543 If multiple options or @code{-a} are given, the selected information is
2544 printed in this order:
2546 @example
2547 @var{sysname} @var{nodename} @var{release} @var{osversion} @var{machine}
2548 @end example
2550 The @var{osversion}, at least, may well be multiple words.  For example:
2552 @example
2553 uname -a
2554 @result{} Linux hayley 1.0.4 #3 Thu May 12 18:06:34 1994 i486
2555 @end example
2558 The program accepts the following options.  Also see @ref{Common options}.
2560 @table @samp
2562 @item -a
2563 @itemx --all
2564 @opindex -a
2565 @opindex --all
2566 Print all of the below information.
2568 @item -m
2569 @itemx --machine
2570 @opindex -m
2571 @opindex --machine
2572 @cindex machine type
2573 @cindex hardware type
2574 Print the machine (hardware) type.
2576 @item -n
2577 @itemx --nodename
2578 @opindex -n
2579 @opindex --nodename
2580 @cindex hostname
2581 @cindex node name
2582 @cindex network node name
2583 Print the machine's network node hostname.
2585 @item -p
2586 @itemx --processor
2587 @opindex -p
2588 @opindex --processor
2589 @cindex host processor type
2590 Print the machine's processor type
2592 @item -r
2593 @itemx --release
2594 @opindex -r
2595 @opindex --release
2596 @cindex operating system release
2597 @cindex release of operating system
2598 Print the operating system release.
2600 @item -s
2601 @itemx --sysname
2602 @opindex -s
2603 @opindex --sysname
2604 @cindex operating system name
2605 @cindex name of operating system
2606 Print the operating system name.
2608 @item -v
2609 @opindex -v
2610 @cindex operating system version
2611 @cindex version of operating system
2612 Print the operating system version.
2614 @end table
2617 @node hostname invocation
2618 @section @code{hostname}: Print or set system name
2620 @pindex hostname
2621 @cindex setting the hostname
2622 @cindex printing the hostname
2623 @cindex system name, printing
2624 @cindex appropriate privileges
2626 With no arguments, @code{hostname} prints the name of the current host
2627 system.  With one argument, it sets the current host name to the
2628 specified string.  You must have appropriate privileges to set the host
2629 name. Synopsis:
2631 @example
2632 hostname [@var{name}]
2633 @end example
2635 The only options are @samp{--help} and @samp{--version}.  @xref{Common
2636 options}.
2639 @node Modified command invocation
2640 @chapter Modified command invocation
2642 @cindex modified command invocation
2643 @cindex invocation of commands, modified
2644 @cindex commands for invoking other commands
2646 This section describes commands that run other commands in some context
2647 different than the current one: a modified environment, as a different
2648 user, etc.
2650 @menu
2651 * chroot invocation::           Modify the root directory.
2652 * env invocation::              Modify environment variables.
2653 * nice invocation::             Modify scheduling priority.
2654 * nohup invocation::            Immunize to hangups.
2655 * su invocation::               Modify user and group id.
2656 @end menu
2659 @node chroot invocation
2660 @section @code{chroot}: Run a command with a different root directory
2662 @pindex chroot
2663 @cindex running a program in a specified root directory
2664 @cindex root directory, running a program in a specified
2666 @code{chroot} runs a command with a specified root directory.
2667 On many systems, only the super-user can do this.
2668 Synopses:
2670 @example
2671 chroot @var{newroot} [@var{command} [@var{args}]@dots{}]
2672 chroot @var{option}
2673 @end example
2675 Ordinarily, filenames are looked up starting at the root of the
2676 directory structure, i.e., @file{/}.  @code{chroot} changes the root to
2677 the directory @var{newroot} (which must exist) and then runs
2678 @var{command} with optional @var{args}.  If @var{command} is not
2679 specified, the default is the value of the @code{SHELL} environment
2680 variable or @code{/bin/sh} if not set, invoked with the @samp{-i} option.
2682 The only options are @samp{--help} and @samp{--version}.  @xref{Common
2683 options}.
2686 @node env invocation
2687 @section @code{env}: Run a command in a modified environment
2689 @pindex env
2690 @cindex environment, running a program in a modified
2691 @cindex modified environment, running a program in a
2692 @cindex running a program in a modified environment
2694 @code{env} runs a command with a modified environment.  Synopses:
2696 @example
2697 env [@var{option}]@dots{} [@var{name}=@var{value}]@dots{} @c
2698 [@var{command} [@var{args}]@dots{}]
2700 @end example
2702 Arguments of the form @samp{@var{variable}=@var{value}} set
2703 the environment variable @var{variable} to value @var{value}.
2704 @var{value} may be empty (@samp{@var{variable}=}).  Setting a variable
2705 to an empty value is different from unsetting it.
2707 @vindex PATH
2708 The first remaining argument specifies the program name to invoke; it is
2709 searched for according to the @code{PATH} environment variable.  Any
2710 remaining arguments are passed as arguments to that program.
2712 @cindex environment, printing
2714 If no command name is specified following the environment
2715 specifications, the resulting environment is printed.  This is like
2716 specifying a command name of @code{printenv}.
2718 The program accepts the following options.  Also see @ref{Common options}.
2720 @table @samp
2722 @item -u @var{name}
2723 @itemx --unset=@var{name}
2724 @opindex -u
2725 @opindex -unset
2726 Remove variable @var{name} from the environment, if it was in the
2727 environment.
2729 @item -
2730 @itemx -i
2731 @itemx --ignore-environment
2732 @opindex -
2733 @opindex -i
2734 @opindex --ignore-environment
2735 Start with an empty environment, ignoring the inherited environment.
2737 @end table
2740 @node nice invocation
2741 @section @code{nice}: Run a command with modified scheduling priority
2743 @pindex nice
2744 @cindex modifying scheduling priority
2745 @cindex scheduling priority, modifying
2746 @cindex priority, modifying
2747 @cindex appropriate privileges
2749 @code{nice} prints or modifies the scheduling priority of a job.
2750 Synopsis:
2752 @example
2753 nice [@var{option}]@dots{} [@var{command} [@var{arg}]@dots{}]
2754 @end example
2756 If no arguments are given, @code{nice} prints the current scheduling
2757 priority, which it inherited.  Otherwise, @code{nice} runs the given
2758 @var{command} with its scheduling priority adjusted.  If no
2759 @var{adjustment} is given, the priority of the command is incremented by
2760 10.  You must have appropriate privileges to specify a negative
2761 adjustment.  The priority can be adjusted by @code{nice} over the range
2762 of -20 (the highest priority) to 19 (the lowest).
2764 @cindex conflicts with shell built-ins
2765 @cindex built-in shell commands, conflicts with
2766 Because most shells have a built-in command by the same name, using the
2767 unadorned command name in a script or interactively may get you
2768 different functionality than that described here.
2770 The program accepts the following option.  Also see @ref{Common options}.
2772 @table @samp
2773 @item -n @var{adjustment}
2774 @itemx -@var{adjustment}
2775 @itemx --adjustment=@var{adjustment}
2776 @opindex -n
2777 @opindex --adjustment
2778 @opindex -@var{adjustment}
2779 Add @var{adjustment} instead of 10 to the command's priority.
2780 @end table
2783 @node nohup invocation
2784 @section @code{nohup}: Run a command immune to hangups
2786 @pindex nohup
2787 @cindex hangups, immunity to
2788 @cindex immunity to hangups
2789 @cindex logging out and continuing to run
2791 @flindex nohup.out
2792 @code{nohup} runs the given @var{command} with hangup signals ignored,
2793 so that the command can continue running in the background after you log
2794 out. Synopsis:
2796 @example
2797 nohup @var{command} [@var{arg}]@dots{}
2798 @end example
2800 @flindex nohup.out
2801 @code{nohup} increases the scheduling priority of @var{command} by 5, so
2802 it has a slightly smaller change to run.  If standard output is a terminal,
2803 it and standard error are redirected so that they are appended to the
2804 file @file{nohup.out}; if that cannot be written to, they are appended
2805 to the file @file{$HOME/nohup.out}.  If that cannot be written to, the
2806 command is not run.
2808 If @code{nohup} creates either @file{nohup.out} or
2809 @file{$HOME/nohup.out}, it creates it with no ``group'' or ``other''
2810 access permissions.  It does not change the permissions if the output
2811 file already existed.
2813 @code{nohup} does not automatically put the command it runs in the
2814 background; you must do that explicitly, by ending the command line
2815 with an @samp{&}.
2817 The only options are @samp{--help} and @samp{--version}.  @xref{Common
2818 options}.
2821 @node su invocation
2822 @section @code{su}: Run a command with substitute user and group id
2824 @pindex su
2825 @cindex substitute user and group ids
2826 @cindex user id, switching
2827 @cindex super-user, becoming
2828 @cindex root, becoming
2830 @code{su} allows one user to temporarily become another user.  It runs a
2831 command (often an interactive shell) with the real and effective user
2832 id, group id, and supplemental groups of a given @var{user}. Synopsis:
2834 @example
2835 su [@var{option}]@dots{} [@var{user} [@var{arg}]@dots{}]
2836 @end example
2838 @cindex passwd entry, and @code{su} shell
2839 @flindex /bin/sh
2840 @flindex /etc/passwd
2841 If no @var{user} is given, the default is @code{root}, the super-user.
2842 The shell to use is taken from @var{user}'s @code{passwd} entry, or
2843 @file{/bin/sh} if none is specified there.  If @var{user} has a
2844 password, @code{su} prompts for the password unless run by a user with
2845 effective user id of zero (the super-user).
2847 @vindex HOME
2848 @vindex SHELL
2849 @vindex USER
2850 @vindex LOGNAME
2851 @cindex login shell
2852 By default, @code{su} does not change the current directory.
2853 It sets the environment variables @code{HOME} and @code{SHELL}
2854 from the password entry for @var{user}, and if @var{user} is not
2855 the super-user, sets @code{USER} and @code{LOGNAME} to @var{user}.
2856 By default, the shell is not a login shell.
2858 Any additional @var{arg}s are passed as additional arguments to the
2859 shell.
2861 @cindex @samp{-su}
2862 GNU @code{su} does not treat @file{/bin/sh} or any other shells specially
2863 (e.g., by setting @code{argv[0]} to @samp{-su}, passing @code{-c} only
2864 to certain shells, etc.).
2866 @findex syslog
2867 @code{su} can optionally be compiled to use @code{syslog} to report
2868 failed, and optionally successful, @code{su} attempts.  (If the system
2869 supports @code{syslog}.)  However, GNU @code{su} does not check if the
2870 user is a member of the @code{wheel} group; see below.
2872 The program accepts the following options.  Also see @ref{Common options}.
2874 @table @samp
2875 @item -c @var{command}
2876 @itemx --command=@var{command}
2877 @opindex -c
2878 @opindex --command
2879 Pass @var{command}, a single command line to run, to the shell with
2880 a @code{-c} option instead of starting an interactive shell.
2882 @item -f
2883 @itemx --fast
2884 @opindex -f
2885 @opindex --fast
2886 @flindex .cshrc
2887 @cindex file name pattern expansion, disabled
2888 @cindex globbing, disabled
2889 Pass the @code{-f} option to the shell.  This probably only makes sense
2890 if the shell run is @code{csh} or @code{tcsh}, for which the @code{-f}
2891 option prevents reading the startup file (@file{.cshrc}).  With
2892 Bourne-like shells, the @code{-f} option disables file name pattern
2893 expansion (globbing), which is not likely to be useful.
2895 @item -
2896 @itemx -l
2897 @itemx --login
2898 @opindex -
2899 @opindex -l
2900 @opindex --login
2901 @c other variables already indexed above
2902 @vindex TERM
2903 @vindex PATH
2904 @cindex login shell, creating
2905 Make the shell a login shell.  This means the following.  Unset all
2906 environment variables except @code{TERM}, @code{HOME}, and @code{SHELL}
2907 (which are set as described above), and @code{USER} and @code{LOGNAME}
2908 (which are set, even for the super-user, as described above), and set
2909 @code{PATH} to a compiled-in default value.  Change to @var{user}'s home
2910 directory.  Prepend @samp{-} to the shell's name, intended to make it
2911 read its login startup file(s).
2913 @item -m
2914 @itemx -p
2915 @itemx --preserve-environment
2916 @opindex -m
2917 @opindex -p
2918 @opindex --preserve-environment
2919 @cindex environment, preserving
2920 @flindex /etc/shells
2921 @cindex restricted shell
2922 Do not change the environment variables @code{HOME}, @code{USER},
2923 @code{LOGNAME}, or @code{SHELL}.  Run the shell given in the environment
2924 variable @code{SHELL} instead of the shell from @var{user}'s passwd
2925 entry, unless the user running @code{su} is not the superuser and
2926 @var{user}'s shell is restricted.  A @dfn{restricted shell} is one that
2927 is not listed in the file @file{/etc/shells}, or in a compiled-in list
2928 if that file does not exist.  Parts of what this option does can be
2929 overridden by @code{--login} and @code{--shell}.
2931 @item -s @var{shell}
2932 @itemx --shell=@var{shell}
2933 @opindex -s
2934 @opindex --shell
2935 Run @var{shell} instead of the shell from @var{user}'s passwd entry,
2936 unless the user running @code{su} is not the superuser and @var{user}'s
2937 shell is restricted (see @samp{-m} just above).
2939 @end table
2941 @cindex wheel group, not supported
2942 @cindex group wheel, not supported
2943 @cindex fascism
2944 @heading Why GNU @code{su} does not support the @samp{wheel} group
2946 (This section is by Richard Stallman.)
2948 @cindex Twenex
2949 @cindex MIT AI lab
2950 Sometimes a few of the users try to hold total power over all the
2951 rest.  For example, in 1984, a few users at the MIT AI lab decided to
2952 seize power by changing the operator password on the Twenex system and
2953 keeping it secret from everyone else.  (I was able to thwart this coup
2954 and give power back to the users by patching the kernel, but I
2955 wouldn't know how to do that in Unix.)
2957 However, occasionally the rulers do tell someone.  Under the usual
2958 @code{su} mechanism, once someone learns the root password who
2959 sympathizes with the ordinary users, he or she can tell the rest.  The
2960 ``wheel group'' feature would make this impossible, and thus cement the
2961 power of the rulers.
2963 I'm on the side of the masses, not that of the rulers.  If you are
2964 used to supporting the bosses and sysadmins in whatever they do, you
2965 might find this idea strange at first.
2968 @node Delaying
2969 @chapter Delaying
2971 @cindex delaying commands
2972 @cindex commands for delaying
2974 @c Perhaps @code{wait} or other commands should be described here also?
2976 @menu
2977 * sleep invocation::            Delay for a specified time.
2978 @end menu
2981 @node sleep invocation
2982 @section @code{sleep}: Delay for a specified time
2984 @pindex sleep
2985 @cindex delay for a specified time
2987 @code{sleep} pauses for an amount of time specified by the sum of
2988 the values of the command line arguments.
2989 Synopsis:
2991 @example
2992 sleep [@var{number}[smhd]]@dots{}
2993 @end example
2995 @cindex time units
2996 Each argument is a number followed by an optional unit; the default
2997 is seconds.  The units are:
2999 @table @samp
3000 @item s
3001 seconds
3002 @item m
3003 minutes
3004 @item h
3005 hours
3006 @item d
3007 days
3008 @end table
3010 The only options are @samp{--help} and @samp{--version}.  @xref{Common
3011 options}.
3014 @node Numeric operations
3015 @chapter Numeric operations
3017 @cindex numeric operations
3018 These programs do numerically-related operations.
3020 @menu
3021 * factor invocation::              Show factors of numbers.
3022 * seq invocation::                 Print sequences of numbers.
3023 @end menu
3026 @node factor invocation
3027 @section @code{factor}: Print prime factors
3029 @pindex factor
3030 @cindex prime factors
3032 @code{factor} prints prime factors.  Synopses:
3034 @example
3035 factor [@var{number}]@dots{}
3036 factor @var{option}
3037 @end example
3039 If no @var{number} is specified on the command line, @code{factor} reads
3040 numbers from standard input, delimited by newlines, tabs, or spaces.
3042 The only options are @samp{--help} and @samp{--version}.  @xref{Common
3043 options}.
3046 @node seq invocation
3047 @section @code{seq}: Print numeric sequences
3049 @pindex seq
3050 @cindex numeric sequences
3051 @cindex sequence of numbers
3053 @code{seq} prints a sequence of numbers to standard output.  Synopses:
3055 @example
3056 seq [@var{option}]@dots{} [@var{first} [@var{step}]] @var{last}@dots{}
3057 @end example
3059 @code{seq} prints the numbers from @var{first} to @var{last} by
3060 @var{step}.  By default, @var{first} and @var{step} are both 1, and each
3061 number is printed on its own line.  All numbers can be reals, not just
3062 integers.
3064 The program accepts the following options.  Also see @ref{Common options}.
3066 @table @samp
3067 @item -f @var{format}
3068 @itemx --format=@var{format}
3069 @opindex -f @var{format}
3070 @opindex --format=@var{format}
3071 @cindex formatting of numbers in @code{seq}
3072 Print all numbers using @var{format}; default @samp{%g}.
3073 @var{format} must contain exactly one of the standarding float output
3074 formats @samp{%e}, @samp{%f}, or @samp{%g}.
3076 @item -s @var{string}
3077 @itemx --separator=@var{string}
3078 @cindex separator for numbers in @code{seq}
3079 Separate numbers with @var{string}; default is a newline.
3080 The output always terminates with a newline.
3082 @item -w
3083 @itemx --equal-width
3084 Print all numbers with the same width, by padding with leading zeroes.
3085 (To have other kinds of padding, use @samp{--format}).
3087 @end table
3090 @node Index
3091 @unnumbered Index
3093 @printindex cp
3095 @contents
3096 @bye
3098 @c Local variables:
3099 @c texinfo-column-for-description: 33
3100 @c End: