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 * String expressions:: <colon> match substr index length quote
722 * Numeric expressions:: + - * / %
723 * Relations for expr:: | & < <= = == != >= >
724 * Examples of expr:: Examples.
728 @node String expressions
729 @subsection String expressions
731 @cindex string expressions
732 @cindex expressions, string
734 @code{expr} supports pattern matching and other string operators. These
735 have lower precedence than both the numeric and relational operators (in
740 @item @var{string} : @var{regex}
741 @cindex pattern matching
742 @cindex regular expression matching
743 @cindex matching patterns
744 Perform pattern matching. The arguments are coerced to strings and the
745 second is considered to be a (basic, a la GNU @code{grep}) regular
746 expression, with a @code{^} implicitly prepended. The first argument is
747 then matched against this regular expression.
749 If the match succeeds and @var{regex} uses @samp{\(} and @samp{\)}, the
750 @code{:} expression returns the part of @var{string} that matched the
751 subexpression; otherwise, it returns the number of characters matched.
753 If the match fails, the @code{:} operator returns the null string if
754 @samp{\(} and @samp{\)} are used in @var{regex}, otherwise 0.
756 @kindex \( @r{regexp operator}
757 Only the first @samp{\( @dots{} \)} pair is relevant to the return
758 value; additional pairs are meaningful only for grouping the regular
759 expression operators.
761 @kindex \+ @r{regexp operator}
762 @kindex \? @r{regexp operator}
763 @kindex \| @r{regexp operator}
764 In the regular expression, @code{\+}, @code{\?}, and @code{\|} are
765 operators which respectively match one or more, zero or one, or separate
766 alternatives. SunOS and other @code{expr}'s treat these as regular
767 characters. (POSIX allows either behavior.)
768 @xref{Top, , Regular Expression Library, regex, Regex}, for details of
769 regular expression syntax. Some examples are in @ref{Examples of expr}.
771 @item match @var{string} @var{regex}
773 An alternative way to do pattern matching. This is the same as
774 @w{@samp{@var{string} : @var{regex}}}.
776 @item substr @var{string} @var{position} @var{length}
778 Returns the substring of @var{string} beginning at @var{position}
779 with length at most @var{length}. If either @var{position} or
780 @var{length} is negative, zero, or non-numeric, returns the null string.
782 @item index @var{string} @var{charset}
784 Returns the first position in @var{string} where the first character in
785 @var{charset} was found. If no character in @var{charset} is found in
786 @var{string}, return 0.
788 @item length @var{string}
790 Returns the length of @var{string}.
792 @item quote @var{token}
794 Interpret @var{token} as a string, even if it is a keyword like @var{match}
795 or an operator like @code{/}.
796 This makes it possible to test @code{expr length quote "$x"} or
797 @code{expr quote "$x" : '.*/\(.\)'} and have it do the right thing even if
798 the value of @var{$x} happens to be (for example) @code{/} or @code{index}.
799 This operator is a GNU extension. It is disabled when
800 the environment variable @var{POSIXLY_CORRECT} is set.
804 To make @code{expr} interpret keywords as strings, you must use the
805 @code{quote} operator.
808 @node Numeric expressions
809 @subsection Numeric expressions
811 @cindex numeric expressions
812 @cindex expressions, numeric
814 @code{expr} supports the usual numeric operators, in order of increasing
815 precedence. The string operators (previous section) have lower precedence,
816 the connectives (next section) have higher.
825 Addition and subtraction. Both arguments are coerced to numbers;
826 an error occurs if this cannot be done.
832 @cindex multiplication
835 Multiplication, division, remainder. Both arguments are coerced to
836 numbers; an error occurs if this cannot be done.
841 @node Relations for expr
842 @subsection Relations for @code{expr}
844 @cindex connectives, logical
845 @cindex logical connectives
846 @cindex relations, numeric or string
848 @code{expr} supports the usual logical connectives and relations. These
849 are higher precedence than either the string or numeric operators
850 (previous sections). Here is the list, lowest-precedence operator first.
856 @cindex logical or operator
858 Returns its first argument if that is neither null nor 0, otherwise its
863 @cindex logical and operator
865 Return its first argument if neither argument is null or 0, otherwise
868 @item < <= = == != >= >
875 @cindex comparison operators
876 Compare the arguments and return 1 if the relation is true, 0 otherwise.
877 @code{==} is a synonym for @code{=}. @code{expr} first tries to coerce
878 both arguments to numbers and do a numeric comparison; if either
879 coercion fails, it does a lexicographic comparison.
884 @node Examples of expr
885 @subsection Examples of using @code{expr}
887 @cindex examples of @code{expr}
888 Here are a few examples, including quoting for shell metacharacters.
890 To add 1 to the shell variable @code{foo}, in Bourne-compatible shells:
895 To print the non-directory part of the file name stored in
896 @code{$fname}, which need not contain a @code{/}.
898 expr $fname : '.*/\(^.*\)' '^|' $fname
901 An example showing that @code{\+} is an operator:
913 @error{} expr: syntax error
914 expr index quote index a
923 @cindex commands for redirection
925 Unix shells commonly provide several forms of @dfn{redirection}---ways
926 to change the input source or output destination of a command. But one
927 useful redirection is performed by a separate command, not by the shell;
931 * tee invocation:: Redirect output to multiple files.
936 @section @code{tee}: Redirect output to multiple files
940 @cindex destinations, multiple output
941 @cindex read from stdin and write to stdout and files
943 The @code{tee} command copies standard input to standard output and also
944 to any files given as arguments. This is useful when you want not only
945 to send some data down a pipe, but also to save a copy. Synopsis:
948 tee [@var{option}]@dots{} [@var{file}]@dots{}
951 If a file being written to does not already exist, it is created. If a
952 file being written to already exists, the data it previously contained
953 is overwritten unless the @code{-a} option is used.
955 The program accepts the following options. Also see @ref{Common options}.
962 Append standard input to the given files rather than overwriting
966 @itemx --ignore-interrupts
968 @opindex --ignore-interrupts
969 Ignore interrupt signals.
974 @node File name manipulation
975 @chapter File name manipulation
977 @cindex file name manipulation
978 @cindex manipulation of file names
979 @cindex commands for file name manipulation
981 This section describes commands that manipulate file names.
984 * basename invocation:: Strip directory and suffix from a file name.
985 * dirname invocation:: Strip non-directory suffix from a file name.
986 * pathchk invocation:: Check file name portability.
990 @node basename invocation
991 @section @code{basename}: Strip directory and suffix from a file name
994 @cindex strip directory and suffix from file names
995 @cindex directory, stripping from file names
996 @cindex suffix, stripping from file names
997 @cindex file names, stripping directory and suffix
998 @cindex leading directory components, stripping
1000 @code{basename} removes any leading directory components from
1001 @var{name}. Synopsis:
1004 basename @var{name} [@var{suffix}]
1007 If @var{suffix} is specified and is identical to the end of @var{name},
1008 it is removed from @var{name} as well. @code{basename} prints the
1009 result on standard output.
1011 The only options are @samp{--help} and @samp{--version}. @xref{Common
1015 @node dirname invocation
1016 @section @code{dirname}: Strip non-directory suffix from a file name
1019 @cindex directory components, printing
1020 @cindex stripping non-directory suffix
1021 @cindex non-directory suffix, stripping
1023 @code{dirname} prints all but the final slash-delimited component of
1024 a string (presumably a filename). Synopsis:
1030 If @var{name} is a single component, @code{dirname} prints @samp{.}
1031 (meaning the current directory).
1033 The only options are @samp{--help} and @samp{--version}. @xref{Common
1037 @node pathchk invocation
1038 @section @code{pathchk}: Check file name portability
1041 @cindex file names, checking validity and portability
1042 @cindex valid file names, checking for
1043 @cindex portable file names, checking for
1045 @code{pathchk} checks portability of filenames. Synopsis:
1048 pathchk [@var{option}]@dots{} @var{name}@dots{}
1051 For each @var{name}, @code{pathchk} prints a message if any of
1052 these conditions is true:
1055 one of the existing directories in @var{name} does not have search
1056 (execute) permission,
1058 the length of @var{name} is larger than its filesystem's maximum
1061 the length of one component of @var{name}, corresponding to an
1062 existing directory name, is larger than its filesystem's maximum
1063 length for a file name component.
1066 The program accepts the following option. Also see @ref{Common options}.
1071 @itemx --portability
1073 @opindex --portability
1074 Instead of performing length checks on the underlying filesystem,
1075 test the length of each file name and its components against the
1076 POSIX.1 minimum limits for portability. Also check that the file
1077 name contains no characters not in the portable file name character set.
1081 @cindex exit status of @code{pathchk}
1085 0 if all specified file names passed all of the tests,
1090 @node Working context
1091 @chapter Working context
1093 @cindex working context
1094 @cindex commands for printing the working context
1096 This section describes commands that display or alter the context in
1097 which you are working: the current directory, the terminal settings, and
1098 so forth. See also the user-related commands in the next section.
1101 * pwd invocation:: Print working directory.
1102 * stty invocation:: Print or change terminal characteristics.
1103 * printenv invocation:: Print environment variables.
1104 * tty invocation:: Print file name of terminal on standard input.
1108 @node pwd invocation
1109 @section @code{pwd}: Print working directory
1112 @cindex print name of current directory
1113 @cindex current working directory, printing
1114 @cindex working directory, printing
1116 @cindex symbolic links and @code{pwd}
1117 @code{pwd} prints the fully resolved name of the current directory.
1118 That is, all components of the printed name will be actual directory
1119 names---none will be symbolic links.
1121 @cindex conflicts with shell built-ins
1122 @cindex built-in shell commands, conflicts with
1123 Because most shells have a built-in command by the same name, using the
1124 unadorned command name in a script or interactively may get you
1125 different functionality than that described here.
1127 The only options are a lone @samp{--help} or
1128 @samp{--version}. @xref{Common options}.
1131 @node stty invocation
1132 @section @code{stty}: Print or change terminal characteristics
1135 @cindex change or print terminal settings
1136 @cindex terminal settings
1137 @cindex line settings of terminal
1139 @code{stty} prints or changes terminal characteristics, such as baud rate.
1143 stty [@var{setting}]@dots{}
1147 If given no arguments, @code{stty} prints the baud rate, line
1148 discipline number (on systems that support it), and line settings
1149 that have been changed from the values set by @samp{stty sane}.
1150 Mode reading and setting are performed on the tty line connected to
1153 @code{stty} accepts many non-option arguments that change aspects of
1154 the terminal line operation, as described below.
1156 The program accepts the following options. Also see @ref{Common options}.
1163 Print all current settings in human-readable form.
1169 @cindex machine-readable @code{stty} output
1170 Print all current settings in a form that can be used as an argument to
1171 another @code{stty} command to restore the current settings.
1175 Many settings can be turned off by preceding them with a @samp{-}.
1176 Such arguments are marked below with ``May be negated'' in their
1177 description. The descriptions themselves refer to the positive
1178 case, that is, when @emph{not} negated (unless stated otherwise,
1181 Some settings are not available on all POSIX systems, since they use
1182 extensions. Such arguments are marked below with ``Non-POSIX'' in their
1183 description. On non-POSIX systems, those or other settings also may not
1184 be available, but it's not feasible to document all the variations: just
1188 * Control:: Control settings
1189 * Input:: Input settings
1190 * Output:: Output settings
1191 * Local:: Local settings
1192 * Combination:: Combination settings
1193 * Characters:: Special characters
1194 * Special:: Special settings
1199 @subsection Control settings
1201 @cindex control settings
1207 @cindex two-way parity
1208 Generate parity bit in output and expect parity bit in input.
1215 Set odd parity (even if negated). May be negated.
1222 @cindex character size
1223 @cindex eight-bit characters
1224 Set character size to 5, 6, 7, or 8 bits.
1229 Send a hangup signal when the last process closes the tty. May be
1235 Use two stop bits per character (one if negated). May be negated.
1239 Allow input to be received. May be negated.
1243 @cindex modem control
1244 Disable modem control signals. May be negated.
1248 @cindex hardware flow control
1249 @cindex flow control, hardware
1250 @cindex RTS/CTS flow control
1251 Enable RTS/CTS flow control. Non-POSIX. May be negated.
1256 @subsection Input settings
1258 @cindex input settings
1263 @cindex breaks, ignoring
1264 Ignore break characters. May be negated.
1268 @cindex breaks, cause interrupts
1269 Make breaks cause an interrupt signal. May be negated.
1273 @cindex parity, ignoring
1274 Ignore characters with parity errors. May be negated.
1278 @cindex parity errors, marking
1279 Mark parity errors (with a 255-0-character sequence). May be negated.
1283 Enable input parity checking. May be negated.
1287 @cindex eight-bit input
1288 Clear high (8th) bit of input characters. May be negated.
1292 @cindex newline, translating to return
1293 Translate newline to carriage return. May be negated.
1297 @cindex return, ignoring
1298 Ignore carriage return. May be negated.
1302 @cindex return, translating to newline
1303 Translate carriage return to newline. May be negated.
1307 @kindex C-s/C-q flow control
1308 @cindex XON/XOFF flow control
1309 Enable XON/XOFF flow control (that is, @kbd{CTRL-S}/@kbd{CTRL-Q}). May
1316 @cindex software flow control
1317 @cindex flow control, software
1318 Enable sending of @code{stop} character when the system input buffer
1319 is almost full, and @code{start} character when it becomes almost
1320 empty again. May be negated.
1324 @cindex uppercase, translating to lowercase
1325 Translate uppercase characters to lowercase. Non-POSIX. May be
1330 Allow any character to restart output (only the start character
1331 if negated). Non-POSIX. May be negated.
1335 @cindex beeping at input buffer full
1336 Enable beeping and not flushing input buffer if a character arrives
1337 when the input buffer is full. Non-POSIX. May be negated.
1342 @subsection Output settings
1344 @cindex output settings
1345 These arguments specify output-related operations.
1350 Postprocess output. May be negated.
1354 @cindex lowercase, translating to output
1355 Translate lowercase characters to uppercase. Non-POSIX. May be
1360 @cindex return, translating to newline
1361 Translate carriage return to newline. Non-POSIX. May be negated.
1365 @cindex newline, translating to crlf
1366 Translate newline to carriage return-newline. Non-POSIX. May be
1371 Do not print carriage returns in the first column. Non-POSIX.
1376 Newline performs a carriage return. Non-POSIX. May be negated.
1380 @cindex pad instead of timing for delaying
1381 Use fill (padding) characters instead of timing for delays. Non-POSIX.
1386 @cindex pad character
1387 Use delete characters for fill instead of null characters. Non-POSIX.
1393 Newline delay style. Non-POSIX.
1400 Carriage return delay style. Non-POSIX.
1407 Horizontal tab delay style. Non-POSIX.
1412 Backspace delay style. Non-POSIX.
1417 Vertical tab delay style. Non-POSIX.
1422 Form feed delay style. Non-POSIX.
1427 @subsection Local settings
1429 @cindex local settings
1434 Enable @code{interrupt}, @code{quit}, and @code{suspend} special
1435 characters. May be negated.
1439 Enable @code{erase}, @code{kill}, @code{werase}, and @code{rprnt}
1440 special characters. May be negated.
1444 Enable non-POSIX special characters. May be negated.
1448 Echo input characters. May be negated.
1454 Echo @code{erase} characters as backspace-space-backspace. May be
1459 @cindex newline echoing after @code{kill}
1460 Echo a newline after a @code{kill} character. May be negated.
1464 @cindex newline, echoing
1465 Echo newline even if not echoing other characters. May be negated.
1469 @cindex flushing, disabling
1470 Disable flushing after @code{interrupt} and @code{quit} special
1471 characters. May be negated.
1475 @cindex case translation
1476 Enable input and output of uppercase characters by preceding their
1477 lowercase equivalents with @samp{\}, when @code{icanon} is set.
1478 Non-POSIX. May be negated.
1482 @cindex background jobs, stopping at terminal write
1483 Stop background jobs that try to write to the terminal. Non-POSIX.
1490 Echo erased characters backward, between @samp{\} and @samp{/}.
1491 Non-POSIX. May be negated.
1497 @cindex control characters, using @samp{^@var{c}}
1498 @cindex hat notation for control characters
1499 Echo control characters in hat notation (@samp{^@var{c}}) instead
1500 of literally. Non-POSIX. May be negated.
1506 Echo the @code{kill} special character by erasing each character on
1507 the line as indicated by the @code{echoprt} and @code{echoe} settings,
1508 instead of by the @code{echoctl} and @code{echok} settings. Non-POSIX.
1514 @subsection Combination settings
1516 @cindex combination settings
1517 Combination settings:
1524 Same as @code{parenb -parodd cs7}. May be negated. If negated, same
1525 as @code{-parenb cs8}.
1529 Same as @code{parenb parodd cs7}. May be negated. If negated, same
1530 as @code{-parenb cs8}.
1534 Same as @code{-icrnl -onlcr}. May be negated. If negated, same as
1535 @code{icrnl -inlcr -igncr onlcr -ocrnl -onlret}.
1539 Reset the @code{erase} and @code{kill} special characters to their default
1545 @c This is too long to write inline.
1547 cread -ignbrk brkint -inlcr -igncr icrnl -ixoff -iuclc -ixany
1548 imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel
1549 nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl
1550 -noflsh -xcase -tostop -echoprt echoctl echoke
1552 @noindent and also sets all special characters to their default values.
1556 Same as @code{brkint ignpar istrip icrnl ixon opost isig icanon}, plus
1557 sets the @code{eof} and @code{eol} characters to their default values
1558 if they are the same as the @code{min} and @code{time} characters.
1559 May be negated. If negated, same as @code{raw}.
1565 -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr
1566 -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -isig -icanon
1569 @noindent May be negated. If negated, same as @code{cooked}.
1573 Same as @code{-icanon}. May be negated. If negated, same as
1578 @cindex eight-bit characters
1579 Same as @code{-parenb -istrip cs8}. May be negated. If negated,
1580 same as @code{parenb istrip cs7}.
1584 Same as @code{-parenb -istrip -opost cs8}. May be negated.
1585 If negated, same as @code{parenb istrip opost cs7}.
1589 Same as @code{-ixany}. Non-POSIX. May be negated.
1593 Same as @code{tab0}. Non-POSIX. May be negated. If negated, same
1600 Same as @code{xcase iuclc olcuc}. Non-POSIX. May be negated.
1604 Same as @code{echoe echoctl echoke}.
1608 Same as @code{echoe echoctl echoke -ixany intr ^C erase ^? kill C-u}.
1613 @subsection Special characters
1615 @cindex special characters
1616 @cindex characters, special
1618 The special characters' default values vary from system to system.
1619 They are set with the syntax @samp{name value}, where the names are
1620 listed below and the value can be given either literally, in hat
1621 notation (@samp{^@var{c}}), or as an integer which may start with
1622 @samp{0x} to indicate hexadecimal, @samp{0} to indicate octal, or
1623 any other digit to indicate decimal.
1625 @cindex disabling special characters
1626 @kindex u@r{, and disabling special characters}
1627 For GNU stty, giving a value of @code{^-} or @code{undef} disables that
1628 special character. (This is incompatible with Ultrix @code{stty},
1629 which uses a value of @samp{u} to disable a special character. GNU
1630 @code{stty} treats a value @samp{u} like any other, namely to set that
1631 special character to @key{U}.)
1637 Send an interrupt signal.
1645 Erase the last character typed.
1649 Erase the current line.
1653 Send an end of file (terminate the input).
1661 Alternate character to end the line. Non-POSIX.
1665 Switch to a different shell layer. Non-POSIX.
1669 Restart the output after stopping it.
1677 Send a terminal stop signal.
1681 Send a terminal stop signal after flushing the input. Non-POSIX.
1685 Redraw the current line. Non-POSIX.
1689 Erase the last word typed. Non-POSIX.
1693 Enter the next character typed literally, even if it is a special
1694 character. Non-POSIX.
1699 @subsection Special settings
1701 @cindex special settings
1706 Set the minimum number of characters that will satisfy a read until
1707 the time value has expired, when @code{-icanon} is set.
1711 Set the number of tenths of a second before reads time out if the min
1712 number of characters have not been read, when @code{-icanon} is set.
1714 @item ispeed @var{n}
1716 Set the input speed to @var{n}.
1718 @item ospeed @var{n}
1720 Set the output speed to @var{n}.
1724 Tell the tty kernel driver that the terminal has @var{n} rows. Non-POSIX.
1727 @itemx columns @var{n}
1730 Tell the kernel that the terminal has @var{n} columns. Non-POSIX.
1736 Print the number of rows and columns that the kernel thinks the
1737 terminal has. (Systems that don't support rows and cols in the kernel
1738 typically use the environment variables @code{LINES} and @code{COLUMNS}
1739 instead; however, GNU @code{stty} does not know anything about them.)
1744 Use line discipline @var{n}. Non-POSIX.
1748 Print the terminal speed.
1751 @cindex baud rate, setting
1752 Set the input and output speeds to @var{n}. @var{n} can be one
1753 of: 0 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600
1754 19200 38400 @code{exta} @code{extb}. @code{exta} is the same as
1755 19200; @code{extb} is the same as 38400. 0 hangs up the line if
1756 @code{-clocal} is set.
1760 @node printenv invocation
1761 @section @code{printenv}: Print all or some environment variables
1764 @cindex printing all or some environment variables
1765 @cindex environment variables, printing
1767 @code{printenv} prints environment variable values. Synopsis:
1770 printenv [@var{option}] [@var{variable}]@dots{}
1773 If no @var{variable}s are specified, @code{printenv} prints the value of
1774 every environment variable. Otherwise, it prints the value of each
1775 @var{variable} that is set, and nothing for those that are not set.
1777 The only options are a lone @samp{--help} or @samp{--version}.
1778 @xref{Common options}.
1780 @cindex exit status of @code{printenv}
1784 0 if all variables specified were found
1785 1 if at least one specified variable was not found
1786 2 if a write error occurred
1790 @node tty invocation
1791 @section @code{tty}: Print file name of terminal on standard input
1794 @cindex print terminal file name
1795 @cindex terminal file name, printing
1797 @code{tty} prints the file name of the terminal connected to its standard
1798 input. It prints @samp{not a tty} if standard input is not a terminal.
1802 tty [@var{option}]@dots{}
1805 The program accepts the following option. Also see @ref{Common options}.
1815 Print nothing; only return an exit status.
1819 @cindex exit status of @code{tty}
1823 0 if standard input is a terminal
1824 1 if standard input is not a terminal
1825 2 if given incorrect arguments
1826 3 if a write error occurs
1830 @node User information
1831 @chapter User information
1833 @cindex user information, commands for
1834 @cindex commands for printing user information
1836 This section describes commands that print user-related information:
1837 logins, groups, and so forth.
1840 * id invocation:: Print real and effective uid and gid.
1841 * logname invocation:: Print current login name.
1842 * whoami invocation:: Print effective user id.
1843 * groups invocation:: Print group names a user is in.
1844 * users invocation:: Print login names of users currently logged in.
1845 * who invocation:: Print who is currently logged in.
1850 @section @code{id}: Print real and effective uid and gid
1853 @cindex real uid and gid, printing
1854 @cindex effective uid and gid, printing
1855 @cindex printing real and effective uid and gid
1857 @code{id} prints information about the given user, or the process
1858 running it if no user is specified. Synopsis:
1861 id [@var{option}]@dots{} [@var{username}]
1864 By default, it prints the real user id, real group id, effective user id
1865 if different from the real user id, effective group id if different from
1866 the real group id, and supplemental group ids.
1868 Each of these numeric values is preceded by an identifying string and
1869 followed by the corresponding user or group name in parentheses.
1871 The options cause @code{id} to print only part of the above information.
1872 Also see @ref{Common options}.
1879 Print only the group id.
1885 Print only the supplementary groups.
1891 Print the user or group name instead of the ID number. Requires
1892 @code{-u}, @code{-g}, or @code{-G}.
1898 Print the real, instead of effective, user or group id. Requires
1899 @code{-u}, @code{-g}, or @code{-G}.
1905 Print only the user id.
1910 @node logname invocation
1911 @section @code{logname}: Print current login name
1914 @cindex printing user's login name
1915 @cindex login name, printing
1916 @cindex user name, printing
1921 @code{logname} prints the calling user's name, as found in the file
1922 @file{/etc/utmp}, and exits with a status of 0. If there is no
1923 @file{/etc/utmp} entry for the calling process, @code{logname} prints
1924 an error message and exits with a status of 1.
1926 The only options are @samp{--help} and @samp{--version}. @xref{Common
1930 @node whoami invocation
1931 @section @code{whoami}: Print effective user id
1934 @cindex effective UID, printing
1935 @cindex printing the effective UID
1937 @code{whoami} prints the user name associated with the current
1938 effective user id. It is equivalent to the command @samp{id -un}.
1940 The only options are @samp{--help} and @samp{--version}. @xref{Common
1944 @node groups invocation
1945 @section @code{groups}: Print group names a user is in
1948 @cindex printing groups a user is in
1949 @cindex supplementary groups, printing
1951 @code{groups} prints the names of the primary and any supplementary
1952 groups for each given @var{username}, or the current process if no names
1953 are given. If names are given, the name of each user is printed before
1954 the list of that user's groups. Synopsis:
1957 groups [@var{username}]@dots{}
1960 The group lists are equivalent to the output of the command @samp{id -Gn}.
1962 The only options are @samp{--help} and @samp{--version}. @xref{Common
1966 @node users invocation
1967 @section @code{users}: Print login names of users currently logged in
1970 @cindex printing current usernames
1971 @cindex usernames, printing current
1973 @cindex login sessions, printing users with
1974 @code{users} prints on a single line a blank-separated list of user
1975 names of users currently logged in to the current host. Each user name
1976 corresponds to a login session, so if a user has more than one login
1977 session, that user's name will appear the same number of times in the
1986 With no @var{file} argument, @code{users} extracts its information from
1987 the file @file{/etc/utmp}. If a file argument is given, @code{users}
1988 uses that file instead. A common choice is @file{/etc/wtmp}.
1990 The only options are @samp{--help} and @samp{--version}. @xref{Common
1994 @node who invocation
1995 @section @code{who}: Print who is currently logged in
1998 @cindex printing current user information
1999 @cindex information, about current users
2001 @code{who} prints information about users who are currently logged on.
2005 @code{who} [@var{option}] [@var{file}] [am i]
2008 @cindex terminal lines, currently used
2010 @cindex remote hostname
2011 If given no non-option arguments, @code{who} prints the following
2012 information for each user currently logged on: login name, terminal
2013 line, login time, and remote hostname or X display.
2017 If given one non-option argument, @code{who} uses that instead of
2018 @file{/etc/utmp} as the name of the file containing the record of
2019 users logged on. @file{/etc/wtmp} is commonly given as an argument
2020 to @code{who} to look at who has previously logged on.
2024 If given two non-option arguments, @code{who} prints only the entry
2025 for the user running it (determined from its standard input), preceded
2026 by the hostname. Traditionally, the two arguments given are @samp{am
2027 i}, as in @samp{who am i}.
2029 The program accepts the following options. Also see @ref{Common options}.
2034 Same as @samp{who am i}.
2040 Print only the login names and the number of users logged on.
2041 Overrides all other options.
2045 Ignored; for compatibility with other versions of @code{who}.
2054 After the login time, print the number of hours and minutes that the
2055 user has been idle. @samp{.} means the user was active in last minute.
2056 @samp{old} means the user was idle for more than 24 hours.
2062 Attempt to canonicalize hostnames found in utmp through a DNS lookup. This
2063 is not the default because it can cause significant delays on systems with
2064 automatic dial-up internet access.
2070 Print a line of column headings.
2082 @cindex message status
2083 @pindex write@r{, allowed}
2084 After each login name print a character indicating the user's message status:
2087 @samp{+} allowing @code{write} messages
2088 @samp{-} disallowing @code{write} messages
2089 @samp{?} cannot find terminal device
2095 @node System context
2096 @chapter System context
2098 @cindex system context
2099 @cindex context, system
2100 @cindex commands for system context
2102 This section describes commands that print or change system-wide
2106 * date invocation:: Print or set system date and time.
2107 * uname invocation:: Print system information.
2108 * hostname invocation:: Print or set system name.
2112 @node date invocation
2113 @section @code{date}: Print or set system date and time
2116 @cindex time, printing or setting
2117 @cindex printing the current time
2119 @code{date} with no arguments prints the current time and date, in the
2120 format of the @samp{%c} directive (described below). Synopses:
2123 date [@var{option}]@dots{} [+@var{format}]
2124 date [-u|--utc|--universal] @c this avoids a newline in the output
2125 [ @var{MMDDhhmm}[[@var{CC}]@var{YY}][.@var{ss}] ]
2128 @findex strftime @r{and @code{date}}
2129 @cindex time formats
2130 @cindex formatting times
2131 If given an argument that starts with a @samp{+}, @code{date} prints the
2132 current time and date (or the time and date specified by the
2133 @code{--date} option, see below) in the format defined by that argument,
2134 which is the same as in the @code{strftime} function. Except for
2135 directives, which start with @samp{%}, characters in the format string
2136 are printed unchanged. The directives are described below.
2139 * Time directives:: %[HIklMprsSTXzZ]
2140 * Date directives:: %[aAbBcdDhjmUwWxyY]
2141 * Literal directives:: %[%nt]
2142 * Padding:: Pad with zeroes, spaces (%_), or nothing (%-).
2143 * Setting the time:: Changing the system clock.
2144 * Options for date:: Instead of the current time.
2145 * Examples of date:: Examples.
2148 @node Time directives
2149 @subsection Time directives
2151 @cindex time directives
2152 @cindex directives, time
2154 @code{date} directives related to times.
2166 minute (00@dots{}59)
2170 time, 12-hour (hh:mm:ss [AP]M)
2172 @cindex epoch, seconds since
2173 @cindex seconds since the epoch
2174 @cindex beginning of time
2175 seconds since the epoch, i.e., 1 January 1970 00:00:00 UTC (a
2177 Note that this value is the number of seconds between the epoch
2178 and the current date as defined by the localtime system call.
2179 It isn't changed by the @samp{--date} option.
2181 second (00@dots{}61)
2183 time, 24-hour (hh:mm:ss)
2185 locale's time representation (%H:%M:%S)
2187 RFC-822 style numeric time zone (e.g., -0600 or +0100), or nothing if no
2188 time zone is determinable. This value reflects the @emph{current} time
2189 zone. It isn't changed by the @samp{--date} option.
2191 time zone (e.g., EDT), or nothing if no timezone is
2193 Note that this value reflects the @emph{current} time zone.
2194 It isn't changed by the @samp{--date} option.
2198 @node Date directives
2199 @subsection Date directives
2201 @cindex date directives
2202 @cindex directives, date
2204 @code{date} directives related to dates.
2208 locale's abbreviated weekday name (Sun@dots{}Sat)
2210 locale's full weekday name, variable length (Sunday@dots{}Saturday)
2212 locale's abbreviated month name (Jan@dots{}Dec)
2214 locale's full month name, variable length (January@dots{}December)
2216 locale's date and time (Sat Nov 04 12:02:33 EST 1989)
2218 day of month (01@dots{}31)
2224 day of year (001@dots{}366)
2228 week number of year with Sunday as first day of week (00@dots{}53).
2229 Days in a new year preceding the first Sunday are in week zero.
2231 week number of year with Monday as first day of the week as a decimal
2232 (01@dots{}53). If the week containing January 1 has four or more days in
2233 the new year, then it is considered week 1; otherwise, it is week 53 of
2234 the previous year, and the next week is week 1. (See the ISO 8601: 1988
2237 day of week (0@dots{}6) with 0 corresponding to Sunday
2239 week number of year with Monday as first day of week (00@dots{}53).
2240 Days in a new year preceding the first Monday are in week zero.
2242 locale's date representation (mm/dd/yy)
2244 last two digits of year (00@dots{}99)
2250 @node Literal directives
2251 @subsection Literal directives
2253 @cindex literal directives
2254 @cindex directives, literal
2256 @code{date} directives that produce literal strings.
2271 @cindex numeric field padding
2272 @cindex padding of numeric fields
2273 @cindex fields, padding numeric
2275 By default, @code{date} pads numeric fields with zeroes, so that, for
2276 example, numeric months are always output as two digits. GNU @code{date}
2277 recognizes the following numeric modifiers between the @samp{%} and the
2282 (hyphen) do not pad the field; useful if the output is intended for
2285 (underscore) pad the field with spaces; useful if you need a fixed
2286 number of characters in the output, but zeroes are too distracting.
2290 These are GNU extensions.
2292 Here is an example illustrating the differences:
2295 date +%d/%m -d "Feb 1"
2297 date +%-d/%-m -d "Feb 1"
2299 date +%_d/%_m -d "Feb 1"
2304 @node Setting the time
2305 @subsection Setting the time
2307 @cindex setting the time
2308 @cindex time setting
2309 @cindex appropriate privileges
2311 If given an argument that does not start with @samp{+}, @code{date} sets
2312 the system clock to the time and date specified by that argument (as
2313 described below). You must have appropriate privileges to set the
2314 system clock. The @samp{--date} and @samp{--set} options may not be
2315 used with such an argument. The @samp{--universal} option may be used
2316 with such an argument to indicate that the specified time and date are
2317 relative to Coordinated Universal Time rather than to the local time
2320 The argument must consist entirely of digits, which have the following
2333 first two digits of year (optional)
2335 last two digits of year (optional)
2340 The @samp{--set} option also sets the system clock; see the next section.
2343 @node Options for date
2344 @subsection Options for @code{date}
2346 @cindex @code{date} options
2347 @cindex options for @code{date}
2349 The program accepts the following options. Also see @ref{Common options}.
2353 @item -d @var{datestr}
2354 @itemx --date=@var{datestr}
2357 @cindex parsing date strings
2358 @cindex date strings, parsing
2359 @cindex arbitrary date strings, parsing
2362 @opindex next @var{day}
2363 @opindex last @var{day}
2364 Display the time and date specified in @var{datestr} instead of the
2365 current time and date. @var{datestr} can be in almost any common
2366 format. It can contain month names, timezones, @samp{am} and @samp{pm},
2367 @samp{yesterday}, @samp{ago}, @samp{next}, etc. @xref{Date input formats}.
2369 @item -f @var{datefile}
2370 @itemx --file=@var{datefile}
2373 Parse each line in @var{datefile} as with @samp{-d} and display the
2374 resulting time and date. If @var{datefile} is @samp{-}, use standard
2375 input. This is useful when you have many dates to process, because the
2376 system overhead of starting up the @code{date} executable many times can
2382 Display the time and date using the RFC-822-specified
2383 format, @samp{%a, %_d %b %Y %H:%M:%S %z}.
2384 If @samp{--utc} is also specified, use @samp{GMT} in place of @samp{%z}.
2387 @itemx --reference=@var{file}
2389 @opindex --reference
2390 Display the time and date reference according to the last modification
2391 time of @var{file}, instead of the current time and date.
2393 @item -s @var{datestr}
2394 @itemx --set=@var{datestr}
2397 Set the time and date to @var{datestr}, See @samp{-d} above.
2404 @opindex --universal
2405 @cindex coordinated universal time
2406 @cindex Greenwich Mean Time
2407 Print or set the time and date in Universal Coordinated Time instead of
2408 in local (wall clock) time.
2413 @node Examples of date
2414 @subsection Examples of @code{date}
2416 @cindex examples of @code{date}
2418 Here are a few examples. Also see the documentation for the @samp{-d}
2419 option in the previous section.
2424 To print the date of the day before yesterday:
2427 date --date='2 days ago'
2431 To print the date of the day three months and one day hence:
2433 date --date='3 months 1 day'
2437 To print the day of year of Christmas in the current year:
2439 date --date='25 Dec' +%j
2443 To print the current full month name and the day of the month:
2448 But this may not be what you want because for the first nine days of
2449 the month, the @samp{%d} expands to a zero-padded two-digit field,
2450 for example @samp{date -d 1may '+%B %d'} will print @samp{May 01}.
2453 To print a date without the leading zero for one-digit days
2454 of the month, you can use the (GNU extension) @code{-} modifier to suppress
2455 the padding altogether.
2457 date -d=1may '+%B %-d'
2461 To print the current date and time in the format required by many
2462 non-GNU versions of @code{date} when setting the system clock:
2468 To set the system clock forward by two minutes:
2470 date --set='+2 minutes'
2474 To print the date in the format specified by RFC-822,
2475 use @samp{date --rfc}. I just did and saw this:
2478 Mon, 25 Mar 1996 23:34:17 -0600
2482 To convert a date string to the number of seconds since the epoch
2483 (which is 1970-01-01 00:00:00 UTC), use the @samp{--date} option with
2484 the @samp{%s} format. That can be useful in sorting and/or graphing
2485 and/or comparing data by date. The following command outputs the
2486 number of the seconds since the epoch for the time one second later
2487 than the epoch, but in time zone five hours later (Cambridge, Massachusetts),
2488 thus a total of five hours and one second after the epoch:
2491 date --date='1970-01-01 00:00:01 UTC +5 hours' +%s
2495 Suppose you had @emph{not} specified time zone information in the example above.
2496 Then, date would have used your computer's idea of the time zone when
2497 interpreting the string. Here's what you would get if you were in
2501 # local time zone used
2502 date --date='1970-01-01 00:00:01' +%s
2507 If you're sorting or graphing dated data, your raw date values may be
2508 represented as seconds since the epoch. But few people can look at
2509 the date @samp{946684800} and casually note ``Oh, that's the first second
2513 date --date='2000-01-01 UTC' +%s
2517 To convert such an unwieldy number of seconds back to
2518 a more readable form, use a command like this:
2521 date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z"
2522 2000-01-01 00:00:00 +0000
2528 @node uname invocation
2529 @section @code{uname}: Print system information
2532 @cindex print system information
2533 @cindex system information, printing
2535 @code{uname} prints information about the machine and operating system
2536 it is run on. If no options are given, @code{uname} acts as if the
2537 @code{-s} option were given. Synopsis:
2540 uname [@var{option}]@dots{}
2543 If multiple options or @code{-a} are given, the selected information is
2544 printed in this order:
2547 @var{sysname} @var{nodename} @var{release} @var{osversion} @var{machine}
2550 The @var{osversion}, at least, may well be multiple words. For example:
2554 @result{} Linux hayley 1.0.4 #3 Thu May 12 18:06:34 1994 i486
2558 The program accepts the following options. Also see @ref{Common options}.
2566 Print all of the below information.
2572 @cindex machine type
2573 @cindex hardware type
2574 Print the machine (hardware) type.
2582 @cindex network node name
2583 Print the machine's network node hostname.
2588 @opindex --processor
2589 @cindex host processor type
2590 Print the machine's processor type
2596 @cindex operating system release
2597 @cindex release of operating system
2598 Print the operating system release.
2604 @cindex operating system name
2605 @cindex name of operating system
2606 Print the operating system name.
2610 @cindex operating system version
2611 @cindex version of operating system
2612 Print the operating system version.
2617 @node hostname invocation
2618 @section @code{hostname}: Print or set system name
2621 @cindex setting the hostname
2622 @cindex printing the hostname
2623 @cindex system name, printing
2624 @cindex appropriate privileges
2626 With no arguments, @code{hostname} prints the name of the current host
2627 system. With one argument, it sets the current host name to the
2628 specified string. You must have appropriate privileges to set the host
2632 hostname [@var{name}]
2635 The only options are @samp{--help} and @samp{--version}. @xref{Common
2639 @node Modified command invocation
2640 @chapter Modified command invocation
2642 @cindex modified command invocation
2643 @cindex invocation of commands, modified
2644 @cindex commands for invoking other commands
2646 This section describes commands that run other commands in some context
2647 different than the current one: a modified environment, as a different
2651 * chroot invocation:: Modify the root directory.
2652 * env invocation:: Modify environment variables.
2653 * nice invocation:: Modify scheduling priority.
2654 * nohup invocation:: Immunize to hangups.
2655 * su invocation:: Modify user and group id.
2659 @node chroot invocation
2660 @section @code{chroot}: Run a command with a different root directory
2663 @cindex running a program in a specified root directory
2664 @cindex root directory, running a program in a specified
2666 @code{chroot} runs a command with a specified root directory.
2667 On many systems, only the super-user can do this.
2671 chroot @var{newroot} [@var{command} [@var{args}]@dots{}]
2675 Ordinarily, filenames are looked up starting at the root of the
2676 directory structure, i.e., @file{/}. @code{chroot} changes the root to
2677 the directory @var{newroot} (which must exist) and then runs
2678 @var{command} with optional @var{args}. If @var{command} is not
2679 specified, the default is the value of the @code{SHELL} environment
2680 variable or @code{/bin/sh} if not set, invoked with the @samp{-i} option.
2682 The only options are @samp{--help} and @samp{--version}. @xref{Common
2686 @node env invocation
2687 @section @code{env}: Run a command in a modified environment
2690 @cindex environment, running a program in a modified
2691 @cindex modified environment, running a program in a
2692 @cindex running a program in a modified environment
2694 @code{env} runs a command with a modified environment. Synopses:
2697 env [@var{option}]@dots{} [@var{name}=@var{value}]@dots{} @c
2698 [@var{command} [@var{args}]@dots{}]
2702 Arguments of the form @samp{@var{variable}=@var{value}} set
2703 the environment variable @var{variable} to value @var{value}.
2704 @var{value} may be empty (@samp{@var{variable}=}). Setting a variable
2705 to an empty value is different from unsetting it.
2708 The first remaining argument specifies the program name to invoke; it is
2709 searched for according to the @code{PATH} environment variable. Any
2710 remaining arguments are passed as arguments to that program.
2712 @cindex environment, printing
2714 If no command name is specified following the environment
2715 specifications, the resulting environment is printed. This is like
2716 specifying a command name of @code{printenv}.
2718 The program accepts the following options. Also see @ref{Common options}.
2723 @itemx --unset=@var{name}
2726 Remove variable @var{name} from the environment, if it was in the
2731 @itemx --ignore-environment
2734 @opindex --ignore-environment
2735 Start with an empty environment, ignoring the inherited environment.
2740 @node nice invocation
2741 @section @code{nice}: Run a command with modified scheduling priority
2744 @cindex modifying scheduling priority
2745 @cindex scheduling priority, modifying
2746 @cindex priority, modifying
2747 @cindex appropriate privileges
2749 @code{nice} prints or modifies the scheduling priority of a job.
2753 nice [@var{option}]@dots{} [@var{command} [@var{arg}]@dots{}]
2756 If no arguments are given, @code{nice} prints the current scheduling
2757 priority, which it inherited. Otherwise, @code{nice} runs the given
2758 @var{command} with its scheduling priority adjusted. If no
2759 @var{adjustment} is given, the priority of the command is incremented by
2760 10. You must have appropriate privileges to specify a negative
2761 adjustment. The priority can be adjusted by @code{nice} over the range
2762 of -20 (the highest priority) to 19 (the lowest).
2764 @cindex conflicts with shell built-ins
2765 @cindex built-in shell commands, conflicts with
2766 Because most shells have a built-in command by the same name, using the
2767 unadorned command name in a script or interactively may get you
2768 different functionality than that described here.
2770 The program accepts the following option. Also see @ref{Common options}.
2773 @item -n @var{adjustment}
2774 @itemx -@var{adjustment}
2775 @itemx --adjustment=@var{adjustment}
2777 @opindex --adjustment
2778 @opindex -@var{adjustment}
2779 Add @var{adjustment} instead of 10 to the command's priority.
2783 @node nohup invocation
2784 @section @code{nohup}: Run a command immune to hangups
2787 @cindex hangups, immunity to
2788 @cindex immunity to hangups
2789 @cindex logging out and continuing to run
2792 @code{nohup} runs the given @var{command} with hangup signals ignored,
2793 so that the command can continue running in the background after you log
2797 nohup @var{command} [@var{arg}]@dots{}
2801 @code{nohup} increases the scheduling priority of @var{command} by 5, so
2802 it has a slightly smaller change to run. If standard output is a terminal,
2803 it and standard error are redirected so that they are appended to the
2804 file @file{nohup.out}; if that cannot be written to, they are appended
2805 to the file @file{$HOME/nohup.out}. If that cannot be written to, the
2808 If @code{nohup} creates either @file{nohup.out} or
2809 @file{$HOME/nohup.out}, it creates it with no ``group'' or ``other''
2810 access permissions. It does not change the permissions if the output
2811 file already existed.
2813 @code{nohup} does not automatically put the command it runs in the
2814 background; you must do that explicitly, by ending the command line
2817 The only options are @samp{--help} and @samp{--version}. @xref{Common
2822 @section @code{su}: Run a command with substitute user and group id
2825 @cindex substitute user and group ids
2826 @cindex user id, switching
2827 @cindex super-user, becoming
2828 @cindex root, becoming
2830 @code{su} allows one user to temporarily become another user. It runs a
2831 command (often an interactive shell) with the real and effective user
2832 id, group id, and supplemental groups of a given @var{user}. Synopsis:
2835 su [@var{option}]@dots{} [@var{user} [@var{arg}]@dots{}]
2838 @cindex passwd entry, and @code{su} shell
2840 @flindex /etc/passwd
2841 If no @var{user} is given, the default is @code{root}, the super-user.
2842 The shell to use is taken from @var{user}'s @code{passwd} entry, or
2843 @file{/bin/sh} if none is specified there. If @var{user} has a
2844 password, @code{su} prompts for the password unless run by a user with
2845 effective user id of zero (the super-user).
2852 By default, @code{su} does not change the current directory.
2853 It sets the environment variables @code{HOME} and @code{SHELL}
2854 from the password entry for @var{user}, and if @var{user} is not
2855 the super-user, sets @code{USER} and @code{LOGNAME} to @var{user}.
2856 By default, the shell is not a login shell.
2858 Any additional @var{arg}s are passed as additional arguments to the
2862 GNU @code{su} does not treat @file{/bin/sh} or any other shells specially
2863 (e.g., by setting @code{argv[0]} to @samp{-su}, passing @code{-c} only
2864 to certain shells, etc.).
2867 @code{su} can optionally be compiled to use @code{syslog} to report
2868 failed, and optionally successful, @code{su} attempts. (If the system
2869 supports @code{syslog}.) However, GNU @code{su} does not check if the
2870 user is a member of the @code{wheel} group; see below.
2872 The program accepts the following options. Also see @ref{Common options}.
2875 @item -c @var{command}
2876 @itemx --command=@var{command}
2879 Pass @var{command}, a single command line to run, to the shell with
2880 a @code{-c} option instead of starting an interactive shell.
2887 @cindex file name pattern expansion, disabled
2888 @cindex globbing, disabled
2889 Pass the @code{-f} option to the shell. This probably only makes sense
2890 if the shell run is @code{csh} or @code{tcsh}, for which the @code{-f}
2891 option prevents reading the startup file (@file{.cshrc}). With
2892 Bourne-like shells, the @code{-f} option disables file name pattern
2893 expansion (globbing), which is not likely to be useful.
2901 @c other variables already indexed above
2904 @cindex login shell, creating
2905 Make the shell a login shell. This means the following. Unset all
2906 environment variables except @code{TERM}, @code{HOME}, and @code{SHELL}
2907 (which are set as described above), and @code{USER} and @code{LOGNAME}
2908 (which are set, even for the super-user, as described above), and set
2909 @code{PATH} to a compiled-in default value. Change to @var{user}'s home
2910 directory. Prepend @samp{-} to the shell's name, intended to make it
2911 read its login startup file(s).
2915 @itemx --preserve-environment
2918 @opindex --preserve-environment
2919 @cindex environment, preserving
2920 @flindex /etc/shells
2921 @cindex restricted shell
2922 Do not change the environment variables @code{HOME}, @code{USER},
2923 @code{LOGNAME}, or @code{SHELL}. Run the shell given in the environment
2924 variable @code{SHELL} instead of the shell from @var{user}'s passwd
2925 entry, unless the user running @code{su} is not the superuser and
2926 @var{user}'s shell is restricted. A @dfn{restricted shell} is one that
2927 is not listed in the file @file{/etc/shells}, or in a compiled-in list
2928 if that file does not exist. Parts of what this option does can be
2929 overridden by @code{--login} and @code{--shell}.
2931 @item -s @var{shell}
2932 @itemx --shell=@var{shell}
2935 Run @var{shell} instead of the shell from @var{user}'s passwd entry,
2936 unless the user running @code{su} is not the superuser and @var{user}'s
2937 shell is restricted (see @samp{-m} just above).
2941 @cindex wheel group, not supported
2942 @cindex group wheel, not supported
2944 @heading Why GNU @code{su} does not support the @samp{wheel} group
2946 (This section is by Richard Stallman.)
2950 Sometimes a few of the users try to hold total power over all the
2951 rest. For example, in 1984, a few users at the MIT AI lab decided to
2952 seize power by changing the operator password on the Twenex system and
2953 keeping it secret from everyone else. (I was able to thwart this coup
2954 and give power back to the users by patching the kernel, but I
2955 wouldn't know how to do that in Unix.)
2957 However, occasionally the rulers do tell someone. Under the usual
2958 @code{su} mechanism, once someone learns the root password who
2959 sympathizes with the ordinary users, he or she can tell the rest. The
2960 ``wheel group'' feature would make this impossible, and thus cement the
2961 power of the rulers.
2963 I'm on the side of the masses, not that of the rulers. If you are
2964 used to supporting the bosses and sysadmins in whatever they do, you
2965 might find this idea strange at first.
2971 @cindex delaying commands
2972 @cindex commands for delaying
2974 @c Perhaps @code{wait} or other commands should be described here also?
2977 * sleep invocation:: Delay for a specified time.
2981 @node sleep invocation
2982 @section @code{sleep}: Delay for a specified time
2985 @cindex delay for a specified time
2987 @code{sleep} pauses for an amount of time specified by the sum of
2988 the values of the command line arguments.
2992 sleep [@var{number}[smhd]]@dots{}
2996 Each argument is a number followed by an optional unit; the default
2997 is seconds. The units are:
3010 The only options are @samp{--help} and @samp{--version}. @xref{Common
3014 @node Numeric operations
3015 @chapter Numeric operations
3017 @cindex numeric operations
3018 These programs do numerically-related operations.
3021 * factor invocation:: Show factors of numbers.
3022 * seq invocation:: Print sequences of numbers.
3026 @node factor invocation
3027 @section @code{factor}: Print prime factors
3030 @cindex prime factors
3032 @code{factor} prints prime factors. Synopses:
3035 factor [@var{number}]@dots{}
3039 If no @var{number} is specified on the command line, @code{factor} reads
3040 numbers from standard input, delimited by newlines, tabs, or spaces.
3042 The only options are @samp{--help} and @samp{--version}. @xref{Common
3046 @node seq invocation
3047 @section @code{seq}: Print numeric sequences
3050 @cindex numeric sequences
3051 @cindex sequence of numbers
3053 @code{seq} prints a sequence of numbers to standard output. Synopses:
3056 seq [@var{option}]@dots{} [@var{first} [@var{step}]] @var{last}@dots{}
3059 @code{seq} prints the numbers from @var{first} to @var{last} by
3060 @var{step}. By default, @var{first} and @var{step} are both 1, and each
3061 number is printed on its own line. All numbers can be reals, not just
3064 The program accepts the following options. Also see @ref{Common options}.
3067 @item -f @var{format}
3068 @itemx --format=@var{format}
3069 @opindex -f @var{format}
3070 @opindex --format=@var{format}
3071 @cindex formatting of numbers in @code{seq}
3072 Print all numbers using @var{format}; default @samp{%g}.
3073 @var{format} must contain exactly one of the standarding float output
3074 formats @samp{%e}, @samp{%f}, or @samp{%g}.
3076 @item -s @var{string}
3077 @itemx --separator=@var{string}
3078 @cindex separator for numbers in @code{seq}
3079 Separate numbers with @var{string}; default is a newline.
3080 The output always terminates with a newline.
3083 @itemx --equal-width
3084 Print all numbers with the same width, by padding with leading zeroes.
3085 (To have other kinds of padding, use @samp{--format}).
3099 @c texinfo-column-for-description: 33