3 @setfilename sh-utils.info
4 @settitle GNU shell utilities
9 @c Define new indices for file names and options.
13 @c Put everything in one index (arbitrarily chosen to be the concept index).
22 @set Francois Franc,ois
25 @set Francois Fran\noexpand\ptexc cois
31 * Shell utilities: (sh-utils). GNU shell utilities.
32 * basename: (sh-utils)basename invocation. Strip directory and suffix.
33 * date: (sh-utils)date invocation. Print/set system date and time.
34 * dirname: (sh-utils)dirname invocation. Strip non-directory suffix.
35 * echo: (sh-utils)echo invocation. Print a line of text.
36 * env: (sh-utils)env invocation. Modify the environment.
37 * expr: (sh-utils)expr invocation. Evaluate expressions.
38 * false: (sh-utils)false invocation. Do nothing, unsuccessfully.
39 * groups: (sh-utils)groups invocation. Print group names a user is in.
40 * hostname: (sh-utils)hostname invocation. Print or set system name.
41 * id: (sh-utils)id invocation. Print real/effective uid/gid.
42 * logname: (sh-utils)logname invocation. Print current login name.
43 * nice: (sh-utils)nice invocation. Modify scheduling priority.
44 * nohup: (sh-utils)nohup invocation. Immunize to hangups.
45 * pathchk: (sh-utils)pathchk invocation. Check file name portability.
46 * printenv: (sh-utils)printenv invocation. Print environment variables.
47 * printf: (sh-utils)printf invocation. Format and print data.
48 * pwd: (sh-utils)pwd invocation. Print working directory.
49 * sleep: (sh-utils)sleep invocation. Delay for a specified time.
50 * stty: (sh-utils)stty invocation. Print/change terminal settings.
51 * su: (sh-utils)su invocation. Modify user and group id.
52 * tee: (sh-utils)tee invocation. Redirect to multiple files.
53 * test: (sh-utils)test invocation. File/string tests.
54 * true: (sh-utils)true invocation. Do nothing, successfully.
55 * tty: (sh-utils)tty invocation. Print terminal name.
56 * uname: (sh-utils)uname invocation. Print system information.
57 * users: (sh-utils)users invocation. Print current user names.
58 * who: (sh-utils)who invocation. Print who is logged in.
59 * whoami: (sh-utils)whoami invocation. Print effective user id.
60 * yes: (sh-utils)yes invocation. Print a string indefinitely.
66 This file documents the GNU shell utilities.
68 Copyright (C) 1994 Free Software Foundation, Inc.
70 Permission is granted to make and distribute verbatim copies of
71 this manual provided the copyright notice and this permission notice
72 are preserved on all copies.
75 Permission is granted to process this file through TeX and print the
76 results, provided the printed document carries copying permission
77 notice identical to this one except for the removal of this paragraph
78 (this paragraph not being relevant to the printed manual).
81 Permission is granted to copy and distribute modified versions of this
82 manual under the conditions for verbatim copying, provided that the entire
83 resulting derived work is distributed under the terms of a permission
84 notice identical to this one.
86 Permission is granted to copy and distribute translations of this manual
87 into another language, under the above conditions for modified versions,
88 except that this permission notice may be stated in a translation approved
93 @title GNU @code{sh-utils}
94 @subtitle A set of shell utilities
95 @subtitle for version @value{VERSION}, @value{RELEASEDATE}
96 @author David MacKenzie et al.
99 @vskip 0pt plus 1filll
100 Copyright @copyright{} 1994 Free Software Foundation, Inc.
102 Permission is granted to make and distribute verbatim copies of
103 this manual provided the copyright notice and this permission notice
104 are preserved on all copies.
106 Permission is granted to copy and distribute modified versions of this
107 manual under the conditions for verbatim copying, provided that the entire
108 resulting derived work is distributed under the terms of a permission
109 notice identical to this one.
111 Permission is granted to copy and distribute translations of this manual
112 into another language, under the above conditions for modified versions,
113 except that this permission notice may be stated in a translation approved
120 @top GNU shell utilities
122 @cindex shell utilities
123 @cindex utilities for shell programming
125 This manual minimally documents version @value{VERSION} of the GNU shell
129 * Introduction:: Caveats, overview, and authors.
130 * Common options:: Common options.
131 * Date input formats:: Specifying date strings.
132 * Printing text:: echo printf yes
133 * Conditions:: false true test expr
135 * File name manipulation:: dirname basename pathchk
136 * Working context:: pwd stty printenv tty
137 * User information:: id logname whoami groups users who
138 * System context:: date uname hostname
139 * Modified command invocation:: env nice nohup su
141 * Index:: General index.
147 @chapter 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.
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{bug-gnu-utils@@prep.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}.
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, Francois
183 @cindex Stallman, Richard
184 This manual is based on the Unix man pages in the distribution, which
185 were originally written by David MacKenzie and updated by Jim Meyering.
186 @value{Francois} Pinard did the initial conversion to Texinfo format.
187 Karl Berry did the indexing, some reorganization, and editing of the results.
188 Richard Stallman contributed his usual invaluable insights to the
193 @chapter Common options
195 @cindex common options
197 Certain options are available in all these programs. Rather than
198 writing identical descriptions for each of the programs, they are
199 described here. (In fact, every GNU program accepts (or should accept)
202 Many of these programs take arbitrary strings as arguments. In those
203 cases, @samp{--help} and @samp{--version} are taken as these options
204 only if there is one and exactly one command line argument.
211 Print a usage message listing all available options, then exit successfully.
215 @cindex version number, finding
216 Print the version number, then exit successfully.
221 @include getdate.texi
225 @chapter Printing text
227 @cindex printing text, commands for
228 @cindex commands for printing text
230 This section describes commands that display text strings.
233 * echo invocation:: Print a line of text.
234 * printf invocation:: Format and print data.
235 * yes invocation:: Print a string until interrupted.
239 @node echo invocation
240 @section @code{echo}: Print a line of text
243 @cindex displaying text
244 @cindex printing text
245 @cindex text, displaying
246 @cindex arbitrary text, displaying
251 echo [@var{option}]@dots{} [@var{string}]@dots{}
254 @code{echo} writes each given @var{string} to standard output, with a
255 space between each and a newline after the last one.
257 The program accepts the following options. Also see @ref{Common options}.
262 Do not output the trailing newline.
266 @cindex backslash escapes
267 Enable interpretation of the following backslash-escaped characters in
276 suppress trailing newline
290 the character whose ASCII code is @var{nnn} (octal); if @var{nnn} is not
291 a valid octal number, it is printed literally.
297 @node printf invocation
298 @section @code{printf}: Format and print data
304 printf @var{format} [@var{argument}]@dots{}
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.
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.
324 An additional escape, @samp{\c}, causes @code{printf} to produce no
327 The only options are a lone @samp{--help} or
328 @samp{--version}. @xref{Common options}.
332 @section @code{yes}: Print a string until interrupted
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}.
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
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.
365 @node false invocation
366 @section @code{false}: Do nothing, unsuccessfully
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
384 @cindex do nothing, successfully
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
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.
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
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!)
445 @cindex block special check
446 True if @var{file} exists and is a block special device.
450 @cindex character special check
451 True if @var{file} exists and is a character special device.
455 @cindex directory check
456 True if @var{file} exists and is a directory.
460 @cindex regular file check
461 True if @var{file} exists and is a regular file.
467 @cindex symbolic link check
468 True if @var{file} exists and is a symbolic link.
472 @cindex named pipe check
473 True if @var{file} exists and is a named pipe.
478 True if @var{file} exists and is a socket.
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).
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.
501 @cindex set-group-id check
502 True if @var{file} exists and has its set-group-id bit set.
506 @cindex sticky bit check
507 True if @var{file} has its @dfn{sticky} bit set.
511 @cindex readable file check
512 True if @var{file} exists and is readable.
516 @cindex set-user-id check
517 True if @var{file} exists and has its set-user-id bit set.
521 @cindex writable file check
522 True if @var{file} exists and is writable.
526 @cindex executable file check
527 True if @var{file} exists and is executable.
531 @cindex owned by effective uid check
532 True if @var{file} exists and is owned by the current effective user id.
536 @cindex owned by effective gid check
537 True if @var{file} exists and is owned by the current effective group id.
541 @node File characteristics tests
542 @subsection File characteristics tests
544 @cindex file characteristics tests
546 These options test other file characteristics.
552 @cindex existence-of-file check
553 True if @var{file} exists.
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}
562 @cindex newer-than file check
563 True if @var{file1} is newer (according to modification date) than
566 @item @var{file1} -ot @var{file2}
568 @cindex older-than file check
569 True if @var{file1} is older (according to modification date) than
572 @item @var{file1} -ef @var{file2}
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.
583 @subsection 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.
593 @item -z @var{string}
595 @cindex zero-length string check
596 True if the length of @var{string} is zero.
598 @item -n @var{string}
601 @cindex nonzero-length string check
602 True if the length of @var{string} is non-zero.
604 @item @var{string1} = @var{string2}
606 @cindex equal string check
607 True if the strings are equal.
609 @item @var{string1} != @var{string2}
611 @cindex not-equal string check
612 True if the strings are not equal.
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}.
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}
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.
650 test -1 -gt -2 && echo yes
652 test -l abc -gt 1 && echo yes
655 @error{} test: integer expression expected before -eq
659 @node Connectives for test
660 @subsection Connectives for @code{test}
662 @cindex logical connectives
663 @cindex connectives, logical
665 The usual logical connectives.
671 True if @var{expr} is false.
673 @item @var{expr1} -a @var{expr2}
675 @cindex logical and operator
677 True if both @var{expr1} and @var{expr2} are true.
679 @item @var{expr1} -o @var{expr2}
681 @cindex logical or operator
683 True if either @var{expr1} or @var{expr2} is true.
688 @node expr invocation
689 @section @code{expr}: Evaluate expressions
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}, though you may need to quote
703 them to protect characters with special meaning to the shell, e.g.,
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}
715 0 if the expression is neither null nor 0,
716 1 if the expression is null or 0,
717 2 for invalid expressions.
721 * Relations for expr:: | & < <= = == != >= >
722 * Numeric expressions:: + - * / %
723 * String expressions:: : match substr index length
724 * Examples of expr:: Examples.
728 @node Relations for expr
729 @subsection Relations for @code{expr}
731 @cindex connectives, logical
732 @cindex logical connectives
733 @cindex relations, numeric or string
735 The usual logical connectives and relations, in order of precedence.
741 @cindex logical or operator
743 Yields its first argument if it is neither null nor 0, otherwise its
748 @cindex logical and operator
750 Yields its first argument if neither argument is null or 0, otherwise
753 @item < <= = == != >= >
760 @cindex comparison operators
761 Compare the arguments and return 1 if the relation is true, 0 otherwise.
762 @code{==} is a synonym for @code{=}. @code{expr} first tries to coerce
763 both arguments to numbers and do a numeric comparison; if either
764 coercion fails, it does a lexicographic comparison.
769 @node Numeric expressions
770 @subsection Numeric expressions
772 @cindex numeric expressions
773 @cindex expressions, numeric
775 Numeric operators, in order of increasing precedence. The connectives
776 (previous section) have higher precedence, the string operators
777 (following section) have lower.
786 Addition and subtraction. Both arguments are coerced to numbers;
787 an error occurs if this cannot be done.
793 @cindex multiplication
796 Multiplication, division, remainder. Both arguments are coerced to
797 numbers; an error occurs if this cannot be done.
802 @node String expressions
803 @subsection String expressions
805 @cindex string expressions
806 @cindex expressions, string
808 String operators. These have lowest precedence.
812 @item @var{string} : @var{regex}
813 @cindex pattern matching
814 @cindex regular expression matching
815 @cindex matching patterns
816 Perform pattern matching. The arguments are coerced to strings and the
817 second is considered to be a (basic, a la @code{grep}) regular
818 expression, with a @code{^} implicitly prepended. The first argument is
819 then matched against this regular expression.
821 If the match succeeds and @var{regex} uses @samp{\(} and @samp{\)}, the
822 @code{:} expression returns the part of @var{string} that matched the
823 subexpression; otherwise, it returns the number of characters matched.
825 If the match fails, the @code{:} operator returns the null string if
826 @samp{\(} and @samp{\)} are used in @var{regex}, otherwise 0.
828 Only the first @samp{\( @dots{} \)} pair is relevant to the return
829 value; additional pairs are meaningful only for grouping the regular
830 expression operators.
832 @xref{Top, , Regular Expression Library, regex, Regex}, for details of
833 regular expression syntax.
835 @item match @var{string} @var{regex}
837 An alternative way to do pattern matching. This is the same as
838 @w{@samp{@var{string} : @var{regex}}}.
840 @item substr @var{string} @var{position} @var{length}
842 Returns the substring of @var{string} beginning at @var{position}
843 with length at most @var{length}. If either @var{position} or
844 @var{length} is negative or non-numeric, returns the null string.
846 @item index @var{string} @var{character-class}
848 Returns the first position in @var{string} where the first character in
849 @var{charset} was found. If no character in @var{charset} is found in
850 @var{string}, return 0.
852 @item length @var{string}
854 Returns the length of @var{string}.
858 The keywords cannot be used as strings.
861 @node Examples of expr
862 @subsection Examples of @code{expr}
864 @cindex examples of @code{expr}
865 Here are a few examples, including quoting for shell metacharacters.
867 To add 1 to the shell variable @code{foo}, in Bourne-compatible shells:
872 To print the non-directory part of the file name stored in
873 @code{$fname}, which need not contain a @code{/}.
875 expr $fname : '.*/\(^.*\)' '^|' $fname
884 @error{} expr: syntax error
893 @cindex commands for redirection
895 Unix shells commonly provide several forms of @dfn{redirection}---ways
896 to change the input source or output destination of a command. But one
897 useful redirection is performed by a separate command, not by the shell;
902 * tee invocation:: Redirect output to multiple files.
906 @section @code{tee}: Redirect output to multiple files
910 @cindex destinations, multiple output
911 @cindex read from stdin and write to stdout and files
913 The @code{tee} command copies standard input to standard output and also
914 to any files given as arguments. This is useful when you want not only
915 to send some data down a pipe, but also to save a copy.
920 tee [@var{option}]@dots{} [@var{file}]@dots{}
923 If a file being written to does not already exist, it is created. If a
924 file being written to already exists, the data it previously contained
925 is overwritten unless the @code{-a} option is used.
927 The program accepts the following options. Also see @ref{Common options}.
934 Append standard input to the given files rather than overwriting
938 @itemx --ignore-interrupts
940 @opindex --ignore-interrupts
941 Ignore interrupt signals.
946 @node File name manipulation
947 @chapter File name manipulation
949 @cindex file name manipulation
950 @cindex manipulation of file names
951 @cindex commands for file name manipulation
953 This section describes commands that manipulate file names.
956 * basename invocation:: Strip directory and suffix from a file name.
957 * dirname invocation:: Strip non-directory suffix from a file name.
958 * pathchk invocation:: Check file name portability.
962 @node basename invocation
963 @section @code{basename}: Strip directory and suffix from a file name
966 @cindex strip directory and suffix from file names
967 @cindex directory, stripping from file names
968 @cindex suffix, stripping from file names
969 @cindex file names, stripping directory and suffix
970 @cindex leading directory components, stripping
975 basename @var{name} [@var{suffix}]
978 The @code{basename} command removes any leading directory components
979 from @var{name}. If @var{suffix} is specified and is identical
980 to the end of @var{name}, it is removed from @var{name} as well.
981 @code{basename} prints the result on standard output.
983 The only options are @samp{--help} and @samp{--version}. @xref{Common
987 @node dirname invocation
988 @section @code{dirname}: Strip non-directory suffix from a file name
991 @cindex directory components, printing
992 @cindex stripping non-directory suffix
993 @cindex non-directory suffix, stripping
1001 @code{dirname} prints all but the final slash-delimited component
1002 of @var{name}. If @var{name} is a single component,
1003 @code{dirname} prints @samp{.} (meaning the current directory).
1005 The only options are @samp{--help} and @samp{--version}. @xref{Common
1009 @node pathchk invocation
1010 @section @code{pathchk}: Check file name portability
1013 @cindex file names, checking validity and portability
1014 @cindex valid file names, checking for
1015 @cindex portable file names, checking for
1020 pathchk [@var{option}]@dots{} @var{name}@dots{}
1023 For each @var{name}, @code{pathchk} prints a message if any of
1024 these conditions is true:
1027 one of the existing directories in @var{name} does not have search
1028 (execute) permission,
1030 the length of @var{name} is larger than its filesystem's maximum
1033 the length of one component of @var{name}, corresponding to an
1034 existing directory name, is larger than its filesystem's maximum
1035 length for a file name component.
1038 The program accepts the following option. Also see @ref{Common options}.
1043 @itemx --portability
1045 @opindex --portability
1046 Instead of performing length checks on the underlying filesystem,
1047 test the length of each file name and its components against the
1048 POSIX.1 minimum limits for portability. Also check that the file
1049 name contains no characters not in the portable file name character set.
1053 @cindex exit status of @code{pathchk}
1057 0 if all specified file names passed all of the tests,
1062 @node Working context
1063 @chapter Working context
1065 @cindex working context
1066 @cindex commands for printing the working context
1068 This section describes commands that display or alter the context in
1069 which you are working: the current directory, the terminal settings, and
1070 so forth. See also the user-related commands in the next section.
1073 * pwd invocation:: Print working directory.
1074 * stty invocation:: Print or change terminal characteristics.
1075 * printenv invocation:: Print environment variables.
1076 * tty invocation:: Print file name of terminal on standard input.
1080 @node pwd invocation
1081 @section @code{pwd}: Print working directory
1084 @cindex print name of current directory
1085 @cindex current working directory, printing
1086 @cindex working directory, printing
1088 @cindex symbolic links and @code{pwd}
1089 @code{pwd} prints the fully resolved name of the current directory.
1090 That is, all components of the printed name will be actual directory
1091 names---none will be symbolic links.
1093 @cindex conflicts with shell built-ins
1094 @cindex built-in shell commands, conflicts with
1095 Because most shells have a built-in command by the same name, using the
1096 unadorned command name in a script or interactively may get you
1097 different functionality than that described here.
1099 The only options are a lone @samp{--help} or
1100 @samp{--version}. @xref{Common options}.
1103 @node stty invocation
1104 @section @code{stty}: Print or change terminal characteristics
1107 @cindex change or print terminal settings
1108 @cindex terminal settings
1109 @cindex line settings of terminal
1111 If given no arguments, @code{stty} prints the baud rate, line
1112 discipline number (on systems that support it), and line settings
1113 that have been changed from the values set by @samp{stty sane}.
1114 Mode reading and setting are performed on the tty line connected to
1117 @code{stty} accepts many non-option arguments that change aspects of
1118 the terminal line operation, as described below.
1123 stty [@var{setting}]@dots{}
1127 The program accepts the following options. Also see @ref{Common options}.
1134 Print all current settings in human-readable form.
1140 @cindex machine-readable @code{stty} output
1141 Print all current settings in a form that can be used as an argument to
1142 another @code{stty} command to restore the current settings.
1146 Many settings can be turned off by preceding them with a @samp{-}.
1147 Such arguments are marked below with ``May be negated'' in their
1148 description. The descriptions themselves refer to the positive
1149 case, that is, when @emph{not} negated (unless stated otherwise,
1152 Some settings are not available on all POSIX systems, since they use
1153 extensions. Such arguments are marked below with ``Non-POSIX'' in their
1154 description. On non-POSIX systems, those or other settings also may not
1155 be available, but it's not feasible to document all the variations: just
1159 * Control:: Control settings
1160 * Input:: Input settings
1161 * Output:: Output settings
1162 * Local:: Local settings
1163 * Combination:: Combination settings
1164 * Characters:: Special characters
1165 * Special:: Special settings
1170 @subsection Control settings
1172 @cindex control settings
1178 @cindex two-way parity
1179 Generate parity bit in output and expect parity bit in input.
1186 Set odd parity (even if negated). May be negated.
1193 @cindex character size
1194 @cindex eight-bit characters
1195 Set character size to 5, 6, 7, or 8 bits.
1200 Send a hangup signal when the last process closes the tty. May be
1206 Use two stop bits per character (one if negated). May be negated.
1210 Allow input to be received. May be negated.
1214 @cindex modem control
1215 Disable modem control signals. May be negated.
1219 @cindex hardware flow control
1220 @cindex flow control, hardware
1221 @cindex RTS/CTS flow control
1222 Enable RTS/CTS flow control. Non-POSIX. May be negated.
1227 @subsection Input settings
1229 @cindex input settings
1234 @cindex breaks, ignoring
1235 Ignore breaks. May be negated.
1239 @cindex breaks, cause interrupts
1240 Make breaks cause an interrupt signal. May be negated.
1244 @cindex parity, ignoring
1245 Ignore parity errors. May be negated.
1249 @cindex parity errors, marking
1250 Mark parity errors (with a 255-0-character sequence). May be negated.
1254 Enable input parity checking. May be negated.
1258 @cindex eight-bit input
1259 Clear high (8th) bit of input characters. May be negated.
1263 @cindex newline, translating to return
1264 Translate newline to carriage return. May be negated.
1268 @cindex return, ignoring
1269 Ignore carriage return. May be negated.
1273 @cindex return, translating to newline
1274 Translate carriage return to newline. May be negated.
1278 @kindex C-s/C-q flow control
1279 @cindex XON/XOFF flow control
1280 Enable XON/XOFF flow control (that is, @key{CTRL-s}/@key{CTRL-Q}). May
1287 @cindex software flow control
1288 @cindex flow control, software
1289 Enable sending of @code{stop} character when the system input buffer
1290 is almost full, and @code{start} character when it becomes almost
1291 empty again. May be negated.
1295 @cindex uppercase, translating to lowercase
1296 Translate uppercase characters to lowercase. Non-POSIX. May be
1301 Allow any character to restart output (only the start character
1302 if negated). Non-POSIX. May be negated.
1306 @cindex beeping at input buffer full
1307 Enable beeping and not flushing input buffer if a character arrives
1308 when the input buffer is full. Non-POSIX. May be negated.
1313 @subsection Output settings
1315 @cindex output settings
1316 These arguments specify output-related operations.
1321 Postprocess output. May be negated.
1325 @cindex lowercase, translating to output
1326 Translate lowercase characters to uppercase. Non-POSIX. May be
1331 @cindex return, translating to newline
1332 Translate carriage return to newline. Non-POSIX. May be negated.
1336 @cindex newline, translating to crlf
1337 Translate newline to carriage return-newline. Non-POSIX. May be
1342 Do not print carriage returns in the first column. Non-POSIX.
1347 Newline performs a carriage return. Non-POSIX. May be negated.
1351 @cindex pad instead of timing for delaying
1352 Use fill (padding) characters instead of timing for delays. Non-POSIX.
1357 @cindex pad character
1358 Use delete characters for fill instead of null characters. Non-POSIX.
1364 Newline delay style. Non-POSIX.
1371 Carriage return delay style. Non-POSIX.
1378 Horizontal tab delay style. Non-POSIX.
1383 Backspace delay style. Non-POSIX.
1388 Vertical tab delay style. Non-POSIX.
1393 Form feed delay style. Non-POSIX.
1398 @subsection Local settings
1400 @cindex local settings
1405 Enable @code{interrupt}, @code{quit}, and @code{suspend} special
1406 characters. May be negated.
1410 Enable @code{erase}, @code{kill}, @code{werase}, and @code{rprnt}
1411 special characters. May be negated.
1415 Enable non-POSIX special characters. May be negated.
1419 Echo input characters. May be negated.
1425 Echo @code{erase} characters as backspace-space-backspace. May be
1430 @cindex newline echoing after @code{kill}
1431 Echo a newline after a @code{kill} character. May be negated.
1435 @cindex newline, echoing
1436 Echo newline even if not echoing other characters. May be negated.
1440 @cindex flushing, disabling
1441 Disable flushing after @code{interrupt} and @code{quit} special
1442 characters. May be negated.
1446 @cindex case translation
1447 Enable input and output of uppercase characters by preceding their
1448 lowercase equivalents with @samp{\}, when @code{icanon} is set.
1449 Non-POSIX. May be negated.
1453 @cindex background jobs, stopping at terminal write
1454 Stop background jobs that try to write to the terminal. Non-POSIX.
1461 Echo erased characters backward, between @samp{\} and @samp{/}.
1462 Non-POSIX. May be negated.
1468 @cindex control characters, using @samp{^@var{c}}
1469 @cindex hat notation for control characters
1470 Echo control characters in hat notation (@samp{^@var{c}}) instead
1471 of literally. Non-POSIX. May be negated.
1477 Echo the @code{kill} special character by erasing each character on
1478 the line as indicated by the @code{echoprt} and @code{echoe} settings,
1479 instead of by the @code{echoctl} and @code{echok} settings. Non-POSIX.
1485 @subsection Combination settings
1487 @cindex combination settings
1488 Combination settings:
1495 Same as @code{parenb -parodd cs7}. May be negated. If negated, same
1496 as @code{-parenb cs8}.
1500 Same as @code{parenb parodd cs7}. May be negated. If negated, same
1501 as @code{-parenb cs8}.
1505 Same as @code{-icrnl -onlcr}. May be negated. If negated, same as
1506 @code{icrnl -inlcr -igncr onlcr -ocrnl -onlret}.
1510 Reset the @code{erase} and @code{kill} special characters to their default
1516 @c This is too long to write inline.
1518 cread -ignbrk brkint -inlcr -igncr icrnl -ixoff -iuclc -ixany
1519 imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel
1520 nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl
1521 -noflsh -xcase -tostop -echoprt echoctl echoke
1523 @noindent and also sets all special characters to their default values.
1527 Same as @code{brkint ignpar istrip icrnl ixon opost isig icanon}, plus
1528 sets the @code{eof} and @code{eol} characters to their default values
1529 if they are the same as the @code{min} and @code{time} characters.
1530 May be negated. If negated, same as @code{raw}.
1536 -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr
1537 -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -isig -icanon
1540 @noindent May be negated. If negated, same as @code{cooked}.
1544 Same as @code{-icanon}. May be negated. If negated, same as
1549 @cindex eight-bit characters
1550 Same as @code{-parenb -istrip cs8}. May be negated. If negated,
1551 same as @code{parenb istrip cs7}.
1555 Same as @code{-parenb -istrip -opost cs8}. May be negated.
1556 If negated, same as @code{parenb istrip opost cs7}.
1560 Same as @code{-ixany}. Non-POSIX. May be negated.
1564 Same as @code{tab0}. Non-POSIX. May be negated. If negated, same
1571 Same as @code{xcase iuclc olcuc}. Non-POSIX. May be negated.
1575 Same as @code{echoe echoctl echoke}.
1579 Same as @code{echoe echoctl echoke -ixany intr ^C erase ^? kill C-u}.
1584 @subsection Special characters
1586 @cindex special characters
1587 @cindex characters, special
1589 The special characters' default values vary from system to system.
1590 They are set with the syntax @samp{name value}, where the names are
1591 listed below and the value can be given either literally, in hat
1592 notation (@samp{^@var{c}}), or as an integer which may start with
1593 @samp{0x} to indicate hexadecimal, @samp{0} to indicate octal, or
1594 any other digit to indicate decimal.
1596 @cindex disabling special characters
1597 @kindex u@r{, and disabling special characters}
1598 For GNU stty, giving a value of @code{^-} or @code{undef} disables that
1599 special character. (This is incompatible with Ultrix @code{stty},
1600 which uses a value of @samp{u} to disable a special character. GNU
1601 @code{stty} treats a value @samp{u} like any other, namely to set that
1602 special character to @key{u}.)
1608 Send an interrupt signal.
1616 Erase the last character typed.
1620 Erase the current line.
1624 Send an end of file (terminate the input).
1632 Alternate character to end the line. Non-POSIX.
1636 Switch to a different shell layer. Non-POSIX.
1640 Restart the output after stopping it.
1648 Send a terminal stop signal.
1652 Send a terminal stop signal after flushing the input. Non-POSIX.
1656 Redraw the current line. Non-POSIX.
1660 Erase the last word typed. Non-POSIX.
1664 Enter the next character typed literally, even if it is a special
1665 character. Non-POSIX.
1670 @subsection Special settings
1672 @cindex special settings
1677 Set the minimum number of characters that will satisfy a read until
1678 the time value has expired, when @code{-icanon} is set.
1682 Set the number of tenths of a second before reads time out if the min
1683 number of characters have not been read, when @code{-icanon} is set.
1685 @item ispeed @var{n}
1687 Set the input speed to @var{n}.
1689 @item ospeed @var{n}
1691 Set the output speed to @var{n}.
1695 Tell the tty kernel driver that the terminal has @var{n} rows. Non-POSIX.
1698 @itemx columns @var{n}
1701 Tell the kernel that the terminal has @var{n} columns. Non-POSIX.
1707 Print the number of rows and columns that the kernel thinks the
1708 terminal has. (Systems that don't support rows and cols in the kernel
1709 typically use the environment variables @code{LINES} and @code{COLUMNS}
1710 instead; however, GNU @code{stty} does not know anything about them.)
1715 Use line discipline @var{n}. Non-POSIX.
1719 Print the terminal speed.
1722 @cindex baud rate, setting
1723 Set the input and output speeds to @var{n}. @var{n} can be one
1724 of: 0 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600
1725 19200 38400 @code{exta} @code{extb}. @code{exta} is the same as
1726 19200; @code{extb} is the same as 38400. 0 hangs up the line if
1727 @code{-clocal} is set.
1731 @node printenv invocation
1732 @section @code{printenv}: Print all or some environment variables
1735 @cindex printing all or some environment variables
1736 @cindex environment variables, printing
1741 printenv [@var{option}] [@var{variable}]@dots{}
1744 If no @var{variable}s are specified, @code{printenv} prints the value of
1745 every environment variable. Otherwise, it prints the value of each
1746 @var{variable} that is set, and nothing for those that are not set.
1748 The only options are a lone @samp{--help} or @samp{--version}.
1749 @xref{Common options}.
1751 @cindex exit status of @code{printenv}
1755 0 if all variables specified were found
1756 1 if at least one specified variable was not found
1757 2 if a write error occurred
1761 @node tty invocation
1762 @section @code{tty}: Print file name of terminal on standard input
1765 @cindex print terminal file name
1766 @cindex terminal file name, printing
1768 @code{tty} prints the file name of the tty connected to its standard
1769 input. It prints @samp{not a tty} if standard input is not a tty.
1774 tty [@var{option}]@dots{}
1777 The program accepts the following option. Also see @ref{Common options}.
1787 Print nothing; only return an exit status.
1791 @cindex exit status of @code{tty}
1795 0 if standard input is a tty
1796 1 if standard input is not a tty
1797 2 if given incorrect arguments
1798 3 if a write error occurs
1802 @node User information
1803 @chapter User information
1805 @cindex user information, commands for
1806 @cindex commands for printing user information
1808 This section describes commands that print user-related information:
1809 logins, groups, and so forth.
1812 * id invocation:: Print real and effective uid and gid.
1813 * logname invocation:: Print current login name.
1814 * whoami invocation:: Print effective user id.
1815 * groups invocation:: Print group names a user is in.
1816 * users invocation:: Print login names of users currently logged in.
1817 * who invocation:: Print who is currently logged in.
1822 @section @code{id}: Print real and effective uid and gid
1825 @cindex real uid and gid, printing
1826 @cindex effective uid and gid, printing
1827 @cindex printing real and effective uid and gid
1829 @noindent @code{id} prints information about the given user, or the process
1830 running it if no user is specified.
1835 id [@var{option}]@dots{} [@var{username}]
1838 By default, it prints the real user id, real group id, effective user id
1839 if different from the real user id, effective group id if different from
1840 the real group id, and supplemental group ids.
1842 Each of these numeric values is preceded by an identifying string and
1843 followed by the corresponding user or group name in parentheses.
1845 The options cause @code{id} to print only part of the above information.
1846 Also see @ref{Common options}.
1853 Print only the group id.
1859 Print only the supplementary groups.
1865 Print the user or group name instead of the ID number. Requires
1866 @code{-u}, @code{-g}, or @code{-G}.
1872 Print the real, instead of effective, user or group id. Requires
1873 @code{-u}, @code{-g}, or @code{-G}.
1879 Print only the user id.
1884 @node logname invocation
1885 @section @code{logname}: Print current login name
1888 @cindex printing user's login name
1889 @cindex login name, printing
1890 @cindex user name, printing
1895 @code{logname} prints the calling user's name, as found in the file
1896 @file{/etc/utmp}, and exits with a status of 0. If there is no
1897 @file{/etc/utmp} entry for the calling process, @code{logname} prints
1898 an error message and exits with a status of 1.
1900 The only options are @samp{--help} and @samp{--version}. @xref{Common
1904 @node whoami invocation
1905 @section @code{whoami}: Print effective user id
1908 @cindex effective UID, printing
1909 @cindex printing the effective UID
1911 @code{whoami} prints the user name associated with the current
1912 effective user id. It is equivalent to the command @samp{id -un}.
1914 The only options are @samp{--help} and @samp{--version}. @xref{Common
1918 @node groups invocation
1919 @section @code{groups}: Print group names a user is in
1922 @cindex printing groups a user is in
1923 @cindex supplementary groups, printing
1925 @code{groups} prints the names of the primary and any supplementary
1926 groups that each given @var{username}, or the current process if none
1927 are given, is in. If user names are given, the name of each user is
1928 printed before the list of that user's groups.
1933 groups [@var{username}]@dots{}
1936 The group lists are equivalent to the output of the command @samp{id -Gn}.
1938 The only options are @samp{--help} and @samp{--version}. @xref{Common
1942 @node users invocation
1943 @section @code{users}: Print login names of users currently logged in
1946 @cindex printing current usernames
1947 @cindex usernames, printing current
1949 @cindex login sessions, printing users with
1950 @code{users} prints on a single line a blank-separated list of user
1951 names of users currently logged in to the current host. Each user name
1952 corresponds to a login session, so if a user has more than one login
1953 session, that user's name will appear the same number of times in the
1964 With no @var{file} argument, @code{users} extracts its information from
1965 the file @file{/etc/utmp}. If a file argument is given, @code{users}
1966 uses that file instead. A common choice is @file{/etc/wtmp}.
1968 The only options are @samp{--help} and @samp{--version}. @xref{Common
1972 @node who invocation
1973 @section @code{who}: Print who is currently logged in
1976 @cindex printing current user information
1977 @cindex information, about current users
1982 @code{who} [@var{option}] [@var{file}] [am i]
1985 @cindex terminal lines, currently used
1987 @cindex remote hostname
1988 If given no non-option arguments, @code{who} prints the following
1989 information for each user currently logged on: login name, terminal
1990 line, login time, and remote hostname or X display.
1994 If given one non-option argument, @code{who} uses that instead of
1995 @file{/etc/utmp} as the name of the file containing the record of
1996 users logged on. @file{/etc/wtmp} is commonly given as an argument
1997 to @code{who} to look at who has previously logged on.
2001 If given two non-option arguments, @code{who} prints only the entry
2002 for the user running it (determined from its standard input), preceded
2003 by the hostname. Traditionally, the two arguments given are @samp{am
2004 i}, as in @samp{who am i}.
2006 The program accepts the following options. Also see @ref{Common options}.
2011 Same as @samp{who am i}.
2017 Print only the login names and the number of users logged on.
2018 Overrides all other options.
2022 Ignored; for compatibility with other versions of @code{who}.
2031 After the login time, print the number of hours and minutes that the
2032 user has been idle. @samp{.} means the user was active in last minute.
2033 @samp{old} means the user was idle for more than 24 hours.
2039 Print a line of column headings.
2051 @cindex message status
2052 @pindex write@r{, allowed}
2053 After each login name print a character indicating the user's message status:
2056 @samp{+} allowing @code{write} messages
2057 @samp{-} disallowing @code{write} messages
2058 @samp{?} cannot find terminal device
2064 @node System context
2065 @chapter System context
2067 @cindex system context
2068 @cindex context, system
2069 @cindex commands for system context
2071 This section describes commands that print or change system-wide
2075 * date invocation:: Print or set system date and time.
2076 * uname invocation:: Print system information.
2077 * hostname invocation:: Print or set system name.
2081 @node date invocation
2082 @section @code{date}: Print or set system date and time
2085 @cindex time, printing or setting
2086 @cindex printing the current time
2088 @code{date} with no arguments prints the current time and date, in
2089 the format of the @samp{%c} directive (described below).
2094 date [@var{option}]@dots{} [+@var{format}]
2095 date [-u|--utc|--universal] @c this avoids a newline in the output
2096 [ @var{MMDDhhmm}[[@var{CC}]@var{YY}][.@var{ss}] ]
2099 @findex strftime @r{and @code{date}}
2100 @cindex time formats
2101 @cindex formatting times
2102 If given an argument that starts with a @samp{+}, @code{date} prints the
2103 current time and date (or the time and date specified by the
2104 @code{--date} option, see below) in the format defined by that argument,
2105 which is the same as in the @code{strftime} function. Except for
2106 directives, which start with @samp{%}, characters in the format string
2107 are printed unchanged. The directives are described below.
2110 * Time directives:: %[HIklMprsSTXZ]
2111 * Date directives:: %[aAbBcdDhjmUwWxyY]
2112 * Literal directives:: %[%nt]
2113 * Padding:: Pad with zeroes, spaces (%_), or nothing (%-).
2114 * Setting the time:: Changing the system clock.
2115 * Options for date:: Instead of the current time.
2116 * Examples of date:: Examples.
2119 @node Time directives
2120 @subsection Time directives
2122 @cindex time directives
2123 @cindex directives, time
2125 @code{date} directives related to times.
2137 minute (00@dots{}59)
2141 time, 12-hour (hh:mm:ss [AP]M)
2143 @cindex epoch, seconds since
2144 @cindex seconds since the epoch
2145 @cindex beginning of time
2146 seconds since the epoch, i.e., 1 January 1970 00:00:00 UTC (a
2149 second (00@dots{}61)
2151 time, 24-hour (hh:mm:ss)
2153 locale's time representation (%H:%M:%S)
2155 timezone (e.g., EDT), or nothing if no timezone is
2160 @node Date directives
2161 @subsection Date directives
2163 @cindex date directives
2164 @cindex directives, date
2166 @code{date} directives related to dates.
2170 locale's abbreviated weekday name (Sun@dots{}Sat)
2172 locale's full weekday name, variable length (Sunday@dots{}Saturday)
2174 locale's abbreviated month name (Jan@dots{}Dec)
2176 locale's full month name, variable length (January@dots{}December)
2178 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
2180 day of month (01@dots{}31)
2186 day of year (001@dots{}366)
2190 week number of year with Sunday as first day of week (00@dots{}53)
2192 day of week (0@dots{}6) with 0 corresponding to Sunday
2194 week number of year with Monday as first day of week (00@dots{}53)
2196 locale's date representation (mm/dd/yy)
2198 last two digits of year (00@dots{}99)
2204 @node Literal directives
2205 @subsection Literal directives
2207 @cindex literal directives
2208 @cindex directives, literal
2210 @code{date} directives that produce literal strings.
2225 @cindex numeric field padding
2226 @cindex padding of numeric fields
2227 @cindex fields, padding numeric
2229 By default, @code{date} pads numeric fields with zeroes, so that, for
2230 example, numeric months are always output as two digits. GNU @code{date}
2231 recognizes the following numeric modifiers between the @samp{%} and the
2236 (hyphen) do not pad the field; useful if the output is intended for
2239 (underscore) pad the field with spaces; useful if you need a fixed
2240 number of characters in the output, but zeroes are too distracting.
2244 These are GNU extensions.
2246 Here is an example illustrating the differences:
2249 date +%d/%m -d "Feb 1"
2251 date +%-d/%-m -d "Feb 1"
2253 date +%_d/%_m -d "Feb 1"
2258 @node Setting the time
2259 @subsection Setting the time
2261 @cindex setting the time
2262 @cindex time setting
2263 @cindex appropriate privileges
2265 If given an argument that does not start with @samp{+}, @code{date} sets
2266 the system clock to the time and date specified by that argument (as
2267 described below). You must have appropriate privileges to set the
2268 system clock. The @samp{--date} and @samp{--set} options may not be
2269 used with such an argument. The @samp{--universal} option may be used
2270 with such an argument to indicate that the specified time and date are
2271 relative to Coordinated Universal Time rather than to the local time
2274 The argument must consist entirely of digits, which have the following
2287 first two digits of year (optional)
2289 last two digits of year (optional)
2294 The @samp{--set} option also sets the system clock; see the next section.
2297 @node Options for date
2298 @subsection Options for @code{date}
2300 @cindex @code{date} options
2301 @cindex options for @code{date}
2303 The program accepts the following options. Also see @ref{Common options}.
2307 @item -d @var{datestr}
2308 @itemx --date=@var{datestr}
2311 @cindex parsing date strings
2312 @cindex date strings, parsing
2313 @cindex arbitrary date strings, parsing
2316 @opindex next @var{day}
2317 @opindex last @var{day}
2318 Display the time and date specified in @var{datestr} instead of the
2319 current time and date. @var{datestr} can be in almost any common
2320 format. It can contain month names, timezones, @samp{am} and @samp{pm},
2321 @samp{yesterday}, @samp{ago}, @samp{next}, etc. @xref{Date input formats}.
2323 @item -f @var{datefile}
2324 @itemx --file=@var{datefile}
2327 Parse each line in @var{datefile} as with @samp{-d} and display the
2328 resulting time and date. If @var{datefile} is @samp{-}, use standard
2329 input. This is useful when you have many dates to process, because the
2330 system overhead of starting up the @code{date} executable many times can
2333 @item -s @var{datestr}
2334 @itemx --set=@var{datestr}
2337 Set the time and date to @var{datestr}, See @samp{-d} above.
2344 @opindex --universal
2345 @cindex coordinated universal time
2346 @cindex Greenwich Mean Time
2347 Print or set the time and date in Universal Coordinated Time instead of
2348 in local (wall clock) time.
2353 @node Examples of date
2354 @subsection Examples of @code{date}
2356 @cindex examples of @code{date}
2358 Here are a few examples. Also see the documentation for the @samp{-d}
2359 option in the previous section.
2364 To print the date of the day before yesterday:
2367 date --date='2 days ago'
2371 To print the date of the day three months and one day hence:
2373 date --date='3 months 1 day'
2377 To print the day of year of Christmas in the current year:
2379 date --date='25 Dec' +%j
2383 To print the current full month name and the day of the month:
2388 But this may not be what you want because for the first nine days of
2389 the month, the @samp{%d} expands to a zero-padded two-digit field,
2390 for example @samp{date -d 1may '+%B %d'} will print @samp{May 01}.
2393 To print a date without the leading zero for one-digit days
2394 of the month, you can use the (GNU extension) @code{-} modifier to suppress
2395 the padding altogether.
2397 date -d=1may '+%B %-d'
2401 To print the current date and time in the format required by many
2402 non-GNU versions of @code{date} when setting the system clock:
2408 To set the system clock forward by two minutes:
2410 date --set='+2 minutes'
2416 @node uname invocation
2417 @section @code{uname}: Print system information
2420 @cindex print system information
2421 @cindex system information, printing
2423 @code{uname} prints information about the machine and operating system
2424 it is run on. If no options are given, @code{uname} acts as if the
2425 @code{-s} option were given.
2430 uname [@var{option}]@dots{}
2433 If multiple options or @code{-a} are given, the selected information is
2434 printed in this order:
2437 @var{sysname} @var{nodename} @var{release} @var{osversion} @var{machine}
2440 The @var{osversion}, at least, may well be multiple words. For example:
2444 @result{} Linux hayley 1.0.4 #3 Thu May 12 18:06:34 1994 i486
2448 The program accepts the following options. Also see @ref{Common options}.
2456 Print all of the below information.
2462 @cindex machine type
2463 @cindex hardware type
2464 Print the machine (hardware) type.
2472 @cindex network node name
2473 Print the machine's network node hostname.
2479 @cindex operating system release
2480 @cindex release of operating system
2481 Print the operating system release.
2487 @cindex operating system name
2488 @cindex name of operating system
2489 Print the operating system name.
2493 @cindex operating system version
2494 @cindex version of operating system
2495 Print the operating system version.
2500 @node hostname invocation
2501 @section @code{hostname}: Print or set system name
2504 @cindex setting the hostname
2505 @cindex printing the hostname
2506 @cindex system name, printing
2507 @cindex appropriate privileges
2509 With no arguments, @code{hostname} prints the name of the current host
2510 system. With one argument, it sets the current host name to the
2511 specified string. You must have appropriate privileges to set the host
2517 hostname [@var{name}]
2520 The only options are @samp{--help} and @samp{--version}. @xref{Common
2524 @node Modified command invocation
2525 @chapter Modified command invocation
2527 @cindex modified command invocation
2528 @cindex invocation of commands, modified
2529 @cindex commands for invoking other commands
2531 This section describes commands that run other commands in some context
2532 different than the current one: a modified environment, as a different
2536 * env invocation:: Modify environment variables.
2537 * nice invocation:: Modify scheduling priority.
2538 * nohup invocation:: Immunize to hangups.
2539 * su invocation:: Modify user and group id.
2543 @node env invocation
2544 @section @code{env}: Run a command in a modified environment
2547 @cindex environment, running a program in a modified
2548 @cindex modified environment, running a program in
2550 @code{env} runs a command with an environment modified as specified
2551 by the command line arguments.
2556 env [@var{option}]@dots{} [@var{name}=@var{value}]@dots{} @c
2557 [@var{command} [@var{args}]@dots{}]
2561 Arguments of the form @samp{@var{variable}=@var{value}} set
2562 the environment variable @var{variable} to value @var{value}.
2563 @var{value} may be empty (@samp{@var{variable}=}). Setting a variable
2564 to an empty value is different from unsetting it.
2567 The first remaining argument specifies the program name to invoke; it is
2568 searched for according to the @code{PATH} environment variable. Any
2569 remaining arguments are passed as arguments to that program.
2571 @cindex environment, printing
2573 If no command name is specified following the environment
2574 specifications, the resulting environment is printed. This is like
2575 specifying a command name of @code{printenv}.
2577 The program accepts the following options. Also see @ref{Common options}.
2582 @itemx --unset=@var{name}
2585 Remove variable @var{name} from the environment, if it was in the
2590 @itemx --ignore-environment
2593 @opindex --ignore-environment
2594 Start with an empty environment, ignoring the inherited environment.
2599 @node nice invocation
2600 @section @code{nice}: Run a command with modified scheduling priority
2603 @cindex modifying scheduling priority
2604 @cindex scheduling priority, modifying
2605 @cindex priority, modifying
2606 @cindex appropriate privileges
2608 If no arguments are given, @code{nice} prints the current scheduling
2609 priority, which it inherited. Otherwise, @code{nice} runs the given
2610 @var{command} with its scheduling priority adjusted. If no
2611 @var{adjustment} is given, the priority of the command is incremented by
2612 10. You must have appropriate privileges to specify a negative
2613 adjustment. The priority can be adjusted by @code{nice} over the range
2614 of -20 (the highest priority) to 19 (the lowest).
2619 nice [@var{option}]@dots{} [@var{command} [@var{arg}]@dots{}]
2622 @cindex conflicts with shell built-ins
2623 @cindex built-in shell commands, conflicts with
2624 Because most shells have a built-in command by the same name, using the
2625 unadorned command name in a script or interactively may get you
2626 different functionality than that described here.
2628 The program accepts the following option. Also see @ref{Common options}.
2631 @item -n @var{adjustment}
2632 @itemx -@var{adjustment}
2633 @itemx --adjustment=@var{adjustment}
2635 @opindex --adjustment
2636 @opindex -@var{adjustment}
2637 Add @var{adjustment} instead of 10 to the command's priority.
2641 @node nohup invocation
2642 @section @code{nohup}: Run a command immune to hangups
2645 @cindex hangups, immunity to
2646 @cindex immunity to hangups
2649 @code{nohup} runs the given @var{command} with hangup signals ignored,
2650 so that the command can continue running in the background after you log
2656 nohup @var{command} [@var{arg}]@dots{}
2660 Also, the scheduling priority is increased by 5. If standard output is a
2661 tty, it and standard error are redirected so that they are appended to
2662 the file @file{nohup.out}; if that cannot be written to, they are
2663 appended to the file @file{$HOME/nohup.out}. If that cannot be written
2664 to, the command is not run.
2666 If @code{nohup} creates either @file{nohup.out} or
2667 @file{$HOME/nohup.out}, it creates it with no ``group'' or ``other''
2668 access permissions. It does not change the permissions if the output
2669 file already existed.
2671 @code{nohup} does not automatically put the command it runs in the
2672 background; you must do that explicitly, by ending the command line
2675 The only options are @samp{--help} and @samp{--version}. @xref{Common
2680 @section @code{su}: Run a command with substitute user and group id
2683 @cindex substitute user and group ids
2684 @cindex user id, switching
2685 @cindex super-user, becoming
2686 @cindex root, becoming
2688 @code{su} allows one user to temporarily become another user. It runs a
2689 command (often an interactive shell) with the real and effective user
2690 id, group id, and supplemental groups of a given @var{user}.
2695 su [@var{option}]@dots{} [@var{user} [@var{arg}]@dots{}]
2698 @cindex passwd entry, and @code{su} shell
2700 @flindex /etc/passwd
2701 If no @var{user} is given, the default is @code{root}, the super-user.
2702 The shell to use is taken from @var{user}'s @code{passwd} entry, or
2703 @file{/bin/sh} if none is specified there. If @var{user} has a
2704 password, @code{su} prompts for the password unless run by a user with
2705 effective user id of zero (the super-user).
2712 By default, @code{su} does not change the current directory.
2713 It sets the environment variables @code{HOME} and @code{SHELL}
2714 from the password entry for @var{user}, and if @var{user} is not
2715 the super-user, sets @code{USER} and @code{LOGNAME} to @var{user}.
2716 By default, the shell is not a login shell.
2718 Any additional @var{arg}s are passed as additional arguments to the
2722 GNU @code{su} does not treat @file{/bin/sh} or any other shells specially
2723 (e.g., by setting @code{argv[0]} to @samp{-su}, passing @code{-c} only
2724 to certain shells, etc.).
2727 @code{su} can optionally be compiled to use @code{syslog} to report
2728 failed, and optionally successful, @code{su} attempts. (If the system
2729 supports @code{syslog}.) However, GNU @code{su} does not check if the
2730 user is a member of the @code{wheel} group; see below.
2732 The program accepts the following options. Also see @ref{Common options}.
2735 @item -c @var{command}
2736 @itemx --command=@var{command}
2739 Pass @var{command}, a single command line to run, to the shell with
2740 a @code{-c} option instead of starting an interactive shell.
2747 @cindex file name pattern expansion, disabled
2748 @cindex globbing, disabled
2749 Pass the @code{-f} option to the shell. This probably only makes sense
2750 if the shell run is @code{csh} or @code{tcsh}, for which the @code{-f}
2751 option prevents reading the startup file (@file{.cshrc}). With
2752 Bourne-like shells, the @code{-f} option disables file name pattern
2753 expansion (globbing), which is not likely to be useful.
2761 @c other variables already indexed above
2764 @cindex login shell, creating
2765 Make the shell a login shell. This means the following. Unset all
2766 environment variables except @code{TERM}, @code{HOME}, and @code{SHELL}
2767 (which are set as described above), and @code{USER} and @code{LOGNAME}
2768 (which are set, even for the super-user, as described above), and set
2769 @code{PATH} to a compiled-in default value. Change to @var{user}'s home
2770 directory. Prepend @samp{-} to the shell's name, intended to make it
2771 read its login startup file(s).
2775 @itemx --preserve-environment
2778 @opindex --preserve-environment
2779 @cindex environment, preserving
2780 @flindex /etc/shells
2781 @cindex restricted shell
2782 Do not change the environment variables @code{HOME}, @code{USER},
2783 @code{LOGNAME}, or @code{SHELL}. Run the shell given in the environment
2784 variable @code{SHELL} instead of the shell from @var{user}'s passwd
2785 entry, unless the user running @code{su} is not the superuser and
2786 @var{user}'s shell is restricted. A @dfn{restricted shell} is one that
2787 is not listed in the file @file{/etc/shells}, or in a compiled-in list
2788 if that file does not exist. Parts of what this option does can be
2789 overridden by @code{--login} and @code{--shell}.
2791 @item -s @var{shell}
2792 @itemx --shell=@var{shell}
2795 Run @var{shell} instead of the shell from @var{user}'s passwd entry,
2796 unless the user running @code{su} is not the superuser and @var{user}'s
2797 shell is restricted (see @samp{-m} just above).
2801 @cindex wheel group, not supported
2802 @cindex group wheel, not supported
2804 @heading Why GNU @code{su} does not support the @samp{wheel} group
2806 (This section is by Richard Stallman.)
2810 Sometimes a few of the users try to hold total power over all the
2811 rest. For example, in 1984, a few users at the MIT AI lab decided to
2812 seize power by changing the operator password on the Twenex system and
2813 keeping it secret from everyone else. (I was able to thwart this coup
2814 and give power back to the users by patching the kernel, but I
2815 wouldn't know how to do that in Unix.)
2817 However, occasionally the rulers do tell someone. Under the usual
2818 @code{su} mechanism, once someone learns the root password who
2819 sympathizes with the ordinary users, he or she can tell the rest. The
2820 ``wheel group'' feature would make this impossible, and thus cement the
2821 power of the rulers.
2823 I'm on the side of the masses, not that of the rulers. If you are
2824 used to supporting the bosses and sysadmins in whatever they do, you
2825 might find this idea strange at first.
2831 @cindex delaying commands
2832 @cindex commands for delaying
2834 Perhaps @code{wait} or other commands should be described here also?
2837 * sleep invocation:: Delay for a specified time.
2841 @node sleep invocation
2842 @section @code{sleep}: Delay for a specified time
2845 @cindex delay for a specified time
2847 @code{sleep} pauses for an amount of time specified by the sum of
2848 the values of the command line arguments.
2853 sleep [@var{number}[smhd]]@dots{}
2857 Each argument is a number followed by an optional unit; the default
2858 is seconds. The units are:
2871 The only options are @samp{--help} and @samp{--version}. @xref{Common
2884 @c texinfo-column-for-description: 33