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).
21 @set Francois Fran@,{c}ois
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.
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.
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).
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
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.
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
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.
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
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
139 * Numeric operations:: factor seq
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{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}.
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}
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
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)
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.
213 Print a usage message listing all available options, then exit successfully.
217 @cindex version number, finding
218 Print the version number, then exit successfully.
223 @include getdate.texi
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.
235 * echo invocation:: Print a line of text.
236 * printf invocation:: Format and print data.
237 * yes invocation:: Print a string until interrupted.
241 @node echo invocation
242 @section @code{echo}: Print a line of text
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:
254 echo [@var{option}]@dots{} [@var{string}]@dots{}
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
301 @code{printf} does formatted printing of text. Synopsis:
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 nonzero.
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} itself, though you may need to
703 quote them to protect characters with special meaning to the shell,
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:: <colon> match substr index length quote
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, zero, or non-numeric, returns the null string.
846 @item index @var{string} @var{charset}
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}.
856 @item quote @var{token}
858 Interpret @var{token} as a string, even if it is a keyword like @var{match}
859 or an operator like @code{/}.
860 This makes it possible to test @code{expr length quote "$x"} or
861 @code{expr quote "$x" : '.*/\(.\)'} and have it do the right thing even if
862 the value of @var{$x} happens to be (for example) @code{/} or @code{index}.
863 This operator is a GNU extension. It is disabled when
864 the environment variable @var{POSIXLY_CORRECT} is set.
868 To make @code{expr} interpret keywords as strings, you must use the
869 @code{quote} operator.
872 @node Examples of expr
873 @subsection Examples of @code{expr}
875 @cindex examples of @code{expr}
876 Here are a few examples, including quoting for shell metacharacters.
878 To add 1 to the shell variable @code{foo}, in Bourne-compatible shells:
883 To print the non-directory part of the file name stored in
884 @code{$fname}, which need not contain a @code{/}.
886 expr $fname : '.*/\(^.*\)' '^|' $fname
895 @error{} expr: syntax error
896 expr index quote index a
906 @cindex commands for redirection
908 Unix shells commonly provide several forms of @dfn{redirection}---ways
909 to change the input source or output destination of a command. But one
910 useful redirection is performed by a separate command, not by the shell;
914 * tee invocation:: Redirect output to multiple files.
919 @section @code{tee}: Redirect output to multiple files
923 @cindex destinations, multiple output
924 @cindex read from stdin and write to stdout and files
926 The @code{tee} command copies standard input to standard output and also
927 to any files given as arguments. This is useful when you want not only
928 to send some data down a pipe, but also to save a copy. Synopsis:
931 tee [@var{option}]@dots{} [@var{file}]@dots{}
934 If a file being written to does not already exist, it is created. If a
935 file being written to already exists, the data it previously contained
936 is overwritten unless the @code{-a} option is used.
938 The program accepts the following options. Also see @ref{Common options}.
945 Append standard input to the given files rather than overwriting
949 @itemx --ignore-interrupts
951 @opindex --ignore-interrupts
952 Ignore interrupt signals.
957 @node File name manipulation
958 @chapter File name manipulation
960 @cindex file name manipulation
961 @cindex manipulation of file names
962 @cindex commands for file name manipulation
964 This section describes commands that manipulate file names.
967 * basename invocation:: Strip directory and suffix from a file name.
968 * dirname invocation:: Strip non-directory suffix from a file name.
969 * pathchk invocation:: Check file name portability.
973 @node basename invocation
974 @section @code{basename}: Strip directory and suffix from a file name
977 @cindex strip directory and suffix from file names
978 @cindex directory, stripping from file names
979 @cindex suffix, stripping from file names
980 @cindex file names, stripping directory and suffix
981 @cindex leading directory components, stripping
983 @code{basename} removes any leading directory components from
984 @var{name}. Synopsis:
987 basename @var{name} [@var{suffix}]
990 If @var{suffix} is specified and is identical to the end of @var{name},
991 it is removed from @var{name} as well. @code{basename} prints the
992 result on standard output.
994 The only options are @samp{--help} and @samp{--version}. @xref{Common
998 @node dirname invocation
999 @section @code{dirname}: Strip non-directory suffix from a file name
1002 @cindex directory components, printing
1003 @cindex stripping non-directory suffix
1004 @cindex non-directory suffix, stripping
1006 @code{dirname} prints all but the final slash-delimited component of
1007 a string (presumably a filename). Synopsis:
1013 If @var{name} is a single component, @code{dirname} prints @samp{.}
1014 (meaning the current directory).
1016 The only options are @samp{--help} and @samp{--version}. @xref{Common
1020 @node pathchk invocation
1021 @section @code{pathchk}: Check file name portability
1024 @cindex file names, checking validity and portability
1025 @cindex valid file names, checking for
1026 @cindex portable file names, checking for
1028 @code{pathchk} checks portability of filenames. Synopsis:
1031 pathchk [@var{option}]@dots{} @var{name}@dots{}
1034 For each @var{name}, @code{pathchk} prints a message if any of
1035 these conditions is true:
1038 one of the existing directories in @var{name} does not have search
1039 (execute) permission,
1041 the length of @var{name} is larger than its filesystem's maximum
1044 the length of one component of @var{name}, corresponding to an
1045 existing directory name, is larger than its filesystem's maximum
1046 length for a file name component.
1049 The program accepts the following option. Also see @ref{Common options}.
1054 @itemx --portability
1056 @opindex --portability
1057 Instead of performing length checks on the underlying filesystem,
1058 test the length of each file name and its components against the
1059 POSIX.1 minimum limits for portability. Also check that the file
1060 name contains no characters not in the portable file name character set.
1064 @cindex exit status of @code{pathchk}
1068 0 if all specified file names passed all of the tests,
1073 @node Working context
1074 @chapter Working context
1076 @cindex working context
1077 @cindex commands for printing the working context
1079 This section describes commands that display or alter the context in
1080 which you are working: the current directory, the terminal settings, and
1081 so forth. See also the user-related commands in the next section.
1084 * pwd invocation:: Print working directory.
1085 * stty invocation:: Print or change terminal characteristics.
1086 * printenv invocation:: Print environment variables.
1087 * tty invocation:: Print file name of terminal on standard input.
1091 @node pwd invocation
1092 @section @code{pwd}: Print working directory
1095 @cindex print name of current directory
1096 @cindex current working directory, printing
1097 @cindex working directory, printing
1099 @cindex symbolic links and @code{pwd}
1100 @code{pwd} prints the fully resolved name of the current directory.
1101 That is, all components of the printed name will be actual directory
1102 names---none will be symbolic links.
1104 @cindex conflicts with shell built-ins
1105 @cindex built-in shell commands, conflicts with
1106 Because most shells have a built-in command by the same name, using the
1107 unadorned command name in a script or interactively may get you
1108 different functionality than that described here.
1110 The only options are a lone @samp{--help} or
1111 @samp{--version}. @xref{Common options}.
1114 @node stty invocation
1115 @section @code{stty}: Print or change terminal characteristics
1118 @cindex change or print terminal settings
1119 @cindex terminal settings
1120 @cindex line settings of terminal
1122 @code{stty} prints or changes terminal characteristics, such as baud rate.
1126 stty [@var{setting}]@dots{}
1130 If given no arguments, @code{stty} prints the baud rate, line
1131 discipline number (on systems that support it), and line settings
1132 that have been changed from the values set by @samp{stty sane}.
1133 Mode reading and setting are performed on the tty line connected to
1136 @code{stty} accepts many non-option arguments that change aspects of
1137 the terminal line operation, as described below.
1139 The program accepts the following options. Also see @ref{Common options}.
1146 Print all current settings in human-readable form.
1152 @cindex machine-readable @code{stty} output
1153 Print all current settings in a form that can be used as an argument to
1154 another @code{stty} command to restore the current settings.
1158 Many settings can be turned off by preceding them with a @samp{-}.
1159 Such arguments are marked below with ``May be negated'' in their
1160 description. The descriptions themselves refer to the positive
1161 case, that is, when @emph{not} negated (unless stated otherwise,
1164 Some settings are not available on all POSIX systems, since they use
1165 extensions. Such arguments are marked below with ``Non-POSIX'' in their
1166 description. On non-POSIX systems, those or other settings also may not
1167 be available, but it's not feasible to document all the variations: just
1171 * Control:: Control settings
1172 * Input:: Input settings
1173 * Output:: Output settings
1174 * Local:: Local settings
1175 * Combination:: Combination settings
1176 * Characters:: Special characters
1177 * Special:: Special settings
1182 @subsection Control settings
1184 @cindex control settings
1190 @cindex two-way parity
1191 Generate parity bit in output and expect parity bit in input.
1198 Set odd parity (even if negated). May be negated.
1205 @cindex character size
1206 @cindex eight-bit characters
1207 Set character size to 5, 6, 7, or 8 bits.
1212 Send a hangup signal when the last process closes the tty. May be
1218 Use two stop bits per character (one if negated). May be negated.
1222 Allow input to be received. May be negated.
1226 @cindex modem control
1227 Disable modem control signals. May be negated.
1231 @cindex hardware flow control
1232 @cindex flow control, hardware
1233 @cindex RTS/CTS flow control
1234 Enable RTS/CTS flow control. Non-POSIX. May be negated.
1239 @subsection Input settings
1241 @cindex input settings
1246 @cindex breaks, ignoring
1247 Ignore break characters. May be negated.
1251 @cindex breaks, cause interrupts
1252 Make breaks cause an interrupt signal. May be negated.
1256 @cindex parity, ignoring
1257 Ignore characters with parity errors. May be negated.
1261 @cindex parity errors, marking
1262 Mark parity errors (with a 255-0-character sequence). May be negated.
1266 Enable input parity checking. May be negated.
1270 @cindex eight-bit input
1271 Clear high (8th) bit of input characters. May be negated.
1275 @cindex newline, translating to return
1276 Translate newline to carriage return. May be negated.
1280 @cindex return, ignoring
1281 Ignore carriage return. May be negated.
1285 @cindex return, translating to newline
1286 Translate carriage return to newline. May be negated.
1290 @kindex C-s/C-q flow control
1291 @cindex XON/XOFF flow control
1292 Enable XON/XOFF flow control (that is, @kbd{CTRL-S}/@kbd{CTRL-Q}). May
1299 @cindex software flow control
1300 @cindex flow control, software
1301 Enable sending of @code{stop} character when the system input buffer
1302 is almost full, and @code{start} character when it becomes almost
1303 empty again. May be negated.
1307 @cindex uppercase, translating to lowercase
1308 Translate uppercase characters to lowercase. Non-POSIX. May be
1313 Allow any character to restart output (only the start character
1314 if negated). Non-POSIX. May be negated.
1318 @cindex beeping at input buffer full
1319 Enable beeping and not flushing input buffer if a character arrives
1320 when the input buffer is full. Non-POSIX. May be negated.
1325 @subsection Output settings
1327 @cindex output settings
1328 These arguments specify output-related operations.
1333 Postprocess output. May be negated.
1337 @cindex lowercase, translating to output
1338 Translate lowercase characters to uppercase. Non-POSIX. May be
1343 @cindex return, translating to newline
1344 Translate carriage return to newline. Non-POSIX. May be negated.
1348 @cindex newline, translating to crlf
1349 Translate newline to carriage return-newline. Non-POSIX. May be
1354 Do not print carriage returns in the first column. Non-POSIX.
1359 Newline performs a carriage return. Non-POSIX. May be negated.
1363 @cindex pad instead of timing for delaying
1364 Use fill (padding) characters instead of timing for delays. Non-POSIX.
1369 @cindex pad character
1370 Use delete characters for fill instead of null characters. Non-POSIX.
1376 Newline delay style. Non-POSIX.
1383 Carriage return delay style. Non-POSIX.
1390 Horizontal tab delay style. Non-POSIX.
1395 Backspace delay style. Non-POSIX.
1400 Vertical tab delay style. Non-POSIX.
1405 Form feed delay style. Non-POSIX.
1410 @subsection Local settings
1412 @cindex local settings
1417 Enable @code{interrupt}, @code{quit}, and @code{suspend} special
1418 characters. May be negated.
1422 Enable @code{erase}, @code{kill}, @code{werase}, and @code{rprnt}
1423 special characters. May be negated.
1427 Enable non-POSIX special characters. May be negated.
1431 Echo input characters. May be negated.
1437 Echo @code{erase} characters as backspace-space-backspace. May be
1442 @cindex newline echoing after @code{kill}
1443 Echo a newline after a @code{kill} character. May be negated.
1447 @cindex newline, echoing
1448 Echo newline even if not echoing other characters. May be negated.
1452 @cindex flushing, disabling
1453 Disable flushing after @code{interrupt} and @code{quit} special
1454 characters. May be negated.
1458 @cindex case translation
1459 Enable input and output of uppercase characters by preceding their
1460 lowercase equivalents with @samp{\}, when @code{icanon} is set.
1461 Non-POSIX. May be negated.
1465 @cindex background jobs, stopping at terminal write
1466 Stop background jobs that try to write to the terminal. Non-POSIX.
1473 Echo erased characters backward, between @samp{\} and @samp{/}.
1474 Non-POSIX. May be negated.
1480 @cindex control characters, using @samp{^@var{c}}
1481 @cindex hat notation for control characters
1482 Echo control characters in hat notation (@samp{^@var{c}}) instead
1483 of literally. Non-POSIX. May be negated.
1489 Echo the @code{kill} special character by erasing each character on
1490 the line as indicated by the @code{echoprt} and @code{echoe} settings,
1491 instead of by the @code{echoctl} and @code{echok} settings. Non-POSIX.
1497 @subsection Combination settings
1499 @cindex combination settings
1500 Combination settings:
1507 Same as @code{parenb -parodd cs7}. May be negated. If negated, same
1508 as @code{-parenb cs8}.
1512 Same as @code{parenb parodd cs7}. May be negated. If negated, same
1513 as @code{-parenb cs8}.
1517 Same as @code{-icrnl -onlcr}. May be negated. If negated, same as
1518 @code{icrnl -inlcr -igncr onlcr -ocrnl -onlret}.
1522 Reset the @code{erase} and @code{kill} special characters to their default
1528 @c This is too long to write inline.
1530 cread -ignbrk brkint -inlcr -igncr icrnl -ixoff -iuclc -ixany
1531 imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel
1532 nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl
1533 -noflsh -xcase -tostop -echoprt echoctl echoke
1535 @noindent and also sets all special characters to their default values.
1539 Same as @code{brkint ignpar istrip icrnl ixon opost isig icanon}, plus
1540 sets the @code{eof} and @code{eol} characters to their default values
1541 if they are the same as the @code{min} and @code{time} characters.
1542 May be negated. If negated, same as @code{raw}.
1548 -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr
1549 -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -isig -icanon
1552 @noindent May be negated. If negated, same as @code{cooked}.
1556 Same as @code{-icanon}. May be negated. If negated, same as
1561 @cindex eight-bit characters
1562 Same as @code{-parenb -istrip cs8}. May be negated. If negated,
1563 same as @code{parenb istrip cs7}.
1567 Same as @code{-parenb -istrip -opost cs8}. May be negated.
1568 If negated, same as @code{parenb istrip opost cs7}.
1572 Same as @code{-ixany}. Non-POSIX. May be negated.
1576 Same as @code{tab0}. Non-POSIX. May be negated. If negated, same
1583 Same as @code{xcase iuclc olcuc}. Non-POSIX. May be negated.
1587 Same as @code{echoe echoctl echoke}.
1591 Same as @code{echoe echoctl echoke -ixany intr ^C erase ^? kill C-u}.
1596 @subsection Special characters
1598 @cindex special characters
1599 @cindex characters, special
1601 The special characters' default values vary from system to system.
1602 They are set with the syntax @samp{name value}, where the names are
1603 listed below and the value can be given either literally, in hat
1604 notation (@samp{^@var{c}}), or as an integer which may start with
1605 @samp{0x} to indicate hexadecimal, @samp{0} to indicate octal, or
1606 any other digit to indicate decimal.
1608 @cindex disabling special characters
1609 @kindex u@r{, and disabling special characters}
1610 For GNU stty, giving a value of @code{^-} or @code{undef} disables that
1611 special character. (This is incompatible with Ultrix @code{stty},
1612 which uses a value of @samp{u} to disable a special character. GNU
1613 @code{stty} treats a value @samp{u} like any other, namely to set that
1614 special character to @key{U}.)
1620 Send an interrupt signal.
1628 Erase the last character typed.
1632 Erase the current line.
1636 Send an end of file (terminate the input).
1644 Alternate character to end the line. Non-POSIX.
1648 Switch to a different shell layer. Non-POSIX.
1652 Restart the output after stopping it.
1660 Send a terminal stop signal.
1664 Send a terminal stop signal after flushing the input. Non-POSIX.
1668 Redraw the current line. Non-POSIX.
1672 Erase the last word typed. Non-POSIX.
1676 Enter the next character typed literally, even if it is a special
1677 character. Non-POSIX.
1682 @subsection Special settings
1684 @cindex special settings
1689 Set the minimum number of characters that will satisfy a read until
1690 the time value has expired, when @code{-icanon} is set.
1694 Set the number of tenths of a second before reads time out if the min
1695 number of characters have not been read, when @code{-icanon} is set.
1697 @item ispeed @var{n}
1699 Set the input speed to @var{n}.
1701 @item ospeed @var{n}
1703 Set the output speed to @var{n}.
1707 Tell the tty kernel driver that the terminal has @var{n} rows. Non-POSIX.
1710 @itemx columns @var{n}
1713 Tell the kernel that the terminal has @var{n} columns. Non-POSIX.
1719 Print the number of rows and columns that the kernel thinks the
1720 terminal has. (Systems that don't support rows and cols in the kernel
1721 typically use the environment variables @code{LINES} and @code{COLUMNS}
1722 instead; however, GNU @code{stty} does not know anything about them.)
1727 Use line discipline @var{n}. Non-POSIX.
1731 Print the terminal speed.
1734 @cindex baud rate, setting
1735 Set the input and output speeds to @var{n}. @var{n} can be one
1736 of: 0 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600
1737 19200 38400 @code{exta} @code{extb}. @code{exta} is the same as
1738 19200; @code{extb} is the same as 38400. 0 hangs up the line if
1739 @code{-clocal} is set.
1743 @node printenv invocation
1744 @section @code{printenv}: Print all or some environment variables
1747 @cindex printing all or some environment variables
1748 @cindex environment variables, printing
1750 @code{printenv} prints environment variable values. Synopsis:
1753 printenv [@var{option}] [@var{variable}]@dots{}
1756 If no @var{variable}s are specified, @code{printenv} prints the value of
1757 every environment variable. Otherwise, it prints the value of each
1758 @var{variable} that is set, and nothing for those that are not set.
1760 The only options are a lone @samp{--help} or @samp{--version}.
1761 @xref{Common options}.
1763 @cindex exit status of @code{printenv}
1767 0 if all variables specified were found
1768 1 if at least one specified variable was not found
1769 2 if a write error occurred
1773 @node tty invocation
1774 @section @code{tty}: Print file name of terminal on standard input
1777 @cindex print terminal file name
1778 @cindex terminal file name, printing
1780 @code{tty} prints the file name of the terminal connected to its standard
1781 input. It prints @samp{not a tty} if standard input is not a terminal.
1785 tty [@var{option}]@dots{}
1788 The program accepts the following option. Also see @ref{Common options}.
1798 Print nothing; only return an exit status.
1802 @cindex exit status of @code{tty}
1806 0 if standard input is a terminal
1807 1 if standard input is not a terminal
1808 2 if given incorrect arguments
1809 3 if a write error occurs
1813 @node User information
1814 @chapter User information
1816 @cindex user information, commands for
1817 @cindex commands for printing user information
1819 This section describes commands that print user-related information:
1820 logins, groups, and so forth.
1823 * id invocation:: Print real and effective uid and gid.
1824 * logname invocation:: Print current login name.
1825 * whoami invocation:: Print effective user id.
1826 * groups invocation:: Print group names a user is in.
1827 * users invocation:: Print login names of users currently logged in.
1828 * who invocation:: Print who is currently logged in.
1833 @section @code{id}: Print real and effective uid and gid
1836 @cindex real uid and gid, printing
1837 @cindex effective uid and gid, printing
1838 @cindex printing real and effective uid and gid
1840 @code{id} prints information about the given user, or the process
1841 running it if no user is specified. Synopsis:
1844 id [@var{option}]@dots{} [@var{username}]
1847 By default, it prints the real user id, real group id, effective user id
1848 if different from the real user id, effective group id if different from
1849 the real group id, and supplemental group ids.
1851 Each of these numeric values is preceded by an identifying string and
1852 followed by the corresponding user or group name in parentheses.
1854 The options cause @code{id} to print only part of the above information.
1855 Also see @ref{Common options}.
1862 Print only the group id.
1868 Print only the supplementary groups.
1874 Print the user or group name instead of the ID number. Requires
1875 @code{-u}, @code{-g}, or @code{-G}.
1881 Print the real, instead of effective, user or group id. Requires
1882 @code{-u}, @code{-g}, or @code{-G}.
1888 Print only the user id.
1893 @node logname invocation
1894 @section @code{logname}: Print current login name
1897 @cindex printing user's login name
1898 @cindex login name, printing
1899 @cindex user name, printing
1904 @code{logname} prints the calling user's name, as found in the file
1905 @file{/etc/utmp}, and exits with a status of 0. If there is no
1906 @file{/etc/utmp} entry for the calling process, @code{logname} prints
1907 an error message and exits with a status of 1.
1909 The only options are @samp{--help} and @samp{--version}. @xref{Common
1913 @node whoami invocation
1914 @section @code{whoami}: Print effective user id
1917 @cindex effective UID, printing
1918 @cindex printing the effective UID
1920 @code{whoami} prints the user name associated with the current
1921 effective user id. It is equivalent to the command @samp{id -un}.
1923 The only options are @samp{--help} and @samp{--version}. @xref{Common
1927 @node groups invocation
1928 @section @code{groups}: Print group names a user is in
1931 @cindex printing groups a user is in
1932 @cindex supplementary groups, printing
1934 @code{groups} prints the names of the primary and any supplementary
1935 groups for each given @var{username}, or the current process if no names
1936 are given. If names are given, the name of each user is printed before
1937 the list of that user's groups. Synopsis:
1940 groups [@var{username}]@dots{}
1943 The group lists are equivalent to the output of the command @samp{id -Gn}.
1945 The only options are @samp{--help} and @samp{--version}. @xref{Common
1949 @node users invocation
1950 @section @code{users}: Print login names of users currently logged in
1953 @cindex printing current usernames
1954 @cindex usernames, printing current
1956 @cindex login sessions, printing users with
1957 @code{users} prints on a single line a blank-separated list of user
1958 names of users currently logged in to the current host. Each user name
1959 corresponds to a login session, so if a user has more than one login
1960 session, that user's name will appear the same number of times in the
1969 With no @var{file} argument, @code{users} extracts its information from
1970 the file @file{/etc/utmp}. If a file argument is given, @code{users}
1971 uses that file instead. A common choice is @file{/etc/wtmp}.
1973 The only options are @samp{--help} and @samp{--version}. @xref{Common
1977 @node who invocation
1978 @section @code{who}: Print who is currently logged in
1981 @cindex printing current user information
1982 @cindex information, about current users
1984 @code{who} prints information about users who are currently logged on.
1988 @code{who} [@var{option}] [@var{file}] [am i]
1991 @cindex terminal lines, currently used
1993 @cindex remote hostname
1994 If given no non-option arguments, @code{who} prints the following
1995 information for each user currently logged on: login name, terminal
1996 line, login time, and remote hostname or X display.
2000 If given one non-option argument, @code{who} uses that instead of
2001 @file{/etc/utmp} as the name of the file containing the record of
2002 users logged on. @file{/etc/wtmp} is commonly given as an argument
2003 to @code{who} to look at who has previously logged on.
2007 If given two non-option arguments, @code{who} prints only the entry
2008 for the user running it (determined from its standard input), preceded
2009 by the hostname. Traditionally, the two arguments given are @samp{am
2010 i}, as in @samp{who am i}.
2012 The program accepts the following options. Also see @ref{Common options}.
2017 Same as @samp{who am i}.
2023 Print only the login names and the number of users logged on.
2024 Overrides all other options.
2028 Ignored; for compatibility with other versions of @code{who}.
2037 After the login time, print the number of hours and minutes that the
2038 user has been idle. @samp{.} means the user was active in last minute.
2039 @samp{old} means the user was idle for more than 24 hours.
2045 Print a line of column headings.
2057 @cindex message status
2058 @pindex write@r{, allowed}
2059 After each login name print a character indicating the user's message status:
2062 @samp{+} allowing @code{write} messages
2063 @samp{-} disallowing @code{write} messages
2064 @samp{?} cannot find terminal device
2070 @node System context
2071 @chapter System context
2073 @cindex system context
2074 @cindex context, system
2075 @cindex commands for system context
2077 This section describes commands that print or change system-wide
2081 * date invocation:: Print or set system date and time.
2082 * uname invocation:: Print system information.
2083 * hostname invocation:: Print or set system name.
2087 @node date invocation
2088 @section @code{date}: Print or set system date and time
2091 @cindex time, printing or setting
2092 @cindex printing the current time
2094 @code{date} with no arguments prints the current time and date, in the
2095 format of the @samp{%c} directive (described below). Synopses:
2098 date [@var{option}]@dots{} [+@var{format}]
2099 date [-u|--utc|--universal] @c this avoids a newline in the output
2100 [ @var{MMDDhhmm}[[@var{CC}]@var{YY}][.@var{ss}] ]
2103 @findex strftime @r{and @code{date}}
2104 @cindex time formats
2105 @cindex formatting times
2106 If given an argument that starts with a @samp{+}, @code{date} prints the
2107 current time and date (or the time and date specified by the
2108 @code{--date} option, see below) in the format defined by that argument,
2109 which is the same as in the @code{strftime} function. Except for
2110 directives, which start with @samp{%}, characters in the format string
2111 are printed unchanged. The directives are described below.
2114 * Time directives:: %[HIklMprsSTXzZ]
2115 * Date directives:: %[aAbBcdDhjmUwWxyY]
2116 * Literal directives:: %[%nt]
2117 * Padding:: Pad with zeroes, spaces (%_), or nothing (%-).
2118 * Setting the time:: Changing the system clock.
2119 * Options for date:: Instead of the current time.
2120 * Examples of date:: Examples.
2123 @node Time directives
2124 @subsection Time directives
2126 @cindex time directives
2127 @cindex directives, time
2129 @code{date} directives related to times.
2141 minute (00@dots{}59)
2145 time, 12-hour (hh:mm:ss [AP]M)
2147 @cindex epoch, seconds since
2148 @cindex seconds since the epoch
2149 @cindex beginning of time
2150 seconds since the epoch, i.e., 1 January 1970 00:00:00 UTC (a
2152 Note that this value is the number of seconds between the epoch
2153 and the current date as defined by the localtime system call.
2154 It isn't changed by the @samp{--date} option.
2156 second (00@dots{}61)
2158 time, 24-hour (hh:mm:ss)
2160 locale's time representation (%H:%M:%S)
2162 RFC-822 style numeric time zone (e.g., -0600 or +0100), or nothing if no
2163 time zone is determinable. This value reflects the @emph{current} time
2164 zone. It isn't changed by the @samp{--date} option.
2166 time zone (e.g., EDT), or nothing if no timezone is
2168 Note that this value reflects the @emph{current} time zone.
2169 It isn't changed by the @samp{--date} option.
2173 @node Date directives
2174 @subsection Date directives
2176 @cindex date directives
2177 @cindex directives, date
2179 @code{date} directives related to dates.
2183 locale's abbreviated weekday name (Sun@dots{}Sat)
2185 locale's full weekday name, variable length (Sunday@dots{}Saturday)
2187 locale's abbreviated month name (Jan@dots{}Dec)
2189 locale's full month name, variable length (January@dots{}December)
2191 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
2193 day of month (01@dots{}31)
2199 day of year (001@dots{}366)
2203 week number of year with Sunday as first day of week (00@dots{}53).
2204 Days in a new year preceding the first Sunday are in week zero.
2206 week number of year with Monday as first day of the week as a decimal
2207 (01@dots{}53). If the week containing January 1 has four or more days in
2208 the new year, then it is considered week 1; otherwise, it is week 53 of
2209 the previous year, and the next week is week 1. (See the ISO 8601: 1988
2212 day of week (0@dots{}6) with 0 corresponding to Sunday
2214 week number of year with Monday as first day of week (00@dots{}53).
2215 Days in a new year preceding the first Monday are in week zero.
2217 locale's date representation (mm/dd/yy)
2219 last two digits of year (00@dots{}99)
2225 @node Literal directives
2226 @subsection Literal directives
2228 @cindex literal directives
2229 @cindex directives, literal
2231 @code{date} directives that produce literal strings.
2246 @cindex numeric field padding
2247 @cindex padding of numeric fields
2248 @cindex fields, padding numeric
2250 By default, @code{date} pads numeric fields with zeroes, so that, for
2251 example, numeric months are always output as two digits. GNU @code{date}
2252 recognizes the following numeric modifiers between the @samp{%} and the
2257 (hyphen) do not pad the field; useful if the output is intended for
2260 (underscore) pad the field with spaces; useful if you need a fixed
2261 number of characters in the output, but zeroes are too distracting.
2265 These are GNU extensions.
2267 Here is an example illustrating the differences:
2270 date +%d/%m -d "Feb 1"
2272 date +%-d/%-m -d "Feb 1"
2274 date +%_d/%_m -d "Feb 1"
2279 @node Setting the time
2280 @subsection Setting the time
2282 @cindex setting the time
2283 @cindex time setting
2284 @cindex appropriate privileges
2286 If given an argument that does not start with @samp{+}, @code{date} sets
2287 the system clock to the time and date specified by that argument (as
2288 described below). You must have appropriate privileges to set the
2289 system clock. The @samp{--date} and @samp{--set} options may not be
2290 used with such an argument. The @samp{--universal} option may be used
2291 with such an argument to indicate that the specified time and date are
2292 relative to Coordinated Universal Time rather than to the local time
2295 The argument must consist entirely of digits, which have the following
2308 first two digits of year (optional)
2310 last two digits of year (optional)
2315 The @samp{--set} option also sets the system clock; see the next section.
2318 @node Options for date
2319 @subsection Options for @code{date}
2321 @cindex @code{date} options
2322 @cindex options for @code{date}
2324 The program accepts the following options. Also see @ref{Common options}.
2328 @item -d @var{datestr}
2329 @itemx --date=@var{datestr}
2332 @cindex parsing date strings
2333 @cindex date strings, parsing
2334 @cindex arbitrary date strings, parsing
2337 @opindex next @var{day}
2338 @opindex last @var{day}
2339 Display the time and date specified in @var{datestr} instead of the
2340 current time and date. @var{datestr} can be in almost any common
2341 format. It can contain month names, timezones, @samp{am} and @samp{pm},
2342 @samp{yesterday}, @samp{ago}, @samp{next}, etc. @xref{Date input formats}.
2344 @item -f @var{datefile}
2345 @itemx --file=@var{datefile}
2348 Parse each line in @var{datefile} as with @samp{-d} and display the
2349 resulting time and date. If @var{datefile} is @samp{-}, use standard
2350 input. This is useful when you have many dates to process, because the
2351 system overhead of starting up the @code{date} executable many times can
2357 Display the time and date using the RFC-822-specified
2358 format, @samp{%a, %_d %b %Y %H:%M:%S %z}.
2359 If @samp{--utc} is also specified, use @samp{GMT} in place of @samp{%z}.
2362 @itemx --reference=@var{file}
2364 @opindex --reference
2365 Display the time and date reference according to the last modification
2366 time of @var{file}, instead of the current time and date.
2368 @item -s @var{datestr}
2369 @itemx --set=@var{datestr}
2372 Set the time and date to @var{datestr}, See @samp{-d} above.
2379 @opindex --universal
2380 @cindex coordinated universal time
2381 @cindex Greenwich Mean Time
2382 Print or set the time and date in Universal Coordinated Time instead of
2383 in local (wall clock) time.
2388 @node Examples of date
2389 @subsection Examples of @code{date}
2391 @cindex examples of @code{date}
2393 Here are a few examples. Also see the documentation for the @samp{-d}
2394 option in the previous section.
2399 To print the date of the day before yesterday:
2402 date --date='2 days ago'
2406 To print the date of the day three months and one day hence:
2408 date --date='3 months 1 day'
2412 To print the day of year of Christmas in the current year:
2414 date --date='25 Dec' +%j
2418 To print the current full month name and the day of the month:
2423 But this may not be what you want because for the first nine days of
2424 the month, the @samp{%d} expands to a zero-padded two-digit field,
2425 for example @samp{date -d 1may '+%B %d'} will print @samp{May 01}.
2428 To print a date without the leading zero for one-digit days
2429 of the month, you can use the (GNU extension) @code{-} modifier to suppress
2430 the padding altogether.
2432 date -d=1may '+%B %-d'
2436 To print the current date and time in the format required by many
2437 non-GNU versions of @code{date} when setting the system clock:
2443 To set the system clock forward by two minutes:
2445 date --set='+2 minutes'
2449 To print the date in the format specified by RFC-822,
2450 use @samp{date --rfc}. I just did and saw this:
2453 Mon, 25 Mar 1996 23:34:17 -0600
2457 To convert a date string to the number of seconds since 1970-01-01 00:00:00,
2458 use the @samp{--date} option with the @samp{%s} format.
2459 That can be useful in sorting and graphing data by date.
2460 The command in the following example prints the number of seconds that
2461 elapsed between the epoch and the specified date: one second after midnight
2463 But it is important to note that the date string is interpreted relative
2464 to the local time zone, UTC+2, so it is two hours and one second
2465 or @samp{7201} seconds after the @code{epoch}.
2468 % env TZ=UTC+2 date --date='1970-01-01 00:00:01' +%s
2473 If you're sorting or graphing dated data, your raw date values may be
2474 represented as seconds since the epoch. But few people can look at
2475 the date @samp{946684800} and casually note ``Oh, that's the first second
2476 of the third millenium.''
2479 % env TZ=UTC date --date='2000-01-01' +%s
2483 To convert such an unwieldy number of seconds back to
2484 a more readable form, use a command like this:
2487 % env TZ=UTC date -d '1970-01-01 UTC 946684800 sec' +"%Y-%m-%d %T %z"
2488 2000-01-01 00:00:00 +0000
2491 Note that in the few preceding examples, the timezone was set to
2492 a specific value through the @samp{TZ} environment variable.
2493 If you do not set @samp{TZ}, you must remember that @samp{--date}
2494 strings are converted relative to the local time zone.
2499 @node uname invocation
2500 @section @code{uname}: Print system information
2503 @cindex print system information
2504 @cindex system information, printing
2506 @code{uname} prints information about the machine and operating system
2507 it is run on. If no options are given, @code{uname} acts as if the
2508 @code{-s} option were given. Synopsis:
2511 uname [@var{option}]@dots{}
2514 If multiple options or @code{-a} are given, the selected information is
2515 printed in this order:
2518 @var{sysname} @var{nodename} @var{release} @var{osversion} @var{machine}
2521 The @var{osversion}, at least, may well be multiple words. For example:
2525 @result{} Linux hayley 1.0.4 #3 Thu May 12 18:06:34 1994 i486
2529 The program accepts the following options. Also see @ref{Common options}.
2537 Print all of the below information.
2543 @cindex machine type
2544 @cindex hardware type
2545 Print the machine (hardware) type.
2553 @cindex network node name
2554 Print the machine's network node hostname.
2559 @opindex --processor
2560 @cindex host processor type
2561 Print the machine's processor type
2567 @cindex operating system release
2568 @cindex release of operating system
2569 Print the operating system release.
2575 @cindex operating system name
2576 @cindex name of operating system
2577 Print the operating system name.
2581 @cindex operating system version
2582 @cindex version of operating system
2583 Print the operating system version.
2588 @node hostname invocation
2589 @section @code{hostname}: Print or set system name
2592 @cindex setting the hostname
2593 @cindex printing the hostname
2594 @cindex system name, printing
2595 @cindex appropriate privileges
2597 With no arguments, @code{hostname} prints the name of the current host
2598 system. With one argument, it sets the current host name to the
2599 specified string. You must have appropriate privileges to set the host
2603 hostname [@var{name}]
2606 The only options are @samp{--help} and @samp{--version}. @xref{Common
2610 @node Modified command invocation
2611 @chapter Modified command invocation
2613 @cindex modified command invocation
2614 @cindex invocation of commands, modified
2615 @cindex commands for invoking other commands
2617 This section describes commands that run other commands in some context
2618 different than the current one: a modified environment, as a different
2622 * chroot invocation:: Modify the root directory.
2623 * env invocation:: Modify environment variables.
2624 * nice invocation:: Modify scheduling priority.
2625 * nohup invocation:: Immunize to hangups.
2626 * su invocation:: Modify user and group id.
2630 @node chroot invocation
2631 @section @code{chroot}: Run a command with a different root directory
2634 @cindex running a program in a specified root directory
2635 @cindex root directory, running a program in a specified
2637 @code{chroot} runs a command with a specified root directory.
2638 On many systems, only the super-user can do this.
2642 chroot @var{newroot} [@var{command} [@var{args}]@dots{}]
2646 Ordinarily, filenames are looked up starting at the root of the
2647 directory structure, i.e., @file{/}. @code{chroot} changes the root to
2648 the directory @var{newroot} (which must exist) and then runs
2649 @var{command} with optional @var{args}. If @var{command} is not
2650 specified, the default is the value of the @code{SHELL} environment
2651 variable or @code{/bin/sh} if not set, invoked with the @samp{-i} option.
2653 The only options are @samp{--help} and @samp{--version}. @xref{Common
2657 @node env invocation
2658 @section @code{env}: Run a command in a modified environment
2661 @cindex environment, running a program in a modified
2662 @cindex modified environment, running a program in a
2663 @cindex running a program in a modified environment
2665 @code{env} runs a command with a modified environment. Synopses:
2668 env [@var{option}]@dots{} [@var{name}=@var{value}]@dots{} @c
2669 [@var{command} [@var{args}]@dots{}]
2673 Arguments of the form @samp{@var{variable}=@var{value}} set
2674 the environment variable @var{variable} to value @var{value}.
2675 @var{value} may be empty (@samp{@var{variable}=}). Setting a variable
2676 to an empty value is different from unsetting it.
2679 The first remaining argument specifies the program name to invoke; it is
2680 searched for according to the @code{PATH} environment variable. Any
2681 remaining arguments are passed as arguments to that program.
2683 @cindex environment, printing
2685 If no command name is specified following the environment
2686 specifications, the resulting environment is printed. This is like
2687 specifying a command name of @code{printenv}.
2689 The program accepts the following options. Also see @ref{Common options}.
2694 @itemx --unset=@var{name}
2697 Remove variable @var{name} from the environment, if it was in the
2702 @itemx --ignore-environment
2705 @opindex --ignore-environment
2706 Start with an empty environment, ignoring the inherited environment.
2711 @node nice invocation
2712 @section @code{nice}: Run a command with modified scheduling priority
2715 @cindex modifying scheduling priority
2716 @cindex scheduling priority, modifying
2717 @cindex priority, modifying
2718 @cindex appropriate privileges
2720 @code{nice} prints or modifies the scheduling priority of a job.
2724 nice [@var{option}]@dots{} [@var{command} [@var{arg}]@dots{}]
2727 If no arguments are given, @code{nice} prints the current scheduling
2728 priority, which it inherited. Otherwise, @code{nice} runs the given
2729 @var{command} with its scheduling priority adjusted. If no
2730 @var{adjustment} is given, the priority of the command is incremented by
2731 10. You must have appropriate privileges to specify a negative
2732 adjustment. The priority can be adjusted by @code{nice} over the range
2733 of -20 (the highest priority) to 19 (the lowest).
2735 @cindex conflicts with shell built-ins
2736 @cindex built-in shell commands, conflicts with
2737 Because most shells have a built-in command by the same name, using the
2738 unadorned command name in a script or interactively may get you
2739 different functionality than that described here.
2741 The program accepts the following option. Also see @ref{Common options}.
2744 @item -n @var{adjustment}
2745 @itemx -@var{adjustment}
2746 @itemx --adjustment=@var{adjustment}
2748 @opindex --adjustment
2749 @opindex -@var{adjustment}
2750 Add @var{adjustment} instead of 10 to the command's priority.
2754 @node nohup invocation
2755 @section @code{nohup}: Run a command immune to hangups
2758 @cindex hangups, immunity to
2759 @cindex immunity to hangups
2760 @cindex logging out and continuing to run
2763 @code{nohup} runs the given @var{command} with hangup signals ignored,
2764 so that the command can continue running in the background after you log
2768 nohup @var{command} [@var{arg}]@dots{}
2772 @code{nohup} increases the scheduling priority of @var{command} by 5, so
2773 it has a slightly smaller change to run. If standard output is a terminal,
2774 it and standard error are redirected so that they are appended to the
2775 file @file{nohup.out}; if that cannot be written to, they are appended
2776 to the file @file{$HOME/nohup.out}. If that cannot be written to, the
2779 If @code{nohup} creates either @file{nohup.out} or
2780 @file{$HOME/nohup.out}, it creates it with no ``group'' or ``other''
2781 access permissions. It does not change the permissions if the output
2782 file already existed.
2784 @code{nohup} does not automatically put the command it runs in the
2785 background; you must do that explicitly, by ending the command line
2788 The only options are @samp{--help} and @samp{--version}. @xref{Common
2793 @section @code{su}: Run a command with substitute user and group id
2796 @cindex substitute user and group ids
2797 @cindex user id, switching
2798 @cindex super-user, becoming
2799 @cindex root, becoming
2801 @code{su} allows one user to temporarily become another user. It runs a
2802 command (often an interactive shell) with the real and effective user
2803 id, group id, and supplemental groups of a given @var{user}. Synopsis:
2806 su [@var{option}]@dots{} [@var{user} [@var{arg}]@dots{}]
2809 @cindex passwd entry, and @code{su} shell
2811 @flindex /etc/passwd
2812 If no @var{user} is given, the default is @code{root}, the super-user.
2813 The shell to use is taken from @var{user}'s @code{passwd} entry, or
2814 @file{/bin/sh} if none is specified there. If @var{user} has a
2815 password, @code{su} prompts for the password unless run by a user with
2816 effective user id of zero (the super-user).
2823 By default, @code{su} does not change the current directory.
2824 It sets the environment variables @code{HOME} and @code{SHELL}
2825 from the password entry for @var{user}, and if @var{user} is not
2826 the super-user, sets @code{USER} and @code{LOGNAME} to @var{user}.
2827 By default, the shell is not a login shell.
2829 Any additional @var{arg}s are passed as additional arguments to the
2833 GNU @code{su} does not treat @file{/bin/sh} or any other shells specially
2834 (e.g., by setting @code{argv[0]} to @samp{-su}, passing @code{-c} only
2835 to certain shells, etc.).
2838 @code{su} can optionally be compiled to use @code{syslog} to report
2839 failed, and optionally successful, @code{su} attempts. (If the system
2840 supports @code{syslog}.) However, GNU @code{su} does not check if the
2841 user is a member of the @code{wheel} group; see below.
2843 The program accepts the following options. Also see @ref{Common options}.
2846 @item -c @var{command}
2847 @itemx --command=@var{command}
2850 Pass @var{command}, a single command line to run, to the shell with
2851 a @code{-c} option instead of starting an interactive shell.
2858 @cindex file name pattern expansion, disabled
2859 @cindex globbing, disabled
2860 Pass the @code{-f} option to the shell. This probably only makes sense
2861 if the shell run is @code{csh} or @code{tcsh}, for which the @code{-f}
2862 option prevents reading the startup file (@file{.cshrc}). With
2863 Bourne-like shells, the @code{-f} option disables file name pattern
2864 expansion (globbing), which is not likely to be useful.
2872 @c other variables already indexed above
2875 @cindex login shell, creating
2876 Make the shell a login shell. This means the following. Unset all
2877 environment variables except @code{TERM}, @code{HOME}, and @code{SHELL}
2878 (which are set as described above), and @code{USER} and @code{LOGNAME}
2879 (which are set, even for the super-user, as described above), and set
2880 @code{PATH} to a compiled-in default value. Change to @var{user}'s home
2881 directory. Prepend @samp{-} to the shell's name, intended to make it
2882 read its login startup file(s).
2886 @itemx --preserve-environment
2889 @opindex --preserve-environment
2890 @cindex environment, preserving
2891 @flindex /etc/shells
2892 @cindex restricted shell
2893 Do not change the environment variables @code{HOME}, @code{USER},
2894 @code{LOGNAME}, or @code{SHELL}. Run the shell given in the environment
2895 variable @code{SHELL} instead of the shell from @var{user}'s passwd
2896 entry, unless the user running @code{su} is not the superuser and
2897 @var{user}'s shell is restricted. A @dfn{restricted shell} is one that
2898 is not listed in the file @file{/etc/shells}, or in a compiled-in list
2899 if that file does not exist. Parts of what this option does can be
2900 overridden by @code{--login} and @code{--shell}.
2902 @item -s @var{shell}
2903 @itemx --shell=@var{shell}
2906 Run @var{shell} instead of the shell from @var{user}'s passwd entry,
2907 unless the user running @code{su} is not the superuser and @var{user}'s
2908 shell is restricted (see @samp{-m} just above).
2912 @cindex wheel group, not supported
2913 @cindex group wheel, not supported
2915 @heading Why GNU @code{su} does not support the @samp{wheel} group
2917 (This section is by Richard Stallman.)
2921 Sometimes a few of the users try to hold total power over all the
2922 rest. For example, in 1984, a few users at the MIT AI lab decided to
2923 seize power by changing the operator password on the Twenex system and
2924 keeping it secret from everyone else. (I was able to thwart this coup
2925 and give power back to the users by patching the kernel, but I
2926 wouldn't know how to do that in Unix.)
2928 However, occasionally the rulers do tell someone. Under the usual
2929 @code{su} mechanism, once someone learns the root password who
2930 sympathizes with the ordinary users, he or she can tell the rest. The
2931 ``wheel group'' feature would make this impossible, and thus cement the
2932 power of the rulers.
2934 I'm on the side of the masses, not that of the rulers. If you are
2935 used to supporting the bosses and sysadmins in whatever they do, you
2936 might find this idea strange at first.
2942 @cindex delaying commands
2943 @cindex commands for delaying
2945 @c Perhaps @code{wait} or other commands should be described here also?
2948 * sleep invocation:: Delay for a specified time.
2952 @node sleep invocation
2953 @section @code{sleep}: Delay for a specified time
2956 @cindex delay for a specified time
2958 @code{sleep} pauses for an amount of time specified by the sum of
2959 the values of the command line arguments.
2963 sleep [@var{number}[smhd]]@dots{}
2967 Each argument is a number followed by an optional unit; the default
2968 is seconds. The units are:
2981 The only options are @samp{--help} and @samp{--version}. @xref{Common
2985 @node Numeric operations
2986 @chapter Numeric operations
2988 @cindex numeric operations
2989 These programs do numerically-related operations.
2992 * factor invocation:: Show factors of numbers.
2993 * seq invocation:: Print sequences of numbers.
2997 @node factor invocation
2998 @section @code{factor}: Print prime factors
3001 @cindex prime factors
3003 @code{factor} prints prime factors. Synopses:
3006 factor [@var{number}]@dots{}
3010 If no @var{number} is specified on the command line, @code{factor} reads
3011 numbers from standard input, delimited by newlines, tabs, or spaces.
3013 The only options are @samp{--help} and @samp{--version}. @xref{Common
3017 @node seq invocation
3018 @section @code{seq}: Print numeric sequences
3021 @cindex numeric sequences
3022 @cindex sequence of numbers
3024 @code{seq} prints a sequence of numbers to standard output. Synopses:
3027 seq [@var{option}]@dots{} [@var{first} [@var{step}]] @var{last}@dots{}
3030 @code{seq} prints the numbers from @var{first} to @var{last} by
3031 @var{step}. By default, @var{first} and @var{step} are both 1, and each
3032 number is printed on its own line. All numbers can be reals, not just
3035 The program accepts the following options. Also see @ref{Common options}.
3038 @item -f @var{format}
3039 @itemx --format=@var{format}
3040 @opindex -f @var{format}
3041 @opindex --format=@var{format}
3042 @cindex formatting of numbers in @code{seq}
3043 Print all numbers using @var{format}; default @samp{%g}.
3044 @var{format} must contain exactly one of the standarding float output
3045 formats @samp{%e}, @samp{%f}, or @samp{%g}.
3047 @item -s @var{string}
3048 @itemx --separator=@var{string}
3049 @cindex separator for numbers in @code{seq}
3050 Separate numbers with @var{string}; default is a newline.
3051 The output always terminates with a newline.
3054 @itemx --equal-width
3055 Print all numbers with the same width, by padding with leading zeroes.
3056 (To have other kinds of padding, use @samp{--format}).
3070 @c texinfo-column-for-description: 33