Copyright © 1994 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
First of all, this manual is incomplete. The stty
section, in
particular, needs substantial reorganization and additional explanatory
text before it will be up to the standard of other GNU manuals.
Explanatory text in general is lacking; the manual presently assumes you
pretty much know what to do, and just need to be reminded of how. Thus,
if you are interested, please get involved in improving this manual.
The entire GNU community will benefit.
Some of these programs are useful only when writing shell scripts; utilities like these are, in fact, the “language” of shell scripts (to a great extent). Others are occasionally useful interactively.
The GNU shell utilities are mostly compatible with the POSIX.2 standard.
Please report bugs to ‘bug-gnu-utils@prep.ai.mit.edu’. Remember to include the version number, machine architecture, input files, and any other information needed to reproduce the bug. See Bugs in GNU CC.
This manual is based on the Unix man pages in the distribution, which were originally written by David MacKenzie and updated by Jim Meyering. {No value for ‘Francois’} Pinard did the initial conversion to Texinfo format. Karl Berry did the indexing, some reorganization, and editing of the results. Richard Stallman contributed his usual invaluable insights to the overall process.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Certain options are available in all these programs. Rather than writing identical descriptions for each of the programs, they are described here. (In fact, every GNU program accepts (or should accept) these options.)
Many of these programs take arbitrary strings as arguments. In those cases, ‘--help’ and ‘--version’ are taken as these options only if there is one and exactly one command line argument.
Print a usage message listing all available options, then exit successfully.
Print the version number, then exit successfully.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes commands that display text strings.
3.1 echo : Print a line of text | Print a line of text. | |
3.2 printf : Format and print data | Format and print data. | |
3.3 yes : Print a string until interrupted | Print a string until interrupted. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
echo
: Print a line of textSynopsis:
echo [ option ]… [ string ]…
echo
writes each given string to standard output, with a
space between each and a newline after the last one.
The program accepts the following options. Also see Common options.
Do not output the trailing newline.
Enable interpretation of the following backslash-escaped characters in each string:
alert (bell)
backspace
suppress trailing newline
form feed
new line
carriage return
horizontal tab
vertical tab
backslash
the character whose ASCII code is nnn (octal); if nnn is not a valid octal number, it is printed literally.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
printf
: Format and print dataSynopsis:
printf format [ argument ]…
printf
prints the format string, interpreting ‘%’
directives and ‘\’ escapes in the same way as the C printf
function. The format argument is re-used as necessary to convert
all of the given arguments.
printf
has one additional directive, ‘%b’, which prints its
argument string with ‘\’ escapes interpreted in the same way as in
the format string.
printf
interprets ‘\0ooo’ in format as an octal number
(if ooo is 0 to 3 octal digits) specifying a character to print,
and ‘\xhhh’ as a hexadecimal number (if hhh is 1 to 3 hex
digits) specifying a character to print.
An additional escape, ‘\c’, causes printf
to produce no
further output.
The only options are a lone ‘--help’ or ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
yes
: Print a string until interruptedyes
prints the command line arguments, separated by spaces and
followed by a newline, forever until it is killed. If no arguments are
given, it prints ‘y’ followed by a newline forever until killed.
The only options are a lone ‘--help’ or ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes commands that are primarily useful for their exit
status, rather than their output. Thus, they are often used as the
condition of shell if
statements, or as the last command in a
pipeline.
4.1 false : Do nothing, unsuccessfully | Do nothing, unsuccessfully. | |
4.2 true : Do nothing, successfully | Do nothing, successfully. | |
4.3 test : Check file types and compare values | Check file types and compare values. | |
4.4 expr : Evaluate expressions | Evaluate expressions. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
false
: Do nothing, unsuccessfullyfalse
does nothing except return an exit status of 1, meaning
failure. It can be used as a place holder in shell scripts
where an unsuccessful command is needed.
Any arguments are ignored, except for a lone ‘--help’ or ‘--version’ (see section Common options).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
true
: Do nothing, successfullytrue
does nothing except return an exit status of 0, meaning
success. It can be used as a place holder in shell scripts
where a successful command is needed, although the shell built-in
command :
(colon) may be faster.
Any arguments are ignored, except for a lone ‘--help’ or ‘--version’ (see section Common options).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
test
: Check file types and compare valuestest
returns a status of 0 (true) or 1 (false) depending on the
evaluation of the conditional expression expr. Each part of the
expression must be a separate argument.
test
has file status checks, string operators, and numeric
comparison operators.
Because most shells have a built-in command by the same name, using the unadorned command name in a script or interactively may get you different functionality than that described here.
Besides the options below, test
accepts a lone ‘--help’ or
‘--version’. See section Common options. A single non-option argument
is also allowed: test
returns true if the argument is not null.
4.3.1 File type tests | -[bcdfhLpSt] | |
4.3.2 Access permission tests | -[gkruwxOG] | |
4.3.3 File characteristics tests | -e -s -nt -ot -ef | |
4.3.4 String tests | -z -n = != | |
4.3.5 Numeric tests | -eq -ne -lt -le -gt -ge | |
4.3.6 Connectives for test | ! -a -o |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options test for particular types of files. (Everything’s a file, but not all files are the same!)
True if file exists and is a block special device.
True if file exists and is a character special device.
True if file exists and is a directory.
True if file exists and is a regular file.
True if file exists and is a symbolic link.
True if file exists and is a named pipe.
True if file exists and is a socket.
True if fd is opened on a terminal. If fd is omitted, it defaults to 1 (standard output).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options test for particular access permissions.
True if file exists and has its set-group-id bit set.
True if file has its sticky bit set.
True if file exists and is readable.
True if file exists and has its set-user-id bit set.
True if file exists and is writable.
True if file exists and is executable.
True if file exists and is owned by the current effective user id.
True if file exists and is owned by the current effective group id.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options test other file characteristics.
True if file exists.
True if file exists and has a size greater than zero.
True if file1 is newer (according to modification date) than file2.
True if file1 is older (according to modification date) than file2.
True if file1 and file2 have the same device and inode numbers, i.e., if they are hard links to each other.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options test string characteristics. Strings are not quoted for
test
, though you may need to quote them to protect characters
with special meaning to the shell, e.g., spaces.
True if the length of string is zero.
True if the length of string is non-zero.
True if the strings are equal.
True if the strings are not equal.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Numeric relationals. The arguments must be entirely numeric (possibly
negative), or the special expression -l string
, which
evaluates to the length of string.
These arithmetic binary operators return true if arg1 is equal, not-equal, less-than, less-than-or-equal, greater-than, or greater-than-or-equal than arg2, respectively.
For example:
test -1 -gt -2 && echo yes ⇒ yes test -l abc -gt 1 && echo yes ⇒ yes test 0x100 -eq 1 error--> test: integer expression expected before -eq
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
test
The usual logical connectives.
True if expr is false.
True if both expr1 and expr2 are true.
True if either expr1 or expr2 is true.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
expr
: Evaluate expressionsexpr
evaluates an expression and writes the result on standard
output. Each token of the expression must be a separate argument.
Operands are either numbers or strings. expr
coerces
anything appearing in an operand position to an integer or a string
depending on the operation being applied to it.
Strings are not quoted for expr
, though you may need to quote
them to protect characters with special meaning to the shell, e.g.,
spaces.
Operators may given as infix symbols or prefix keywords. Parentheses may be used for grouping in the usual manner (you must quote parentheses to avoid the shell evaluating them, however).
Exit status:
0 if the expression is neither null nor 0, 1 if the expression is null or 0, 2 for invalid expressions.
4.4.1 Relations for expr | | & < <= = == != >= > | |
4.4.2 Numeric expressions | + - * / % | |
4.4.3 String expressions | : match substr index length | |
4.4.4 Examples of expr | Examples. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
expr
The usual logical connectives and relations, in order of precedence.
Yields its first argument if it is neither null nor 0, otherwise its second argument.
Yields its first argument if neither argument is null or 0, otherwise 0.
Compare the arguments and return 1 if the relation is true, 0 otherwise.
==
is a synonym for =
. expr
first tries to coerce
both arguments to numbers and do a numeric comparison; if either
coercion fails, it does a lexicographic comparison.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Numeric operators, in order of increasing precedence. The connectives (previous section) have higher precedence, the string operators (following section) have lower.
Addition and subtraction. Both arguments are coerced to numbers; an error occurs if this cannot be done.
Multiplication, division, remainder. Both arguments are coerced to numbers; an error occurs if this cannot be done.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
String operators. These have lowest precedence.
Perform pattern matching. The arguments are coerced to strings and the
second is considered to be a (basic, a la grep
) regular
expression, with a ^
implicitly prepended. The first argument is
then matched against this regular expression.
If the match succeeds and regex uses ‘\(’ and ‘\)’, the
:
expression returns the part of string that matched the
subexpression; otherwise, it returns the number of characters matched.
If the match fails, the :
operator returns the null string if
‘\(’ and ‘\)’ are used in regex, otherwise 0.
Only the first ‘\( … \)’ pair is relevant to the return value; additional pairs are meaningful only for grouping the regular expression operators.
See Regular Expression Library in Regex, for details of regular expression syntax.
An alternative way to do pattern matching. This is the same as ‘string : regex’.
Returns the substring of string beginning at position with length at most length. If either position or length is negative or non-numeric, returns the null string.
Returns the first position in string where the first character in charset was found. If no character in charset is found in string, return 0.
Returns the length of string.
The keywords cannot be used as strings.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
expr
Here are a few examples, including quoting for shell metacharacters.
To add 1 to the shell variable foo
, in Bourne-compatible shells:
foo=`expr $foo + 1`
To print the non-directory part of the file name stored in
$fname
, which need not contain a /
.
expr $fname : '.*/\(^.*\)' '^|' $fname
expr abc : 'a\(.\)c' ⇒ b expr index abcdef cz ⇒ 3 expr index index a error--> expr: syntax error
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Unix shells commonly provide several forms of redirection—ways to change the input source or output destination of a command. But one useful redirection is performed by a separate command, not by the shell; it’s described here.
5.1 tee : Redirect output to multiple files | Redirect output to multiple files. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tee
: Redirect output to multiple filesThe tee
command copies standard input to standard output and also
to any files given as arguments. This is useful when you want not only
to send some data down a pipe, but also to save a copy.
Synopsis:
tee [ option ]… [ file ]…
If a file being written to does not already exist, it is created. If a
file being written to already exists, the data it previously contained
is overwritten unless the -a
option is used.
The program accepts the following options. Also see Common options.
Append standard input to the given files rather than overwriting them.
Ignore interrupt signals.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes commands that manipulate file names.
6.1 basename : Strip directory and suffix from a file name | Strip directory and suffix from a file name. | |
6.2 dirname : Strip non-directory suffix from a file name | Strip non-directory suffix from a file name. | |
6.3 pathchk : Check file name portability | Check file name portability. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
basename
: Strip directory and suffix from a file nameSynopsis:
basename name [ suffix ]
The basename
command removes any leading directory components
from name. If suffix is specified and is identical
to the end of name, it is removed from name as well.
basename
prints the result on standard output.
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dirname
: Strip non-directory suffix from a file nameSynopsis:
dirname name
dirname
prints all but the final slash-delimited component
of name. If name is a single component,
dirname
prints ‘.’ (meaning the current directory).
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
pathchk
: Check file name portabilitySynopsis:
pathchk [ option ]… name…
For each name, pathchk
prints a message if any of
these conditions is true:
The program accepts the following option. Also see Common options.
Instead of performing length checks on the underlying filesystem, test the length of each file name and its components against the POSIX.1 minimum limits for portability. Also check that the file name contains no characters not in the portable file name character set.
Exit status:
0 if all specified file names passed all of the tests, 1 otherwise.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes commands that display or alter the context in which you are working: the current directory, the terminal settings, and so forth. See also the user-related commands in the next section.
7.1 pwd : Print working directory | Print working directory. | |
7.2 stty : Print or change terminal characteristics | Print or change terminal characteristics. | |
7.3 printenv : Print all or some environment variables | Print environment variables. | |
7.4 tty : Print file name of terminal on standard input | Print file name of terminal on standard input. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
pwd
: Print working directorypwd
prints the fully resolved name of the current directory.
That is, all components of the printed name will be actual directory
names—none will be symbolic links.
Because most shells have a built-in command by the same name, using the unadorned command name in a script or interactively may get you different functionality than that described here.
The only options are a lone ‘--help’ or ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
stty
: Print or change terminal characteristicsIf given no arguments, stty
prints the baud rate, line
discipline number (on systems that support it), and line settings
that have been changed from the values set by ‘stty sane’.
Mode reading and setting are performed on the tty line connected to
standard input.
stty
accepts many non-option arguments that change aspects of
the terminal line operation, as described below.
Synopses:
stty [ setting ]… stty [ option ]
The program accepts the following options. Also see Common options.
Print all current settings in human-readable form.
Print all current settings in a form that can be used as an argument to
another stty
command to restore the current settings.
Many settings can be turned off by preceding them with a ‘-’. Such arguments are marked below with “May be negated” in their description. The descriptions themselves refer to the positive case, that is, when not negated (unless stated otherwise, of course).
Some settings are not available on all POSIX systems, since they use extensions. Such arguments are marked below with “Non-POSIX” in their description. On non-POSIX systems, those or other settings also may not be available, but it’s not feasible to document all the variations: just try it and see.
7.2.1 Control settings | ||
7.2.2 Input settings | ||
7.2.3 Output settings | ||
7.2.4 Local settings | ||
7.2.5 Combination settings | ||
7.2.6 Special characters | ||
7.2.7 Special settings |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Control settings:
Generate parity bit in output and expect parity bit in input. May be negated.
Set odd parity (even if negated). May be negated.
Set character size to 5, 6, 7, or 8 bits.
Send a hangup signal when the last process closes the tty. May be negated.
Use two stop bits per character (one if negated). May be negated.
Allow input to be received. May be negated.
Disable modem control signals. May be negated.
Enable RTS/CTS flow control. Non-POSIX. May be negated.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Ignore breaks. May be negated.
Make breaks cause an interrupt signal. May be negated.
Ignore parity errors. May be negated.
Mark parity errors (with a 255-0-character sequence). May be negated.
Enable input parity checking. May be negated.
Clear high (8th) bit of input characters. May be negated.
Translate newline to carriage return. May be negated.
Ignore carriage return. May be negated.
Translate carriage return to newline. May be negated.
Enable XON/XOFF flow control (that is, <CTRL-s>/<CTRL-Q>). May be negated.
Enable sending of stop
character when the system input buffer
is almost full, and start
character when it becomes almost
empty again. May be negated.
Translate uppercase characters to lowercase. Non-POSIX. May be negated.
Allow any character to restart output (only the start character if negated). Non-POSIX. May be negated.
Enable beeping and not flushing input buffer if a character arrives when the input buffer is full. Non-POSIX. May be negated.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These arguments specify output-related operations.
Postprocess output. May be negated.
Translate lowercase characters to uppercase. Non-POSIX. May be negated.
Translate carriage return to newline. Non-POSIX. May be negated.
Translate newline to carriage return-newline. Non-POSIX. May be negated.
Do not print carriage returns in the first column. Non-POSIX. May be negated.
Newline performs a carriage return. Non-POSIX. May be negated.
Use fill (padding) characters instead of timing for delays. Non-POSIX. May be negated.
Use delete characters for fill instead of null characters. Non-POSIX. May be negated.
Newline delay style. Non-POSIX.
Carriage return delay style. Non-POSIX.
Horizontal tab delay style. Non-POSIX.
Backspace delay style. Non-POSIX.
Vertical tab delay style. Non-POSIX.
Form feed delay style. Non-POSIX.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Enable interrupt
, quit
, and suspend
special
characters. May be negated.
Enable erase
, kill
, werase
, and rprnt
special characters. May be negated.
Enable non-POSIX special characters. May be negated.
Echo input characters. May be negated.
Echo erase
characters as backspace-space-backspace. May be
negated.
Echo a newline after a kill
character. May be negated.
Echo newline even if not echoing other characters. May be negated.
Disable flushing after interrupt
and quit
special
characters. May be negated.
Enable input and output of uppercase characters by preceding their
lowercase equivalents with ‘\’, when icanon
is set.
Non-POSIX. May be negated.
Stop background jobs that try to write to the terminal. Non-POSIX. May be negated.
Echo erased characters backward, between ‘\’ and ‘/’. Non-POSIX. May be negated.
Echo control characters in hat notation (‘^c’) instead of literally. Non-POSIX. May be negated.
Echo the kill
special character by erasing each character on
the line as indicated by the echoprt
and echoe
settings,
instead of by the echoctl
and echok
settings. Non-POSIX.
May be negated.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Combination settings:
Same as parenb -parodd cs7
. May be negated. If negated, same
as -parenb cs8
.
Same as parenb parodd cs7
. May be negated. If negated, same
as -parenb cs8
.
Same as -icrnl -onlcr
. May be negated. If negated, same as
icrnl -inlcr -igncr onlcr -ocrnl -onlret
.
Reset the erase
and kill
special characters to their default
values.
Same as:
cread -ignbrk brkint -inlcr -igncr icrnl -ixoff -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
and also sets all special characters to their default values.
Same as brkint ignpar istrip icrnl ixon opost isig icanon
, plus
sets the eof
and eol
characters to their default values
if they are the same as the min
and time
characters.
May be negated. If negated, same as raw
.
Same as:
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -isig -icanon -xcase min 1 time 0
May be negated. If negated, same as cooked
.
Same as -icanon
. May be negated. If negated, same as
icanon
.
Same as -parenb -istrip cs8
. May be negated. If negated,
same as parenb istrip cs7
.
Same as -parenb -istrip -opost cs8
. May be negated.
If negated, same as parenb istrip opost cs7
.
Same as -ixany
. Non-POSIX. May be negated.
Same as tab0
. Non-POSIX. May be negated. If negated, same
as tab3
.
Same as xcase iuclc olcuc
. Non-POSIX. May be negated.
Same as echoe echoctl echoke
.
Same as echoe echoctl echoke -ixany intr ^C erase ^? kill C-u
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The special characters’ default values vary from system to system. They are set with the syntax ‘name value’, where the names are listed below and the value can be given either literally, in hat notation (‘^c’), or as an integer which may start with ‘0x’ to indicate hexadecimal, ‘0’ to indicate octal, or any other digit to indicate decimal.
For GNU stty, giving a value of ^-
or undef
disables that
special character. (This is incompatible with Ultrix stty
,
which uses a value of ‘u’ to disable a special character. GNU
stty
treats a value ‘u’ like any other, namely to set that
special character to <u>.)
Send an interrupt signal.
Send a quit signal.
Erase the last character typed.
Erase the current line.
Send an end of file (terminate the input).
End the line.
Alternate character to end the line. Non-POSIX.
Switch to a different shell layer. Non-POSIX.
Restart the output after stopping it.
Stop the output.
Send a terminal stop signal.
Send a terminal stop signal after flushing the input. Non-POSIX.
Redraw the current line. Non-POSIX.
Erase the last word typed. Non-POSIX.
Enter the next character typed literally, even if it is a special character. Non-POSIX.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Set the minimum number of characters that will satisfy a read until
the time value has expired, when -icanon
is set.
Set the number of tenths of a second before reads time out if the min
number of characters have not been read, when -icanon
is set.
Set the input speed to n.
Set the output speed to n.
Tell the tty kernel driver that the terminal has n rows. Non-POSIX.
Tell the kernel that the terminal has n columns. Non-POSIX.
Print the number of rows and columns that the kernel thinks the
terminal has. (Systems that don’t support rows and cols in the kernel
typically use the environment variables LINES
and COLUMNS
instead; however, GNU stty
does not know anything about them.)
Non-POSIX.
Use line discipline n. Non-POSIX.
Print the terminal speed.
Set the input and output speeds to n. n can be one
of: 0 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600
19200 38400 exta
extb
. exta
is the same as
19200; extb
is the same as 38400. 0 hangs up the line if
-clocal
is set.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
printenv
: Print all or some environment variablesSynopsis:
printenv [ option ] [ variable ]…
If no variables are specified, printenv
prints the value of
every environment variable. Otherwise, it prints the value of each
variable that is set, and nothing for those that are not set.
The only options are a lone ‘--help’ or ‘--version’. See section Common options.
Exit status:
0 if all variables specified were found 1 if at least one specified variable was not found 2 if a write error occurred
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
tty
: Print file name of terminal on standard inputtty
prints the file name of the tty connected to its standard
input. It prints ‘not a tty’ if standard input is not a tty.
Synopsis:
tty [ option ]…
The program accepts the following option. Also see Common options.
Print nothing; only return an exit status.
Exit status:
0 if standard input is a tty 1 if standard input is not a tty 2 if given incorrect arguments 3 if a write error occurs
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes commands that print user-related information: logins, groups, and so forth.
8.1 id : Print real and effective uid and gid | Print real and effective uid and gid. | |
8.2 logname : Print current login name | Print current login name. | |
8.3 whoami : Print effective user id | Print effective user id. | |
8.4 groups : Print group names a user is in | Print group names a user is in. | |
8.5 users : Print login names of users currently logged in | Print login names of users currently logged in. | |
8.6 who : Print who is currently logged in | Print who is currently logged in. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
id
: Print real and effective uid and gidid
prints information about the given user, or the process
running it if no user is specified.
Synopsis:
id [ option ]… [ username ]
By default, it prints the real user id, real group id, effective user id if different from the real user id, effective group id if different from the real group id, and supplemental group ids.
Each of these numeric values is preceded by an identifying string and followed by the corresponding user or group name in parentheses.
The options cause id
to print only part of the above information.
Also see Common options.
Print only the group id.
Print only the supplementary groups.
Print the user or group name instead of the ID number. Requires
-u
, -g
, or -G
.
Print the real, instead of effective, user or group id. Requires
-u
, -g
, or -G
.
Print only the user id.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
logname
: Print current login namelogname
prints the calling user’s name, as found in the file
‘/etc/utmp’, and exits with a status of 0. If there is no
‘/etc/utmp’ entry for the calling process, logname
prints
an error message and exits with a status of 1.
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
whoami
: Print effective user idwhoami
prints the user name associated with the current
effective user id. It is equivalent to the command ‘id -un’.
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
groups
: Print group names a user is ingroups
prints the names of the primary and any supplementary
groups that each given username, or the current process if none
are given, is in. If user names are given, the name of each user is
printed before the list of that user’s groups.
Synopsis:
groups [ username ]…
The group lists are equivalent to the output of the command ‘id -Gn’.
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
users
: Print login names of users currently logged inusers
prints on a single line a blank-separated list of user
names of users currently logged in to the current host. Each user name
corresponds to a login session, so if a user has more than one login
session, that user’s name will appear the same number of times in the
output.
Synopsis:
users [ file ]
With no file argument, users
extracts its information from
the file ‘/etc/utmp’. If a file argument is given, users
uses that file instead. A common choice is ‘/etc/wtmp’.
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
who
: Print who is currently logged inSynopsis:
who
[ option ] [ file ] [ am i ]
If given no non-option arguments, who
prints the following
information for each user currently logged on: login name, terminal
line, login time, and remote hostname or X display.
If given one non-option argument, who
uses that instead of
‘/etc/utmp’ as the name of the file containing the record of
users logged on. ‘/etc/wtmp’ is commonly given as an argument
to who
to look at who has previously logged on.
If given two non-option arguments, who
prints only the entry
for the user running it (determined from its standard input), preceded
by the hostname. Traditionally, the two arguments given are ‘am
i’, as in ‘who am i’.
The program accepts the following options. Also see Common options.
Same as ‘who am i’.
Print only the login names and the number of users logged on. Overrides all other options.
Ignored; for compatibility with other versions of who
.
After the login time, print the number of hours and minutes that the user has been idle. ‘.’ means the user was active in last minute. ‘old’ means the user was idle for more than 24 hours.
Print a line of column headings.
After each login name print a character indicating the user’s message status:
‘+’ allowingwrite
messages ‘-’ disallowingwrite
messages ‘?’ cannot find terminal device
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes commands that print or change system-wide information.
9.1 date : Print or set system date and time | Print or set system date and time. | |
9.2 uname : Print system information | Print system information. | |
9.3 hostname : Print or set system name | Print or set system name. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
date
: Print or set system date and timedate
with no arguments prints the current time and date, in
the format of the ‘%c’ directive (described below).
Synopses:
date [ option ]… [ +format ] date [ -u|--utc|--universal ] [ MMDDhhmm[[CC]YY][.ss] ]
If given an argument that starts with a ‘+’, date
prints the
current time and date (or the time and date specified by the
--date
option, see below) in the format defined by that argument,
which is the same as in the strftime
function. Except for
directives, which start with ‘%’, characters in the format string
are printed unchanged. The directives are described below.
By default, date
pads numeric fields with zeroes.
GNU date
recognizes the following numeric modifiers
between the ‘%’ and the directive. These are GNU extensions.
(hyphen) do not pad the field
(underscore) pad the field with spaces
9.1.1 Time directives | %[HIklMprsSTXZ] | |
9.1.2 Date directives | %[aAbBcdDhjmUwWxyY] | |
9.1.3 Literal directives | %[%nt] | |
9.1.4 Setting the time | Changing the system clock. | |
9.1.5 Options for date | Instead of the current time. | |
9.1.6 Examples of date | Examples. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
date
directives related to times.
hour (00…23)
hour (01…12)
hour ( 0…23)
hour ( 1…12)
minute (00…59)
locale’s AM or PM
time, 12-hour (hh:mm:ss [AP]M)
seconds since the epoch, i.e., 1 January 1970 00:00:00 UTC (a GNU extension)
second (00…61)
time, 24-hour (hh:mm:ss)
locale’s time representation (%H:%M:%S)
time zone (e.g., EDT), or nothing if no time zone is determinable
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
date
directives related to dates.
locale’s abbreviated weekday name (Sun…Sat)
locale’s full weekday name, variable length (Sunday…Saturday)
locale’s abbreviated month name (Jan…Dec)
locale’s full month name, variable length (January…December)
locale’s date and time (Sat Nov 04 12:02:33 EST 1989)
day of month (01…31)
date (mm/dd/yy)
same as %b
day of year (001…366)
month (01…12)
week number of year with Sunday as first day of week (00…53)
day of week (0…6) with 0 corresponding to Sunday
week number of year with Monday as first day of week (00…53)
locale’s date representation (mm/dd/yy)
last two digits of year (00…99)
year (1970….)
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
date
directives that produce literal strings.
a literal %
a newline
a horizontal tab
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If given an argument that does not start with ‘+’, date
sets
the system clock to the time and date specified by that argument (as
described below). You must have appropriate privileges to set the
system clock. The ‘--date’ and ‘--set’ options may not be
used with such an argument. The ‘--universal’ option may be used
with such an argument to indicate that the specified time and date are
relative to Coordinated Universal Time rather than to the local time
zone.
The argument must consist entirely of digits, which have the following meaning:
month
day within month
hour
minute
first two digits of year (optional)
last two digits of year (optional)
second (optional)
The ‘--set’ option also sets the system clock; see the next section.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
date
The program accepts the following options. Also see Common options.
Display the time and date specified in datestr instead of the current time and date. datestr can be in almost any common format. It can contain month names, timezones, ‘am’ and ‘pm’, ‘yesterday’, ‘ago’, ‘next’, etc. The source file ‘getdate.y’ implements this parsing for all GNU routines; we need precise documentation!
Parse each line in datefile as with ‘-d’ and display the
resulting time and date. If datefile is ‘-’, use standard
input. This is useful when you have many dates to process, because the
system overhead of starting up the date
executable many times can
be considerable.
Set the time and date to datestr, See ‘-d’ above.
Print or set the time and date in Universal Coordinated Time instead of in local (wall clock) time.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
date
Here are a few examples. Also see the documentation for the ‘-d’ option in the previous section.
date --date='2 days ago'
date --date='3 months 1 day'
date --date='25 Dec' +%j
date '+%B %d'
But this may not be what you want because for the first nine days of the month, the ‘%d’ expands to a zero-padded two-digit field, for example ‘date -d 1may '+%B %d'’ will print ‘May 01’.
-
modifier to suppress
the padding altogether.
date -d=1may '+%B %-d'
date
when setting the system clock:
date +%m%d%H%M%Y.%S
date --set='+2 minutes'
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
uname
: Print system informationuname
prints information about the machine and operating system
it is run on. If no options are given, uname
acts as if the
-s
option were given.
Synopsis:
uname [ option ]…
If multiple options or -a
are given, the selected information is
printed in this order:
sysname nodename release osversion machine
The osversion, at least, may well be multiple words. For example:
bash$ uname -a ⇒ Linux hayley 1.0.4 #3 Thu May 12 18:06:34 1994 i486
The program accepts the following options. Also see Common options.
Print all of the below information.
Print the machine (hardware) type.
Print the machine’s network node hostname.
Print the operating system release.
Print the operating system name.
Print the operating system version.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
hostname
: Print or set system nameWith no arguments, hostname
prints the name of the current host
system. With one argument, it sets the current host name to the
specified string. You must have appropriate privileges to set the host
name.
Synopsis:
hostname [ name ]
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes commands that run other commands in some context different than the current one: a modified environment, as a different user, etc.
10.1 env : Run a command in a modified environment | Modify environment variables. | |
10.2 nice : Run a command with modified scheduling priority | Modify scheduling priority. | |
10.3 nohup : Run a command immune to hangups | Immunize to hangups. | |
10.4 su : Run a command with substitute user and group id | Modify user and group id. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
env
: Run a command in a modified environmentenv
runs a command with an environment modified as specified
by the command line arguments.
Synopses:
env [ option ]… [ name=value ]… [ command [ args ]… ] env
Arguments of the form ‘variable=value’ set the environment variable variable to value value. value may be empty (‘variable=’). Setting a variable to an empty value is different from unsetting it.
The first remaining argument specifies the program name to invoke; it is
searched for according to the PATH
environment variable. Any
remaining arguments are passed as arguments to that program.
If no command name is specified following the environment
specifications, the resulting environment is printed. This is like
specifying a command name of printenv
.
The program accepts the following options. Also see Common options.
Remove variable name from the environment, if it was in the environment.
Start with an empty environment, ignoring the inherited environment.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
nice
: Run a command with modified scheduling priorityIf no arguments are given, nice
prints the current scheduling
priority, which it inherited. Otherwise, nice
runs the given
command with its scheduling priority adjusted. If no
adjustment is given, the priority of the command is incremented by
10. You must have appropriate privileges to specify a negative
adjustment. The priority can be adjusted by nice
over the range
of -20 (the highest priority) to 19 (the lowest).
Synopsis:
nice [ option ]… [ command [ arg ]… ]
Because most shells have a built-in command by the same name, using the unadorned command name in a script or interactively may get you different functionality than that described here.
The program accepts the following option. Also see Common options.
Add adjustment instead of 10 to the command’s priority.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
nohup
: Run a command immune to hangupsnohup
runs the given command with hangup signals ignored,
so that the command can continue running in the background after you log
out.
Synopsis:
nohup command [ arg ]…
Also, the scheduling priority is increased by 5. If standard output is a tty, it and standard error are redirected so that they are appended to the file ‘nohup.out’; if that cannot be written to, they are appended to the file ‘$HOME/nohup.out’. If that cannot be written to, the command is not run.
If nohup
creates either ‘nohup.out’ or
‘$HOME/nohup.out’, it creates it with no “group” or “other”
access permissions. It does not change the permissions if the output
file already existed.
nohup
does not automatically put the command it runs in the
background; you must do that explicitly, by ending the command line
with an ‘&’.
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
su
: Run a command with substitute user and group idsu
allows one user to temporarily become another user. It runs a
command (often an interactive shell) with the real and effective user
id, group id, and supplemental groups of a given user.
Synopsis:
su [ option ]… [ user [ arg ]… ]
If no user is given, the default is root
, the super-user.
The shell to use is taken from user’s passwd
entry, or
‘/bin/sh’ if none is specified there. If user has a
password, su
prompts for the password unless run by a user with
effective user id of zero (the super-user).
By default, su
does not change the current directory.
It sets the environment variables HOME
and SHELL
from the password entry for user, and if user is not
the super-user, sets USER
and LOGNAME
to user.
By default, the shell is not a login shell.
Any additional args are passed as additional arguments to the shell.
GNU su
does not treat ‘/bin/sh’ or any other shells specially
(e.g., by setting argv[0]
to ‘-su’, passing -c
only
to certain shells, etc.).
su
can optionally be compiled to use syslog
to report
failed, and optionally successful, su
attempts. (If the system
supports syslog
.) However, GNU su
does not check if the
user is a member of the wheel
group; see below.
The program accepts the following options. Also see Common options.
Pass command, a single command line to run, to the shell with
a -c
option instead of starting an interactive shell.
Pass the -f
option to the shell. This probably only makes sense
if the shell run is csh
or tcsh
, for which the -f
option prevents reading the startup file (‘.cshrc’). With
Bourne-like shells, the -f
option disables file name pattern
expansion (globbing), which is not likely to be useful.
Make the shell a login shell. This means the following. Unset all
environment variables except TERM
, HOME
, and SHELL
(which are set as described above), and USER
and LOGNAME
(which are set, even for the super-user, as described above), and set
PATH
to a compiled-in default value. Change to user’s home
directory. Prepend ‘-’ to the shell’s name, intended to make it
read its login startup file(s).
Do not change the environment variables HOME
, USER
,
LOGNAME
, or SHELL
. Run the shell given in the environment
variable SHELL
instead of the shell from user’s passwd
entry, unless the user running su
is not the superuser and
user’s shell is restricted. A restricted shell is one that
is not listed in the file ‘/etc/shells’, or in a compiled-in list
if that file does not exist. Parts of what this option does can be
overridden by --login
and --shell
.
Run shell instead of the shell from user’s passwd entry,
unless the user running su
is not the superuser and user’s
shell is restricted (see ‘-m’ just above).
su
does not support the ‘wheel’ group(This section is by Richard Stallman.)
Sometimes a few of the users try to hold total power over all the rest. For example, in 1984, a few users at the MIT AI lab decided to seize power by changing the operator password on the Twenex system and keeping it secret from everyone else. (I was able to thwart this coup and give power back to the users by patching the kernel, but I wouldn’t know how to do that in Unix.)
However, occasionally the rulers do tell someone. Under the usual
su
mechanism, once someone learns the root password who
sympathizes with the ordinary users, he or she can tell the rest. The
“wheel group” feature would make this impossible, and thus cement the
power of the rulers.
I’m on the side of the masses, not that of the rulers. If you are used to supporting the bosses and sysadmins in whatever they do, you might find this idea strange at first.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Perhaps wait
or other commands should be described here also?
11.1 sleep : Delay for a specified time | Delay for a specified time. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
sleep
: Delay for a specified timesleep
pauses for an amount of time specified by the sum of
the values of the command line arguments.
Synopsis:
sleep [ number[smhd] ]…
Each argument is a number followed by an optional unit; the default is seconds. The units are:
seconds
minutes
hours
days
The only options are ‘--help’ and ‘--version’. See section Common options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | !
%
&
*
+
-
.
/
<
=
>
\
|
A B C D E F G H I K L M N O P Q R S T U V W X Y Z |
---|
Jump to: | !
%
&
*
+
-
.
/
<
=
>
\
|
A B C D E F G H I K L M N O P Q R S T U V W X Y Z |
---|
[Top] | [Contents] | [Index] | [ ? ] |
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on September 19, 2022 using texi2html 5.0.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ Up ] | Up | Up section | 1.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on September 19, 2022 using texi2html 5.0.