summaryrefslogtreecommitdiff
path: root/doc/coreutils.texi
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-01-20 10:55:18 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-01-20 10:55:18 +0000
commit70e9163c9c18e995515598085cb824e554eb7ae7 (patch)
treea42dc8b2a6c031354bf31472de888bfc8a060132 /doc/coreutils.texi
parentcbf5993c43f49281173f185863577d86bfac6eae (diff)
downloadcoreutils-tarball-master.tar.gz
Diffstat (limited to 'doc/coreutils.texi')
-rw-r--r--doc/coreutils.texi7182
1 files changed, 5333 insertions, 1849 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 588147f..01791be 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -1,7 +1,9 @@
\input texinfo
@c %**start of header
@setfilename coreutils.info
-@settitle @sc{gnu} Coreutils
+@settitle GNU Coreutils
+@documentencoding UTF-8
+@allowcodebreaks false
@c %**end of header
@@ -23,7 +25,7 @@
@dircategory Basics
@direntry
* Coreutils: (coreutils). Core GNU (file, text, shell) utilities.
-* Common options: (coreutils)Common options. Common options.
+* Common options: (coreutils)Common options.
* File permissions: (coreutils)File permissions. Access modes.
* Date input formats: (coreutils)Date input formats.
@end direntry
@@ -31,16 +33,18 @@
@c FIXME: the following need documentation
@c * [: (coreutils)[ invocation. File/string tests.
@c * pinky: (coreutils)pinky invocation. FIXME.
-@c * uptime: (coreutils)uptime invocation. FIXME.
@dircategory Individual utilities
@direntry
+* arch: (coreutils)arch invocation. Print machine hardware name.
+* base32: (coreutils)base32 invocation. Base32 encode/decode data.
* base64: (coreutils)base64 invocation. Base64 encode/decode data.
* basename: (coreutils)basename invocation. Strip directory and suffix.
* cat: (coreutils)cat invocation. Concatenate and write files.
+* chcon: (coreutils)chcon invocation. Change SELinux CTX of files.
* chgrp: (coreutils)chgrp invocation. Change file groups.
-* chmod: (coreutils)chmod invocation. Change file permissions.
-* chown: (coreutils)chown invocation. Change file owners/groups.
+* chmod: (coreutils)chmod invocation. Change access permissions.
+* chown: (coreutils)chown invocation. Change file owners and groups.
* chroot: (coreutils)chroot invocation. Specify the root directory.
* cksum: (coreutils)cksum invocation. Print POSIX CRC checksum.
* comm: (coreutils)comm invocation. Compare sorted files by line.
@@ -52,7 +56,7 @@
* df: (coreutils)df invocation. Report file system disk usage.
* dir: (coreutils)dir invocation. List directories briefly.
* dircolors: (coreutils)dircolors invocation. Color setup for ls.
-* dirname: (coreutils)dirname invocation. Strip non-directory suffix.
+* dirname: (coreutils)dirname invocation. Strip last file name component.
* du: (coreutils)du invocation. Report on disk usage.
* echo: (coreutils)echo invocation. Print a line of text.
* env: (coreutils)env invocation. Modify the environment.
@@ -67,7 +71,7 @@
* hostid: (coreutils)hostid invocation. Print numeric host identifier.
* hostname: (coreutils)hostname invocation. Print or set system name.
* id: (coreutils)id invocation. Print user identity.
-* install: (coreutils)install invocation. Copy and change attributes.
+* install: (coreutils)install invocation. Copy files and set attributes.
* join: (coreutils)join invocation. Join lines on a common field.
* kill: (coreutils)kill invocation. Send a signal to processes.
* link: (coreutils)link invocation. Make hard links between files.
@@ -78,10 +82,13 @@
* mkdir: (coreutils)mkdir invocation. Create directories.
* mkfifo: (coreutils)mkfifo invocation. Create FIFOs (named pipes).
* mknod: (coreutils)mknod invocation. Create special files.
+* mktemp: (coreutils)mktemp invocation. Create temporary files.
* mv: (coreutils)mv invocation. Rename files.
* nice: (coreutils)nice invocation. Modify niceness.
* nl: (coreutils)nl invocation. Number lines and write files.
* nohup: (coreutils)nohup invocation. Immunize to hangups.
+* nproc: (coreutils)nproc invocation. Print the number of processors.
+* numfmt: (coreutils)numfmt invocation. Reformat numbers.
* od: (coreutils)od invocation. Dump files in octal, etc.
* paste: (coreutils)paste invocation. Merge lines of files.
* pathchk: (coreutils)pathchk invocation. Check file name portability.
@@ -91,8 +98,10 @@
* ptx: (coreutils)ptx invocation. Produce permuted indexes.
* pwd: (coreutils)pwd invocation. Print working directory.
* readlink: (coreutils)readlink invocation. Print referent of a symlink.
+* realpath: (coreutils)realpath invocation. Print resolved file names.
* rm: (coreutils)rm invocation. Remove files.
* rmdir: (coreutils)rmdir invocation. Remove empty directories.
+* runcon: (coreutils)runcon invocation. Run in specified SELinux CTX.
* seq: (coreutils)seq invocation. Print numeric sequences
* sha1sum: (coreutils)sha1sum invocation. Print or check SHA-1 digests.
* sha2: (coreutils)sha2 utilities. Print or check SHA-2 digests.
@@ -100,25 +109,28 @@
* shuf: (coreutils)shuf invocation. Shuffling text files.
* sleep: (coreutils)sleep invocation. Delay for a specified time.
* sort: (coreutils)sort invocation. Sort text files.
-* split: (coreutils)split invocation. Split into fixed-size pieces.
+* split: (coreutils)split invocation. Split into pieces.
* stat: (coreutils)stat invocation. Report file(system) status.
+* stdbuf: (coreutils)stdbuf invocation. Modify stdio buffering.
* stty: (coreutils)stty invocation. Print/change terminal settings.
-* su: (coreutils)su invocation. Modify user and group ID.
* sum: (coreutils)sum invocation. Print traditional checksum.
-* sync: (coreutils)sync invocation. Synchronize memory and disk.
+* sync: (coreutils)sync invocation. Synchronize memory to disk.
* tac: (coreutils)tac invocation. Reverse files.
* tail: (coreutils)tail invocation. Output the last part of files.
* tee: (coreutils)tee invocation. Redirect to multiple files.
* test: (coreutils)test invocation. File/string tests.
+* timeout: (coreutils)timeout invocation. Run with time limit.
* touch: (coreutils)touch invocation. Change file timestamps.
* tr: (coreutils)tr invocation. Translate characters.
* true: (coreutils)true invocation. Do nothing, successfully.
+* truncate: (coreutils)truncate invocation. Shrink/extend size of a file.
* tsort: (coreutils)tsort invocation. Topological sort.
* tty: (coreutils)tty invocation. Print terminal name.
* uname: (coreutils)uname invocation. Print system information.
* unexpand: (coreutils)unexpand invocation. Convert spaces to tabs.
* uniq: (coreutils)uniq invocation. Uniquify files.
* unlink: (coreutils)unlink invocation. Removal via unlink(2).
+* uptime: (coreutils)uptime invocation. Print uptime and load.
* users: (coreutils)users invocation. Print current user names.
* vdir: (coreutils)vdir invocation. List directories verbosely.
* wc: (coreutils)wc invocation. Line, word, and byte counts.
@@ -128,15 +140,14 @@
@end direntry
@copying
-This manual documents version @value{VERSION} of the @sc{gnu} core
+This manual documents version @value{VERSION} of the GNU core
utilities, including the standard programs for text and file manipulation.
-Copyright @copyright{} 1994, 1995, 1996, 2000, 2001, 2002, 2003, 2004,
-2005, 2006 Free Software Foundation, Inc.
+Copyright @copyright{} 1994-2016 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
-under the terms of the GNU Free Documentation License, Version 1.2 or
+under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
@@ -145,7 +156,7 @@ Free Documentation License''.
@end copying
@titlepage
-@title @sc{gnu} @code{Coreutils}
+@title GNU @code{Coreutils}
@subtitle Core GNU utilities
@subtitle for version @value{VERSION}, @value{UPDATED}
@author David MacKenzie et al.
@@ -154,7 +165,8 @@ Free Documentation License''.
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
-
+@shortcontents
+@contents
@ifnottex
@node Top
@@ -169,205 +181,213 @@ Free Documentation License''.
@cindex file utilities
@menu
-* Introduction:: Caveats, overview, and authors.
-* Common options:: Common options.
-* Output of entire files:: cat tac nl od
-* Formatting file contents:: fmt pr fold
-* Output of parts of files:: head tail split csplit
-* Summarizing files:: wc sum cksum md5sum sha1sum sha2
-* Operating on sorted files:: sort shuf uniq comm ptx tsort
-* Operating on fields within a line:: cut paste join
-* Operating on characters:: tr expand unexpand
-* Directory listing:: ls dir vdir dircolors
-* Basic operations:: cp dd install mv rm shred
-* Special file types:: ln mkdir rmdir mkfifo mknod
-* Changing file attributes:: chgrp chmod chown touch
-* Disk usage:: df du stat sync
-* Printing text:: echo printf yes
-* Conditions:: false true test expr
-* Redirection:: tee
-* File name manipulation:: dirname basename pathchk
-* Working context:: pwd stty printenv tty
-* User information:: id logname whoami groups users who
-* System context:: date uname hostname hostid
-* Modified command invocation:: chroot env nice nohup su
-* Process control:: kill
-* Delaying:: sleep
-* Numeric operations:: factor seq
-* File permissions:: Access modes.
-* Date input formats:: Specifying date strings.
-* Opening the software toolbox:: The software tools philosophy.
-* Copying This Manual:: License for copying this manual.
-* Index:: General index.
+* Introduction:: Caveats, overview, and authors
+* Common options:: Common options
+* Output of entire files:: cat tac nl od base32 base64
+* Formatting file contents:: fmt pr fold
+* Output of parts of files:: head tail split csplit
+* Summarizing files:: wc sum cksum md5sum sha1sum sha2
+* Operating on sorted files:: sort shuf uniq comm ptx tsort
+* Operating on fields:: cut paste join
+* Operating on characters:: tr expand unexpand
+* Directory listing:: ls dir vdir dircolors
+* Basic operations:: cp dd install mv rm shred
+* Special file types:: mkdir rmdir unlink mkfifo mknod ln link readlink
+* Changing file attributes:: chgrp chmod chown touch
+* Disk usage:: df du stat sync truncate
+* Printing text:: echo printf yes
+* Conditions:: false true test expr
+* Redirection:: tee
+* File name manipulation:: dirname basename pathchk mktemp realpath
+* Working context:: pwd stty printenv tty
+* User information:: id logname whoami groups users who
+* System context:: date arch nproc uname hostname hostid uptime
+* SELinux context:: chcon runcon
+* Modified command invocation:: chroot env nice nohup stdbuf timeout
+* Process control:: kill
+* Delaying:: sleep
+* Numeric operations:: factor numfmt seq
+* File permissions:: Access modes
+* Date input formats:: Specifying date strings
+* Opening the software toolbox:: The software tools philosophy
+* GNU Free Documentation License:: Copying and sharing this manual
+* Concept index:: General index
@detailmenu
--- The Detailed Node Listing ---
Common Options
-* Exit status:: Indicating program success or failure.
-* Backup options:: Backup options
-* Block size:: Block size
-* Disambiguating names and IDs:: chgrp and chown owner and group syntax
-* Random sources:: Sources of random data
-* Target directory:: Target directory
-* Trailing slashes:: Trailing slashes
-* Traversing symlinks:: Traversing symlinks to directories
-* Treating / specially:: Treating / specially
-* Standards conformance:: Standards conformance
+* Exit status:: Indicating program success or failure
+* Backup options:: Backup options
+* Block size:: Block size
+* Floating point:: Floating point number representation
+* Signal specifications:: Specifying signals
+* Disambiguating names and IDs:: chgrp, chown, chroot, id: user and group syntax
+* Random sources:: Sources of random data
+* Target directory:: Target directory
+* Trailing slashes:: Trailing slashes
+* Traversing symlinks:: Traversing symlinks to directories
+* Treating / specially:: Treating / specially
+* Standards conformance:: Standards conformance
+* Multi-call invocation:: Multi-call program invocation
Output of entire files
-* cat invocation:: Concatenate and write files.
-* tac invocation:: Concatenate and write files in reverse.
-* nl invocation:: Number lines and write files.
-* od invocation:: Write files in octal or other formats.
-* base64 invocation:: Transform data into printable data.
+* cat invocation:: Concatenate and write files
+* tac invocation:: Concatenate and write files in reverse
+* nl invocation:: Number lines and write files
+* od invocation:: Write files in octal or other formats
+* base32 invocation:: Transform data into printable data
+* base64 invocation:: Transform data into printable data
Formatting file contents
-* fmt invocation:: Reformat paragraph text.
-* pr invocation:: Paginate or columnate files for printing.
-* fold invocation:: Wrap input lines to fit in specified width.
+* fmt invocation:: Reformat paragraph text
+* pr invocation:: Paginate or columnate files for printing
+* fold invocation:: Wrap input lines to fit in specified width
Output of parts of files
-* head invocation:: Output the first part of files.
-* tail invocation:: Output the last part of files.
-* split invocation:: Split a file into fixed-size pieces.
-* csplit invocation:: Split a file into context-determined pieces.
+* head invocation:: Output the first part of files
+* tail invocation:: Output the last part of files
+* split invocation:: Split a file into fixed-size pieces
+* csplit invocation:: Split a file into context-determined pieces
Summarizing files
-* wc invocation:: Print newline, word, and byte counts.
-* sum invocation:: Print checksum and block counts.
-* cksum invocation:: Print CRC checksum and byte counts.
-* md5sum invocation:: Print or check MD5 digests.
-* sha1sum invocation:: Print or check SHA-1 digests.
-* sha2 utilities:: Print or check SHA-2 digests.
+* wc invocation:: Print newline, word, and byte counts
+* sum invocation:: Print checksum and block counts
+* cksum invocation:: Print CRC checksum and byte counts
+* md5sum invocation:: Print or check MD5 digests
+* sha1sum invocation:: Print or check SHA-1 digests
+* sha2 utilities:: Print or check SHA-2 digests
Operating on sorted files
-* sort invocation:: Sort text files.
-* shuf invocation:: Shuffle text files.
-* uniq invocation:: Uniquify files.
-* comm invocation:: Compare two sorted files line by line.
-* ptx invocation:: Produce a permuted index of file contents.
-* tsort invocation:: Topological sort.
+* sort invocation:: Sort text files
+* shuf invocation:: Shuffle text files
+* uniq invocation:: Uniquify files
+* comm invocation:: Compare two sorted files line by line
+* ptx invocation:: Produce a permuted index of file contents
+* tsort invocation:: Topological sort
@command{ptx}: Produce permuted indexes
-* General options in ptx:: Options which affect general program behavior.
-* Charset selection in ptx:: Underlying character set considerations.
-* Input processing in ptx:: Input fields, contexts, and keyword selection.
-* Output formatting in ptx:: Types of output format, and sizing the fields.
-* Compatibility in ptx:: The @acronym{GNU} extensions to @command{ptx}
+* General options in ptx:: Options which affect general program behavior
+* Charset selection in ptx:: Underlying character set considerations
+* Input processing in ptx:: Input fields, contexts, and keyword selection
+* Output formatting in ptx:: Types of output format, and sizing the fields
+* Compatibility in ptx:: The GNU extensions to @command{ptx}
-Operating on fields within a line
+Operating on fields
-* cut invocation:: Print selected parts of lines.
-* paste invocation:: Merge lines of files.
-* join invocation:: Join lines on a common field.
+* cut invocation:: Print selected parts of lines
+* paste invocation:: Merge lines of files
+* join invocation:: Join lines on a common field
Operating on characters
-* tr invocation:: Translate, squeeze, and/or delete characters.
-* expand invocation:: Convert tabs to spaces.
-* unexpand invocation:: Convert spaces to tabs.
+* tr invocation:: Translate, squeeze, and/or delete characters
+* expand invocation:: Convert tabs to spaces
+* unexpand invocation:: Convert spaces to tabs
@command{tr}: Translate, squeeze, and/or delete characters
-* Character sets:: Specifying sets of characters.
-* Translating:: Changing one set of characters to another.
-* Squeezing:: Squeezing repeats and deleting.
+* Character sets:: Specifying sets of characters
+* Translating:: Changing one set of characters to another
+* Squeezing and deleting:: Removing characters
Directory listing
-* ls invocation:: List directory contents
-* dir invocation:: Briefly list directory contents
-* vdir invocation:: Verbosely list directory contents
-* dircolors invocation:: Color setup for @command{ls}
+* ls invocation:: List directory contents
+* dir invocation:: Briefly list directory contents
+* vdir invocation:: Verbosely list directory contents
+* dircolors invocation:: Color setup for @command{ls}
@command{ls}: List directory contents
-* Which files are listed:: Which files are listed
-* What information is listed:: What information is listed
-* Sorting the output:: Sorting the output
-* More details about version sort:: More details about version sort
-* General output formatting:: General output formatting
-* Formatting the file names:: Formatting the file names
+* Which files are listed:: Which files are listed
+* What information is listed:: What information is listed
+* Sorting the output:: Sorting the output
+* Details about version sort:: More details about version sort
+* General output formatting:: General output formatting
+* Formatting the file names:: Formatting the file names
Basic operations
-* cp invocation:: Copy files and directories
-* dd invocation:: Convert and copy a file
-* install invocation:: Copy files and set attributes
-* mv invocation:: Move (rename) files
-* rm invocation:: Remove files or directories
-* shred invocation:: Remove files more securely
+* cp invocation:: Copy files and directories
+* dd invocation:: Convert and copy a file
+* install invocation:: Copy files and set attributes
+* mv invocation:: Move (rename) files
+* rm invocation:: Remove files or directories
+* shred invocation:: Remove files more securely
Special file types
-* link invocation:: Make a hard link via the link syscall
-* ln invocation:: Make links between files
-* mkdir invocation:: Make directories
-* mkfifo invocation:: Make FIFOs (named pipes)
-* mknod invocation:: Make block or character special files
-* readlink invocation:: Print the referent of a symbolic link
-* rmdir invocation:: Remove empty directories
-* unlink invocation:: Remove files via unlink syscall
+* link invocation:: Make a hard link via the link syscall
+* ln invocation:: Make links between files
+* mkdir invocation:: Make directories
+* mkfifo invocation:: Make FIFOs (named pipes)
+* mknod invocation:: Make block or character special files
+* readlink invocation:: Print value of a symlink or canonical file name
+* rmdir invocation:: Remove empty directories
+* unlink invocation:: Remove files via unlink syscall
Changing file attributes
-* chown invocation:: Change file owner and group
-* chgrp invocation:: Change group ownership
-* chmod invocation:: Change access permissions
-* touch invocation:: Change file timestamps
+* chown invocation:: Change file owner and group
+* chgrp invocation:: Change group ownership
+* chmod invocation:: Change access permissions
+* touch invocation:: Change file timestamps
Disk usage
-* df invocation:: Report file system disk space usage
-* du invocation:: Estimate file space usage
-* stat invocation:: Report file or file system status
-* sync invocation:: Synchronize data on disk with memory
+* df invocation:: Report file system disk space usage
+* du invocation:: Estimate file space usage
+* stat invocation:: Report file or file system status
+* sync invocation:: Synchronize cached writes to persistent storage
+* truncate invocation:: Shrink or extend the size of a file
Printing text
-* echo invocation:: Print a line of text
-* printf invocation:: Format and print data
-* yes invocation:: Print a string until interrupted
+* echo invocation:: Print a line of text
+* printf invocation:: Format and print data
+* yes invocation:: Print a string until interrupted
Conditions
-* false invocation:: Do nothing, unsuccessfully
-* true invocation:: Do nothing, successfully
-* test invocation:: Check file types and compare values
-* expr invocation:: Evaluate expressions
+* false invocation:: Do nothing, unsuccessfully
+* true invocation:: Do nothing, successfully
+* test invocation:: Check file types and compare values
+* expr invocation:: Evaluate expressions
@command{test}: Check file types and compare values
-* File type tests:: File type tests
-* Access permission tests:: Access permission tests
-* File characteristic tests:: File characteristic tests
-* String tests:: String tests
-* Numeric tests:: Numeric tests
+* File type tests:: File type tests
+* Access permission tests:: Access permission tests
+* File characteristic tests:: File characteristic tests
+* String tests:: String tests
+* Numeric tests:: Numeric tests
@command{expr}: Evaluate expression
-* String expressions:: + : match substr index length
-* Numeric expressions:: + - * / %
-* Relations for expr:: | & < <= = == != >= >
-* Examples of expr:: Examples of using @command{expr}
+* String expressions:: + : match substr index length
+* Numeric expressions:: + - * / %
+* Relations for expr:: | & < <= = == != >= >
+* Examples of expr:: Examples of using @command{expr}
Redirection
-* tee invocation:: Redirect output to multiple files
+* tee invocation:: Redirect output to multiple files or processes
File name manipulation
* basename invocation:: Strip directory and suffix from a file name
-* dirname invocation:: Strip non-directory suffix from a file name
-* pathchk invocation:: Check file name portability
+* dirname invocation:: Strip last file name component
+* pathchk invocation:: Check file name validity and portability
+* mktemp invocation:: Create temporary file or directory
+* realpath invocation:: Print resolved file names
Working context
@@ -378,13 +398,13 @@ Working context
@command{stty}: Print or change terminal characteristics
-* Control:: Control settings
-* Input:: Input settings
-* Output:: Output settings
-* Local:: Local settings
-* Combination:: Combination settings
-* Characters:: Special characters
-* Special:: Special settings
+* Control:: Control settings
+* Input:: Input settings
+* Output:: Output settings
+* Local:: Local settings
+* Combination:: Combination settings
+* Characters:: Special characters
+* Special:: Special settings
User information
@@ -397,10 +417,13 @@ User information
System context
+* arch invocation:: Print machine hardware name
* date invocation:: Print or set system date and time
+* nproc invocation:: Print the number of processors
* uname invocation:: Print system information
* hostname invocation:: Print or set system name
-* hostid invocation:: Print numeric host identifier.
+* hostid invocation:: Print numeric host identifier
+* uptime invocation:: Print system uptime and load
@command{date}: Print or set system date and time
@@ -408,9 +431,15 @@ System context
* Date conversion specifiers:: %[aAbBcCdDeFgGhjmuUVwWxyY]
* Literal conversion specifiers:: %[%nt]
* Padding and other flags:: Pad with zeros, spaces, etc.
-* Setting the time:: Changing the system clock.
-* Options for date:: Instead of the current time.
-* Examples of date:: Examples.
+* Setting the time:: Changing the system clock
+* Options for date:: Instead of the current time
+* Date input formats:: Specifying date strings
+* Examples of date:: Examples
+
+SELinux context
+
+* chcon invocation:: Change SELinux context of file
+* runcon invocation:: Run a command in specified SELinux context
Modified command invocation
@@ -418,7 +447,8 @@ Modified command invocation
* env invocation:: Run a command in a modified environment
* nice invocation:: Run a command with modified niceness
* nohup invocation:: Run a command immune to hangups
-* su invocation:: Run a command with substitute user and group ID
+* stdbuf invocation:: Run a command with modified I/O buffering
+* timeout invocation:: Run a command with a time limit
Process control
@@ -431,27 +461,29 @@ Delaying
Numeric operations
* factor invocation:: Print prime factors
+* numfmt invocation:: Reformat numbers
* seq invocation:: Print numeric sequences
File permissions
-* Mode Structure:: Structure of file mode bits.
-* Symbolic Modes:: Mnemonic representation of file mode bits.
-* Numeric Modes:: File mode bits as octal numbers.
-* Directory Setuid and Setgid:: Set-user-ID and set-group-ID on directories.
+* Mode Structure:: Structure of file mode bits
+* Symbolic Modes:: Mnemonic representation of file mode bits
+* Numeric Modes:: File mode bits as octal numbers
+* Directory Setuid and Setgid:: Set-user-ID and set-group-ID on directories
Date input formats
-* General date syntax:: Common rules.
-* Calendar date items:: 19 Dec 1994.
-* Time of day items:: 9:20pm.
-* Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
-* Day of week items:: Monday and others.
-* Relative items in date strings:: next tuesday, 2 years ago.
-* Pure numbers in date strings:: 19931219, 1440.
-* Seconds since the Epoch:: @@1078100502.
-* Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
-* Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
+* General date syntax:: Common rules
+* Calendar date items:: 19 Dec 1994
+* Time of day items:: 9:20pm
+* Time zone items:: EST, PDT, UTC, @dots{}
+* Combined date and time of day items:: 1972-09-24T20:02:00,000000-0500
+* Day of week items:: Monday and others
+* Relative items in date strings:: next tuesday, 2 years ago
+* Pure numbers in date strings:: 19931219, 1440
+* Seconds since the Epoch:: @@1078100502
+* Specifying time zone rules:: TZ="America/New_York", TZ="UTC0"
+* Authors of parse_datetime:: Bellovin, Eggert, Salz, Berets, et al.
Opening the software toolbox
@@ -465,7 +497,7 @@ Opening the software toolbox
Copying This Manual
-* GNU Free Documentation License:: License for copying this manual.
+* GNU Free Documentation License:: Copying and sharing this manual
@end detailmenu
@end menu
@@ -476,17 +508,26 @@ Copying This Manual
This manual is a work in progress: many sections make no attempt to explain
basic concepts in a way suitable for novices. Thus, if you are interested,
-please get involved in improving this manual. The entire @sc{gnu} community
+please get involved in improving this manual. The entire GNU community
will benefit.
-@cindex @acronym{POSIX}
-The @sc{gnu} utilities documented here are mostly compatible with the
-@acronym{POSIX} standard.
+@cindex POSIX
+The GNU utilities documented here are mostly compatible with the
+POSIX standard.
@cindex bugs, reporting
-Please report bugs to @email{bug-coreutils@@gnu.org}. Remember
-to include the version number, machine architecture, input files, and
+
+Please report bugs to @email{bug-coreutils@@gnu.org}.
+Include the version number, machine architecture, input files, and
any other information needed to reproduce the bug: your input, what you
-expected, what you got, and why it is wrong. Diffs are welcome, but
+expected, what you got, and why it is wrong.
+
+If you have a problem with @command{sort}, try running @samp{sort
+--debug}, as it can can often help find and fix problems without
+having to wait for an answer to a bug report. If the debug output
+does not suffice to fix the problem on your own, please compress and
+attach it to the rest of your bug report.
+
+Although diffs are welcome,
please include a description of the problem as well, since this is
sometimes difficult to infer. @xref{Bugs, , , gcc, Using and Porting GNU CC}.
@@ -514,7 +555,7 @@ insights to the overall process.
@macro optBackup
@item -b
-@itemx @w{@kbd{--backup}[=@var{method}]}
+@itemx --backup[=@var{method}]
@opindex -b
@opindex --backup
@vindex VERSION_CONTROL
@@ -534,7 +575,7 @@ Append @var{suffix} to each backup file made with @option{-b}.
@macro optTargetDirectory
@item -t @var{directory}
-@itemx @w{@kbd{--target-directory}=@var{directory}}
+@itemx --target-directory=@var{directory}
@opindex -t
@opindex --target-directory
@cindex target directory
@@ -554,8 +595,46 @@ Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. @xref{Target directory}.
@end macro
+@macro outputNUL
+@cindex output NUL-byte-terminated lines
+Output a zero byte (ASCII NUL) at the end of each line,
+rather than a newline. This option enables other programs to parse the
+output even when that output would contain data with embedded newlines.
+@end macro
+
+@macro optNull
+@item -0
+@itemx --null
+@opindex -0
+@opindex --null
+@outputNUL
+@end macro
+
+@macro optZero
+@item -z
+@itemx --zero
+@opindex -z
+@opindex --zero
+@outputNUL
+@end macro
+
+@macro optZeroTerminated
+@item -z
+@itemx --zero-terminated
+@opindex -z
+@opindex --zero-terminated
+@cindex process zero-terminated items
+Delimit items with a zero byte rather than a newline (ASCII LF).
+I.e., treat input as items separated by ASCII NUL
+and terminate output items with ASCII NUL.
+This option can be useful in conjunction with @samp{perl -0} or
+@samp{find -print0} and @samp{xargs -0} which do the same in order to
+reliably handle arbitrary file names (even those containing blanks
+or other special characters).
+@end macro
+
@macro optSi
-@itemx --si
+@item --si
@opindex --si
@cindex SI output
Append an SI-style abbreviation to each size, such as @samp{M} for
@@ -574,22 +653,64 @@ you prefer powers of 1024.
@cindex human-readable output
Append a size letter to each size, such as @samp{M} for mebibytes.
Powers of 1024 are used, not 1000; @samp{M} stands for 1,048,576 bytes.
+This option is equivalent to @option{--block-size=human-readable}.
Use the @option{--si} option if you prefer powers of 1000.
@end macro
@macro optStripTrailingSlashes
-@itemx @w{@kbd{--strip-trailing-slashes}}
+@item --strip-trailing-slashes
@opindex --strip-trailing-slashes
@cindex stripping trailing slashes
Remove any trailing slashes from each @var{source} argument.
@xref{Trailing slashes}.
@end macro
+@macro mayConflictWithShellBuiltIn{cmd}
+@cindex conflicts with shell built-ins
+@cindex built-in shell commands, conflicts with
+Due to shell aliases and built-in @command{\cmd\} functions, using an
+unadorned @command{\cmd\} interactively or in a script may get you
+different functionality than that described here. Invoke it via
+@command{env} (i.e., @code{env \cmd\ @dots{}}) to avoid interference
+from the shell.
+
+@end macro
+
+@macro multiplierSuffixes{varName}
+@var{\varName\} may be, or may be an integer optionally followed by,
+one of the following multiplicative suffixes:
+@example
+@samp{b} => 512 ("blocks")
+@samp{KB} => 1000 (KiloBytes)
+@samp{K} => 1024 (KibiBytes)
+@samp{MB} => 1000*1000 (MegaBytes)
+@samp{M} => 1024*1024 (MebiBytes)
+@samp{GB} => 1000*1000*1000 (GigaBytes)
+@samp{G} => 1024*1024*1024 (GibiBytes)
+@end example
+and so on for @samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}.
+@end macro
+
+@c FIXME: same as above, but no ``blocks'' line.
+@macro multiplierSuffixesNoBlocks{varName}
+@var{\varName\} may be, or may be an integer optionally followed by,
+one of the following multiplicative suffixes:
+@example
+@samp{KB} => 1000 (KiloBytes)
+@samp{K} => 1024 (KibiBytes)
+@samp{MB} => 1000*1000 (MegaBytes)
+@samp{M} => 1024*1024 (MebiBytes)
+@samp{GB} => 1000*1000*1000 (GigaBytes)
+@samp{G} => 1024*1024*1024 (GibiBytes)
+@end example
+and so on for @samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}.
+@end macro
+
@cindex common options
Certain options are available in all of these programs. Rather than
writing identical descriptions for each of the programs, they are
-described here. (In fact, every @sc{gnu} program accepts (or should accept)
+described here. (In fact, every GNU program accepts (or should accept)
these options.)
@vindex POSIXLY_CORRECT
@@ -607,8 +728,15 @@ program description. For example, the @command{env} command's options
must appear before its operands, since in some cases the operands
specify a command that itself contains options.
+Most programs that accept long options recognize unambiguous
+abbreviations of those options. For example, @samp{rmdir
+--ignore-fail-on-non-empty} can be invoked as @samp{rmdir
+--ignore-fail} or even @samp{rmdir --i}. Ambiguous options, such as
+@samp{ls --h}, are identified as such.
+
Some of these programs recognize the @option{--help} and @option{--version}
-options only when one of them is the sole command line argument.
+options only when one of them is the sole command line argument. For
+these programs, abbreviations of the long options are not always recognized.
@table @samp
@@ -634,25 +762,27 @@ operands even if they begin with @samp{-}. For example, @samp{sort --
@cindex standard input
@cindex standard output
A single @samp{-} operand is not really an option, though it looks like one. It
-stands for standard input, or for standard output if that is clear from
-the context. For example, @samp{sort -} reads from standard input,
-and is equivalent to plain @samp{sort}, and @samp{tee -} writes an
-extra copy of its input to standard output. Unless otherwise
-specified, @samp{-} can appear as any operand that requires a file
+stands for a file operand, and some tools treat it as standard input, or as
+standard output if that is clear from the context. For example, @samp{sort -}
+reads from standard input, and is equivalent to plain @samp{sort}. Unless
+otherwise specified, a @samp{-} can appear as any operand that requires a file
name.
@menu
* Exit status:: Indicating program success or failure.
* Backup options:: -b -S, in some programs.
* Block size:: BLOCK_SIZE and --block-size, in some programs.
-* Disambiguating names and IDs:: chgrp and chown owner and group syntax
+* Floating point:: Floating point number representation.
+* Signal specifications:: Specifying signals using the --signal option.
+* Disambiguating names and IDs:: chgrp, chown, chroot, id: user and group syntax
* Random sources:: --random-source, in some programs.
* Target directory:: Specifying a target directory, in some programs.
* Trailing slashes:: --strip-trailing-slashes, in some programs.
* Traversing symlinks:: -H, -L, or -P, in some programs.
* Treating / specially:: --preserve-root and --no-preserve-root.
-* Special built-in utilities:: @command{break}, @command{:}, @command{eval}, @dots{}
-* Standards conformance:: Conformance to the @acronym{POSIX} standard.
+* Special built-in utilities:: @command{break}, @command{:}, @dots{}
+* Standards conformance:: Conformance to the POSIX standard.
+* Multi-call invocation:: Multi-call program invocation.
@end menu
@@ -668,16 +798,16 @@ Nearly every command invocation yields an integral @dfn{exit status}
that can be used to change how other commands work.
For the vast majority of commands, an exit status of zero indicates
success. Failure is indicated by a nonzero value---typically
-@samp{1}, though it may differ on unusual platforms as @acronym{POSIX}
+@samp{1}, though it may differ on unusual platforms as POSIX
requires only that it be nonzero.
However, some of the programs documented here do produce
other exit status values and a few associate different
meanings with the values @samp{0} and @samp{1}.
Here are some of the exceptions:
-@command{chroot}, @command{env}, @command{expr},
-@command{nice}, @command{nohup}, @command{printenv},
-@command{sort}, @command{su}, @command{test}, @command{tty}.
+@command{chroot}, @command{env}, @command{expr}, @command{nice},
+@command{nohup}, @command{numfmt}, @command{printenv}, @command{sort},
+@command{stdbuf}, @command{test}, @command{timeout}, @command{tty}.
@node Backup options
@@ -685,7 +815,7 @@ Here are some of the exceptions:
@cindex backup options
-Some @sc{gnu} programs (at least @command{cp}, @command{install},
+Some GNU programs (at least @command{cp}, @command{install},
@command{ln}, and @command{mv}) optionally make backups of files
before writing new versions.
These options control the details of these backups. The options are also
@@ -694,7 +824,7 @@ briefly mentioned in the descriptions of the particular programs.
@table @samp
@item -b
-@itemx @w{@kbd{--backup}[=@var{method}]}
+@itemx --backup[=@var{method}]
@opindex -b
@opindex --backup
@vindex VERSION_CONTROL
@@ -759,7 +889,7 @@ set, the default is @samp{~}, just as in Emacs.
@cindex block size
-Some @sc{gnu} programs (at least @command{df}, @command{du}, and
+Some GNU programs (at least @command{df}, @command{du}, and
@command{ls}) display sizes in ``blocks''. You can adjust the block size
and method of display to make sizes easier to read. The block size
used for display is independent of any file system block size.
@@ -814,10 +944,11 @@ A block size specification can be a positive integer specifying the number
of bytes per block, or it can be @code{human-readable} or @code{si} to
select a human-readable format. Integers may be followed by suffixes
that are upward compatible with the
-@uref{http://www.bipm.fr/enus/3_SI/si-prefixes.html, SI prefixes}
+@uref{http://www.bipm.org/en/publications/si-brochure/chapter3.html,
+SI prefixes}
for decimal multiples and with the
-@uref{http://physics.nist.gov/cuu/Units/binary.html, IEC 60027-2
-prefixes for binary multiples}.
+@uref{http://physics.nist.gov/cuu/Units/binary.html, ISO/IEC 80000-13
+(formerly IEC 60027-2) prefixes} for binary multiples.
With human-readable formats, output sizes are followed by a size letter
such as @samp{M} for megabytes. @code{BLOCK_SIZE=human-readable} uses
@@ -858,58 +989,56 @@ kilobyte: @math{10^3 = 1000}.
@itemx K
@itemx KiB
@cindex kibibyte, definition of
-kibibyte: @math{2^10 = 1024}. @samp{K} is special: the SI prefix is
-@samp{k} and the IEC 60027-2 prefix is @samp{Ki}, but tradition and
-@acronym{POSIX} use @samp{k} to mean @samp{KiB}.
+kibibyte: @math{2^{10} = 1024}. @samp{K} is special: the SI prefix is
+@samp{k} and the ISO/IEC 80000-13 prefix is @samp{Ki}, but tradition and
+POSIX use @samp{k} to mean @samp{KiB}.
@item MB
@cindex megabyte, definition of
megabyte: @math{10^6 = 1,000,000}.
@item M
@itemx MiB
@cindex mebibyte, definition of
-mebibyte: @math{2^20 = 1,048,576}.
+mebibyte: @math{2^{20} = 1,048,576}.
@item GB
@cindex gigabyte, definition of
gigabyte: @math{10^9 = 1,000,000,000}.
@item G
@itemx GiB
@cindex gibibyte, definition of
-gibibyte: @math{2^30 = 1,073,741,824}.
+gibibyte: @math{2^{30} = 1,073,741,824}.
@item TB
@cindex terabyte, definition of
-terabyte: @math{10^12 = 1,000,000,000,000}.
+terabyte: @math{10^{12} = 1,000,000,000,000}.
@item T
@itemx TiB
@cindex tebibyte, definition of
-tebibyte: @math{2^40 = 1,099,511,627,776}.
+tebibyte: @math{2^{40} = 1,099,511,627,776}.
@item PB
@cindex petabyte, definition of
-petabyte: @math{10^15 = 1,000,000,000,000,000}.
+petabyte: @math{10^{15} = 1,000,000,000,000,000}.
@item P
@itemx PiB
@cindex pebibyte, definition of
-pebibyte: @math{2^50 = 1,125,899,906,842,624}.
+pebibyte: @math{2^{50} = 1,125,899,906,842,624}.
@item EB
@cindex exabyte, definition of
-exabyte: @math{10^18 = 1,000,000,000,000,000,000}.
+exabyte: @math{10^{18} = 1,000,000,000,000,000,000}.
@item E
@itemx EiB
@cindex exbibyte, definition of
-exbibyte: @math{2^60 = 1,152,921,504,606,846,976}.
+exbibyte: @math{2^{60} = 1,152,921,504,606,846,976}.
@item ZB
@cindex zettabyte, definition of
-zettabyte: @math{10^21 = 1,000,000,000,000,000,000,000}
+zettabyte: @math{10^{21} = 1,000,000,000,000,000,000,000}
@item Z
@itemx ZiB
-@math{2^70 = 1,180,591,620,717,411,303,424}.
-(@samp{Zi} is a @acronym{GNU} extension to IEC 60027-2.)
+@math{2^{70} = 1,180,591,620,717,411,303,424}.
@item YB
@cindex yottabyte, definition of
-yottabyte: @math{10^24 = 1,000,000,000,000,000,000,000,000}.
+yottabyte: @math{10^{24} = 1,000,000,000,000,000,000,000,000}.
@item Y
@itemx YiB
-@math{2^80 = 1,208,925,819,614,629,174,706,176}.
-(@samp{Yi} is a @acronym{GNU} extension to IEC 60027-2.)
+@math{2^{80} = 1,208,925,819,614,629,174,706,176}.
@end table
@opindex -k
@@ -924,34 +1053,156 @@ option is equivalent to @option{--block-size=1K}, which
is the default unless the @env{POSIXLY_CORRECT} environment variable is
set. The @option{-h} or @option{--human-readable} option is equivalent to
@option{--block-size=human-readable}. The @option{--si} option is
-equivalent to @option{--block-size=si}.
+equivalent to @option{--block-size=si}. Note for @command{ls}
+the @option{-k} option does not control the display of the
+apparent file sizes, whereas the @option{--block-size} option does.
+
+@node Floating point
+@section Floating point numbers
+@cindex floating point
+@cindex IEEE floating point
+
+Commands that accept or produce floating point numbers employ the
+floating point representation of the underlying system, and suffer
+from rounding error, overflow, and similar floating-point issues.
+Almost all modern systems use IEEE-754 floating point, and it is
+typically portable to assume IEEE-754 behavior these days. IEEE-754
+has positive and negative infinity, distinguishes positive from
+negative zero, and uses special values called NaNs to represent
+invalid computations such as dividing zero by itself. For more
+information, please see David Goldberg's paper
+@uref{http://@/www.validlab.com/@/goldberg/@/paper.pdf, What Every
+Computer Scientist Should Know About Floating-Point Arithmetic}.
+
+@vindex LC_NUMERIC
+Commands that accept floating point numbers as options, operands or
+input use the standard C functions @code{strtod} and @code{strtold} to
+convert from text to floating point numbers. These floating point
+numbers therefore can use scientific notation like @code{1.0e-34} and
+@code{-10e100}. Commands that parse floating point also understand
+case-insensitive @code{inf}, @code{infinity}, and @code{NaN}, although
+whether such values are useful depends on the command in question.
+Modern C implementations also accept hexadecimal floating point
+numbers such as @code{-0x.ep-3}, which stands for @minus{}14/16 times
+@math{2^-3}, which equals @minus{}0.109375. The @env{LC_NUMERIC}
+locale determines the decimal-point character. @xref{Parsing of
+Floats,,, libc, The GNU C Library Reference Manual}.
+
+@node Signal specifications
+@section Signal specifications
+@cindex signals, specifying
+
+A @var{signal} may be a signal name like @samp{HUP}, or a signal
+number like @samp{1}, or an exit status of a process terminated by the
+signal. A signal name can be given in canonical form or prefixed by
+@samp{SIG}@. The case of the letters is ignored. The following signal names
+and numbers are supported on all POSIX compliant systems:
+
+@table @samp
+@item HUP
+1. Hangup.
+@item INT
+2. Terminal interrupt.
+@item QUIT
+3. Terminal quit.
+@item ABRT
+6. Process abort.
+@item KILL
+9. Kill (cannot be caught or ignored).
+@item ALRM
+14. Alarm Clock.
+@item TERM
+15. Termination.
+@end table
+
+@noindent
+Other supported signal names have system-dependent corresponding
+numbers. All systems conforming to POSIX 1003.1-2001 also
+support the following signals:
+
+@table @samp
+@item BUS
+Access to an undefined portion of a memory object.
+@item CHLD
+Child process terminated, stopped, or continued.
+@item CONT
+Continue executing, if stopped.
+@item FPE
+Erroneous arithmetic operation.
+@item ILL
+Illegal Instruction.
+@item PIPE
+Write on a pipe with no one to read it.
+@item SEGV
+Invalid memory reference.
+@item STOP
+Stop executing (cannot be caught or ignored).
+@item TSTP
+Terminal stop.
+@item TTIN
+Background process attempting read.
+@item TTOU
+Background process attempting write.
+@item URG
+High bandwidth data is available at a socket.
+@item USR1
+User-defined signal 1.
+@item USR2
+User-defined signal 2.
+@end table
+
+@noindent
+POSIX 1003.1-2001 systems that support the XSI extension
+also support the following signals:
+
+@table @samp
+@item POLL
+Pollable event.
+@item PROF
+Profiling timer expired.
+@item SYS
+Bad system call.
+@item TRAP
+Trace/breakpoint trap.
+@item VTALRM
+Virtual timer expired.
+@item XCPU
+CPU time limit exceeded.
+@item XFSZ
+File size limit exceeded.
+@end table
+
+@noindent
+POSIX 1003.1-2001 systems that support the XRT extension
+also support at least eight real-time signals called @samp{RTMIN},
+@samp{RTMIN+1}, @dots{}, @samp{RTMAX-1}, @samp{RTMAX}.
@node Disambiguating names and IDs
-@section chown and chgrp: Disambiguating user names and IDs
+@section chown, chgrp, chroot, id: Disambiguating user names and IDs
@cindex user names, disambiguating
@cindex user IDs, disambiguating
@cindex group names, disambiguating
@cindex group IDs, disambiguating
@cindex disambiguating group names and IDs
-Since the @var{owner} and @var{group} arguments to @command{chown} and
-@command{chgrp} may be specified as names or numeric IDs, there is an
+Since the @var{user} and @var{group} arguments to these commands
+may be specified as names or numeric IDs, there is an
apparent ambiguity.
What if a user or group @emph{name} is a string of digits?
@footnote{Using a number as a user name is common in some environments.}
-Should the command interpret it as a user name or as an ID?
-@acronym{POSIX} requires that @command{chown} and @command{chgrp}
+Should the command interpret it as a user name or as an ID@?
+POSIX requires that these commands
first attempt to resolve the specified string as a name, and
-only once that fails, then try to interpret it as an ID.
+only once that fails, then try to interpret it as an ID@.
This is troublesome when you want to specify a numeric ID, say 42,
and it must work even in a pathological situation where
@samp{42} is a user name that maps to some other user ID, say 1000.
Simply invoking @code{chown 42 F}, will set @file{F}s owner ID to
1000---not what you intended.
-GNU @command{chown} and @command{chgrp} provide a way to work around this,
-that at the same time may result in a significant performance improvement
-by eliminating a database look-up.
+GNU @command{chown}, @command{chgrp}, @command{chroot}, and @command{id}
+provide a way to work around this, that at the same time may result in a
+significant performance improvement by eliminating a database look-up.
Simply precede each numeric user ID and/or group ID with a @samp{+},
in order to force its interpretation as an integer:
@@ -961,8 +1212,7 @@ chgrp +$numeric_group_id another-file
chown +0:+0 /
@end example
-GNU @command{chown} and @command{chgrp}
-skip the name look-up process for each @samp{+}-prefixed string,
+The name look-up process is skipped for each @samp{+}-prefixed string,
because a string containing @samp{+} is never a valid user or group name.
This syntax is accepted on most common Unix systems, but not on Solaris 10.
@@ -976,12 +1226,19 @@ sometimes need random data to do their work. For example, @samp{sort
-R} must choose a hash function at random, and it needs random data to
make this selection.
-Normally these commands use the device file @file{/dev/urandom} as the
+By default these commands use an internal pseudo-random generator
+initialized by a small amount of entropy, but can be directed to use
+an external source with the @option{--random-source=@var{file}} option.
+An error is reported if @var{file} does not contain enough bytes.
+
+For example, the device file @file{/dev/urandom} could be used as the
source of random data. Typically, this device gathers environmental
noise from device drivers and other sources into an entropy pool, and
uses the pool to generate random bits. If the pool is short of data,
the device reuses the internal pool to produce more bits, using a
-cryptographically secure pseudorandom number generator.
+cryptographically secure pseudo-random number generator. But be aware
+that this device is not designed for bulk random data generation
+and is relatively slow.
@file{/dev/urandom} suffices for most practical uses, but applications
requiring high-value or long-term protection of private data may
@@ -989,20 +1246,24 @@ require an alternate data source like @file{/dev/random} or
@file{/dev/arandom}. The set of available sources depends on your
operating system.
-To use such a source, specify the @option{--random-source=@var{file}}
-option, e.g., @samp{shuf --random-source=/dev/random}. The contents
-of @var{file} should be as random as possible. An error is reported
-if @var{file} does not contain enough bytes to randomize the input
-adequately.
-
To reproduce the results of an earlier invocation of a command, you
can save some random data into a file and then use that file as the
random source in earlier and later invocations of the command.
+@cindex random seed
+Rather than depending on a file, one can generate a reproducible
+arbitrary amount of pseudo-random data given a seed value, using
+for example:
-Some old-fashioned or stripped-down operating systems lack support for
-@command{/dev/urandom}. On these systems commands like @command{shuf}
-by default fall back on an internal pseudorandom generator initialized
-by a small amount of entropy.
+@example
+get_seeded_random()
+@{
+ seed="$1"
+ openssl enc -aes-256-ctr -pass pass:"$seed" -nosalt \
+ </dev/zero 2>/dev/null
+@}
+
+shuf -i1-100 --random-source=<(get_seeded_random 42)
+@end example
@node Target directory
@section Target directory
@@ -1039,7 +1300,7 @@ treated as a directory and want a diagnostic otherwise, you can use
the @option{--target-directory} (@option{-t}) option.
@item -t @var{directory}
-@itemx @w{@kbd{--target-directory}=@var{directory}}
+@itemx --target-directory=@var{directory}
@opindex --target-directory
@cindex target directory
@cindex destination directory
@@ -1062,7 +1323,7 @@ invocation of the subject command. (It can be done by going through a
shell command, but that requires more human labor and brain power than
it should.)
-The @w{@kbd{--target-directory}} (@option{-t}) option allows the @command{cp},
+The @option{--target-directory} (@option{-t}) option allows the @command{cp},
@command{install}, @command{ln}, and @command{mv} programs to be used
conveniently with @command{xargs}. For example, you can move the files
from the current directory to a sibling directory, @code{d} like this:
@@ -1072,7 +1333,7 @@ ls | xargs mv -t ../d --
@end smallexample
However, this doesn't move files whose names begin with @samp{.}.
-If you use the @sc{gnu} @command{find} program, you can move those
+If you use the GNU @command{find} program, you can move those
files too, with this command:
@example
@@ -1084,7 +1345,7 @@ But both of the above approaches fail if there are no files in the
current directory, or if any file has a name containing a blank or
some other special characters.
The following example removes those limitations and requires both
-@sc{gnu} @command{find} and @sc{gnu} @command{xargs}:
+GNU @command{find} and GNU @command{xargs}:
@example
find . -mindepth 1 -maxdepth 1 -print0 \
@@ -1104,9 +1365,9 @@ options cannot be combined.
@cindex trailing slashes
-Some @sc{gnu} programs (at least @command{cp} and @command{mv}) allow you to
+Some GNU programs (at least @command{cp} and @command{mv}) allow you to
remove any trailing slashes from each @var{source} argument before
-operating on it. The @w{@kbd{--strip-trailing-slashes}} option enables
+operating on it. The @option{--strip-trailing-slashes} option enables
this behavior.
This is useful when a @var{source} argument may have a trailing slash and
@@ -1118,7 +1379,7 @@ option, @command{mv}, for example, (via the system's rename function) must
interpret a trailing slash as a request to dereference the symbolic link
and so must rename the indirectly referenced @emph{directory} and not
the symbolic link. Although it may seem surprising that such behavior
-be the default, it is required by @acronym{POSIX} and is consistent with
+be the default, it is required by POSIX and is consistent with
other parts of that standard.
@node Traversing symlinks
@@ -1127,7 +1388,7 @@ other parts of that standard.
@cindex symbolic link to directory, controlling traversal of
The following options modify how @command{chown} and @command{chgrp}
-@c FIXME: note that `du' has these options, too, but they have slightly
+@c FIXME: note that 'du' has these options, too, but they have slightly
@c different meaning.
traverse a hierarchy when the @option{--recursive} (@option{-R})
option is also specified.
@@ -1146,7 +1407,7 @@ a symlink or its referent.
@macro choptH
@item -H
@opindex -H
-@cindex symbolic link to directory, traverse each that is specified on the command line
+@cindex symbolic link to directory, traverse if on the command line
If @option{--recursive} (@option{-R}) is specified and
a command line argument is a symbolic link to a directory, traverse it.
@end macro
@@ -1175,18 +1436,18 @@ or @option{-P} is specified.
@node Treating / specially
-@section Treating / specially
+@section Treating @file{/} specially
Certain commands can operate destructively on entire hierarchies.
For example, if a user with appropriate privileges mistakenly runs
@samp{rm -rf / tmp/junk}, that may remove
all files on the entire system. Since there are so few
legitimate uses for such a command,
-@sc{gnu} @command{rm} normally declines to operate on any directory
+GNU @command{rm} normally declines to operate on any directory
that resolves to @file{/}. If you really want to try to remove all
the files on your system, you can use the @option{--no-preserve-root}
option, but the default behavior, specified by the
-@option{--preserve-option}, is safer for most purposes.
+@option{--preserve-root} option, is safer for most purposes.
The commands @command{chgrp}, @command{chmod} and @command{chown}
can also operate destructively on entire hierarchies, so they too
@@ -1194,7 +1455,7 @@ support these options. Although, unlike @command{rm}, they don't
actually unlink files, these commands are arguably more dangerous
when operating recursively on @file{/}, since they often work much
more quickly, and hence damage more files before an alert user can
-interrupt them. Tradition and @acronym{POSIX} require these commands
+interrupt them. Tradition and POSIX require these commands
to operate recursively on @file{/}, so they default to
@option{--no-preserve-root}, but using the @option{--preserve-root}
option makes them safer for most purposes. For convenience you can
@@ -1216,7 +1477,7 @@ well-defined behavior: it may generate an error message instead of
exiting.
Here is a list of the special built-in utilities that are standardized
-by @acronym{POSIX} 1003.1-2004.
+by POSIX 1003.1-2004.
@quotation
@t{.@: : break continue eval exec exit export readonly
@@ -1236,33 +1497,56 @@ generates an error message instead of suspending.
@section Standards conformance
@vindex POSIXLY_CORRECT
-In a few cases, the @sc{gnu} utilities' default behavior is
-incompatible with the @acronym{POSIX} standard. To suppress these
+In a few cases, the GNU utilities' default behavior is
+incompatible with the POSIX standard. To suppress these
incompatibilities, define the @env{POSIXLY_CORRECT} environment
-variable. Unless you are checking for @acronym{POSIX} conformance, you
+variable. Unless you are checking for POSIX conformance, you
probably do not need to define @env{POSIXLY_CORRECT}.
-Newer versions of @acronym{POSIX} are occasionally incompatible with older
-versions. For example, older versions of @acronym{POSIX} required the
+Newer versions of POSIX are occasionally incompatible with older
+versions. For example, older versions of POSIX required the
command @samp{sort +1} to sort based on the second and succeeding
-fields in each input line, but starting with @acronym{POSIX} 1003.1-2001
+fields in each input line, but starting with POSIX 1003.1-2001
the same command is required to sort the file named @file{+1}, and you
must instead use the command @samp{sort -k 2} to get the field-based
sort.
@vindex _POSIX2_VERSION
-The @sc{gnu} utilities normally conform to the version of @acronym{POSIX}
+The GNU utilities normally conform to the version of POSIX
that is standard for your system. To cause them to conform to a
-different version of @acronym{POSIX}, define the @env{_POSIX2_VERSION}
+different version of POSIX, define the @env{_POSIX2_VERSION}
environment variable to a value of the form @var{yyyymm} specifying
-the year and month the standard was adopted. Two values are currently
+the year and month the standard was adopted. Three values are currently
supported for @env{_POSIX2_VERSION}: @samp{199209} stands for
-@acronym{POSIX} 1003.2-1992, and @samp{200112} stands for @acronym{POSIX}
-1003.1-2001. For example, if you have a newer system but are running software
-that assumes an older version of @acronym{POSIX} and uses @samp{sort +1}
+POSIX 1003.2-1992, @samp{200112} stands for POSIX
+1003.1-2001, and @samp{200809} stands for POSIX 1003.1-2008.
+For example, if you have a newer system but are running software
+that assumes an older version of POSIX and uses @samp{sort +1}
or @samp{tail +10}, you can work around any compatibility problems by setting
@samp{_POSIX2_VERSION=199209} in your environment.
+@c This node is named "Multi-call invocation", not the usual
+@c "coreutils invocation", so that shell commands like
+@c 'info coreutils "touch invocation"' work as expected.
+@node Multi-call invocation
+@section @command{coreutils}: Multi-call program
+
+@pindex multicall
+@cindex combined
+@cindex calling combined multi-call program
+
+The @command{coreutils} command invokes an individual utility, either
+implicitly selected by the last component of the name used to invoke
+@command{coreutils}, or explicitly with the
+@option{--coreutils-prog} option. Synopsis:
+
+@example
+coreutils @option{--coreutils-prog=PROGRAM} @dots{}
+@end example
+
+The @command{coreutils} command is not installed by default, so
+portable scripts should not rely on its existence.
+
@node Output of entire files
@chapter Output of entire files
@@ -1277,6 +1561,7 @@ in some way.
* tac invocation:: Concatenate and write files in reverse.
* nl invocation:: Number lines and write files.
* od invocation:: Write files in octal or other formats.
+* base32 invocation:: Transform data into printable data.
* base64 invocation:: Transform data into printable data.
@end menu
@@ -1308,7 +1593,7 @@ Equivalent to @option{-vET}.
@itemx --number-nonblank
@opindex -b
@opindex --number-nonblank
-Number all nonblank output lines, starting with 1.
+Number all nonempty output lines, starting with 1.
@item -e
@opindex -e
@@ -1324,14 +1609,17 @@ Display a @samp{$} after the end of each line.
@itemx --number
@opindex -n
@opindex --number
-Number all output lines, starting with 1.
+Number all output lines, starting with 1. This option is ignored
+if @option{-b} is in effect.
@item -s
@itemx --squeeze-blank
@opindex -s
@opindex --squeeze-blank
+@cindex squeezing empty lines
@cindex squeezing blank lines
-Replace multiple adjacent blank lines with a single blank line.
+Suppress repeated adjacent blank lines; output just one empty line
+instead of several.
@item -t
@opindex -t
@@ -1345,7 +1633,7 @@ Display TAB characters as @samp{^I}.
@item -u
@opindex -u
-Ignored; for @acronym{POSIX} compatibility.
+Ignored; for POSIX compatibility.
@item -v
@itemx --show-nonprinting
@@ -1411,21 +1699,30 @@ precedes in the file.
@itemx --regex
@opindex -r
@opindex --regex
-Treat the separator string as a regular expression. Users of @command{tac}
-on MS-DOS/MS-Windows should note that, since @command{tac} reads files in
-binary mode, each line of a text file might end with a CR/LF pair
-instead of the Unix-style LF.
+Treat the separator string as a regular expression.
@item -s @var{separator}
@itemx --separator=@var{separator}
@opindex -s
@opindex --separator
Use @var{separator} as the record separator, instead of newline.
+Note an empty @var{separator} is treated as a zero byte.
+I.e., input and output items are delimited with ASCII NUL.
@end table
+On systems like MS-DOS that distinguish between text and binary files,
+@command{tac} reads and writes in binary mode.
+
@exitstatus
+Example:
+
+@example
+# Reverse a file character by character.
+tac -r -s 'x\|[^x]'
+@end example
+
@node nl invocation
@section @command{nl}: Number lines and write files
@@ -1525,9 +1822,9 @@ Analogous to @option{--body-numbering}.
Analogous to @option{--body-numbering}.
@item -i @var{number}
-@itemx --page-increment=@var{number}
+@itemx --line-increment=@var{number}
@opindex -i
-@opindex --page-increment
+@opindex --line-increment
Increment line numbers by @var{number} (default 1).
@item -l @var{number}
@@ -1606,7 +1903,8 @@ Synopses:
@smallexample
od [@var{option}]@dots{} [@var{file}]@dots{}
od [-abcdfilosx]@dots{} [@var{file}] [[+]@var{offset}[.][b]]
-od [@var{option}]@dots{} --traditional [@var{file}] [[+]@var{offset}[.][b] [[+]@var{label}[.][b]]]
+od [@var{option}]@dots{} --traditional [@var{file}]@c
+ [[+]@var{offset}[.][b] [[+]@var{label}[.][b]]]
@end smallexample
Each line of output consists of the offset in the input, followed by
@@ -1654,6 +1952,16 @@ none (do not print offsets).
The default is octal.
+@item --endian=@var{order}
+@opindex --endian
+@cindex byte-swapping
+@cindex endianness
+Reorder input bytes, to handle inputs with differing byte orders,
+or to provide consistent output independent of the endian convention
+of the current system. Swapping is performed according to the
+specified @option{--type} size and endian @var{order}, which can be
+@samp{little} or @samp{big}.
+
@item -j @var{bytes}
@itemx --skip-bytes=@var{bytes}
@opindex -j
@@ -1661,8 +1969,8 @@ The default is octal.
Skip @var{bytes} input bytes before formatting and writing. If
@var{bytes} begins with @samp{0x} or @samp{0X}, it is interpreted in
hexadecimal; otherwise, if it begins with @samp{0}, in octal; otherwise,
-in decimal. Appending @samp{b} multiplies @var{bytes} by 512, @samp{k}
-by 1024, and @samp{m} by 1048576.
+in decimal.
+@multiplierSuffixes{bytes}
@item -N @var{bytes}
@itemx --read-bytes=@var{bytes}
@@ -1671,16 +1979,18 @@ by 1024, and @samp{m} by 1048576.
Output at most @var{bytes} bytes of the input. Prefixes and suffixes on
@code{bytes} are interpreted as for the @option{-j} option.
-@item -S @var{n}
-@itemx --strings[=@var{n}]
+@item -S @var{bytes}
+@itemx --strings[=@var{bytes}]
@opindex -S
@opindex --strings
@cindex string constants, outputting
Instead of the normal output, output only @dfn{string constants}: at
-least @var{n} consecutive @acronym{ASCII} graphic characters,
-followed by a null (zero) byte.
+least @var{bytes} consecutive ASCII graphic characters,
+followed by a zero byte (ASCII NUL).
+Prefixes and suffixes on @var{bytes} are interpreted as for the
+@option{-j} option.
-If @var{n} is omitted with @option{--strings}, the default is 3.
+If @var{bytes} is omitted with @option{--strings}, the default is 3.
@item -t @var{type}
@itemx --format=@var{type}
@@ -1694,18 +2004,19 @@ of each output line using each of the data types that you specified,
in the order that you specified.
Adding a trailing ``z'' to any type specification appends a display
-of the @acronym{ASCII} character representation of the printable characters
+of the single byte character representation of the printable characters
to the output line generated by the type specification.
@table @samp
@item a
named character, ignoring high-order bit
@item c
-@acronym{ASCII} character or backslash escape,
+printable single byte character, C backslash escape
+or a 3 digit octal sequence
@item d
signed decimal
@item f
-floating point
+floating point (@pxref{Floating point})
@item o
octal
@item u
@@ -1715,7 +2026,7 @@ hexadecimal
@end table
The type @code{a} outputs things like @samp{sp} for space, @samp{nl} for
-newline, and @samp{nul} for a null (zero) byte. Only the least significant
+newline, and @samp{nul} for a zero byte. Only the least significant
seven bits of each byte is used; the high-order bit is ignored.
Type @code{c} outputs
@samp{ }, @samp{\n}, and @code{\0}, respectively.
@@ -1774,7 +2085,7 @@ omitted, the default is 32.
@end table
The next several options are shorthands for format specifications.
-@sc{gnu} @command{od} accepts any combination of shorthands and format
+GNU @command{od} accepts any combination of shorthands and format
specification options. These options accumulate.
@table @samp
@@ -1789,8 +2100,8 @@ Output as octal bytes. Equivalent to @samp{-t o1}.
@item -c
@opindex -c
-Output as @acronym{ASCII} characters or backslash escapes. Equivalent to
-@samp{-t c}.
+Output as printable single byte characters, C backslash escapes
+or 3 digit octal sequences. Equivalent to @samp{-t c}.
@item -d
@opindex -d
@@ -1841,16 +2152,29 @@ address.
@exitstatus
+
+@node base32 invocation
+@section @command{base32}: Transform data into printable data
+
+@pindex base32
+@cindex base32 encoding
+
+@command{base32} transforms data read from a file, or standard input,
+into (or from) base32 encoded form. The base32 encoded form uses
+printable ASCII characters to represent binary data.
+The usage and options of this command are precisely the
+same as for @command{base64}. @xref{base64 invocation}.
+
+
@node base64 invocation
-@section @command{base64}: Transform data into printable data.
+@section @command{base64}: Transform data into printable data
@pindex base64
@cindex base64 encoding
@command{base64} transforms data read from a file, or standard input,
into (or from) base64 encoded form. The base64 encoded form uses
-printable @acronym{ASCII} characters to represent binary data, see
-@uref{ftp://ftp.rfc-editor.org/in-notes/rfc3548.txt, RFC 3548}.
+printable ASCII characters to represent binary data.
Synopses:
@smallexample
@@ -1859,18 +2183,21 @@ base64 --decode [@var{option}]@dots{} [@var{file}]
@end smallexample
The base64 encoding expands data to roughly 133% of the original.
+The base32 encoding expands data to roughly 160% of the original.
+The format conforms to
+@uref{ftp://ftp.rfc-editor.org/in-notes/rfc4648.txt, RFC 4648}.
The program accepts the following options. Also see @ref{Common options}.
@table @samp
-@item -w @var{COLS}
-@itemx --wrap=@var{COLS}
+@item -w @var{cols}
+@itemx --wrap=@var{cols}
@opindex -w
@opindex --wrap
@cindex wrap data
@cindex column to wrap data after
-During encoding, wrap lines after @var{COLS} characters. This must be
+During encoding, wrap lines after @var{cols} characters. This must be
a positive number.
The default is to wrap after 76 characters. Use the value 0 to
@@ -1996,9 +2323,15 @@ between sentences to two spaces.
@opindex -@var{width}
@opindex -w
@opindex --width
-Fill output lines up to @var{width} characters (default 75). @command{fmt}
-initially tries to make lines about 7% shorter than this, to give it
-room to balance line lengths.
+Fill output lines up to @var{width} characters (default 75 or @var{goal}
+plus 10, if @var{goal} is provided).
+
+@item -g @var{goal}
+@itemx --goal=@var{goal}
+@opindex -g
+@opindex --goal
+@command{fmt} initially tries to make lines @var{goal} characters wide.
+By default, this is 7% shorter than @var{width}.
@item -p @var{prefix}
@itemx --prefix=@var{prefix}
@@ -2012,7 +2345,6 @@ leaving the code unchanged.
@exitstatus
-
@node pr invocation
@section @command{pr}: Paginate or columnate files for printing
@@ -2034,11 +2366,9 @@ pr [@var{option}]@dots{} [@var{file}]@dots{}
By default, a 5-line header is printed at each page: two blank lines;
a line with the date, the file name, and the page count; and two more
blank lines. A footer of five blank lines is also printed.
-With the @option{-F}
-option, a 3-line header is printed: the leading two blank lines are
-omitted; no footer is used. The default @var{page_length} in both cases is 66
-lines. The default number of text lines changes from 56 (without @option{-F})
-to 63 (with @option{-F}). The text line of the header takes the form
+The default @var{page_length} is 66
+lines. The default number of text lines is therefore 56.
+The text line of the header takes the form
@samp{@var{date} @var{string} @var{page}}, with spaces inserted around
@var{string} so that the line takes up the full @var{page_width}. Here,
@var{date} is the date (see the @option{-D} or @option{--date-format}
@@ -2058,44 +2388,14 @@ For single
column output no line truncation occurs by default. Use @option{-W} option to
truncate lines in that case.
-The following changes were made in version 1.22i and apply to later
-versions of @command{pr}:
-@c FIXME: this whole section here sounds very awkward to me. I
-@c made a few small changes, but really it all needs to be redone. - Brian
-@c OK, I fixed another sentence or two, but some of it I just don't understand.
-@ - Brian
-@itemize @bullet
-
-@item
-Some small @var{letter options} (@option{-s}, @option{-w}) have been
-redefined for better @acronym{POSIX} compliance. The output of some further
-cases has been adapted to other Unix systems. These changes are not
-compatible with earlier versions of the program.
-
-@item
-Some @var{new capital letter} options (@option{-J}, @option{-S}, @option{-W})
-have been introduced to turn off unexpected interferences of small letter
-options. The @option{-N} option and the second argument @var{last_page}
-of @samp{+FIRST_PAGE} offer more flexibility. The detailed handling of
-form feeds set in the input files requires the @option{-T} option.
-
-@item
-Capital letter options override small letter ones.
-
-@item
-Some of the option-arguments (compare @option{-s}, @option{-e},
-@option{-i}, @option{-n}) cannot be specified as separate arguments from the
-preceding option letter (already stated in the @acronym{POSIX} specification).
-@end itemize
-
The program accepts the following options. Also see @ref{Common options}.
@table @samp
@item +@var{first_page}[:@var{last_page}]
@itemx --pages=@var{first_page}[:@var{last_page}]
-@c The two following @opindex lines evoke warnings because they contain `:'
-@c The `info' spec does not permit that. If we use those lines, we end
+@c The two following @opindex lines evoke warnings because they contain ':'
+@c The 'info' spec does not permit that. If we use those lines, we end
@c up with truncated index entries that don't work.
@c @opindex +@var{first_page}[:@var{last_page}]
@c @opindex --pages=@var{first_page}[:@var{last_page}]
@@ -2155,7 +2455,7 @@ Double space the output.
@cindex time formats
@cindex formatting times
Format header dates using @var{format}, using the same conventions as
-for the command @samp{date +@var{format}}; @xref{date invocation}.
+for the command @samp{date +@var{format}}. @xref{date invocation}.
Except for directives, which start with
@samp{%}, characters in @var{format} are printed unchanged. You can use
this option to specify an arbitrary string in place of the header date,
@@ -2163,10 +2463,10 @@ e.g., @option{--date-format="Monday morning"}.
@vindex POSIXLY_CORRECT
@vindex LC_TIME
-Normally the date
-format defaults to @samp{%Y-%m-%d %H:%M} (for example, @samp{2001-12-04
-23:59}); but if the @env{POSIXLY_CORRECT} environment variable is set
-and the @env{LC_TIME} locale category specifies the @acronym{POSIX}
+The default date format is @samp{%Y-%m-%d %H:%M} (for example,
+@samp{2001-12-04 23:59});
+but if the @env{POSIXLY_CORRECT} environment variable is set
+and the @env{LC_TIME} locale category specifies the POSIX
locale, the default is @samp{%b %e %H:%M %Y} (for example,
@samp{Dec@ @ 4 23:59 2001}.
@@ -2174,7 +2474,7 @@ locale, the default is @samp{%b %e %H:%M %Y} (for example,
Time stamps are listed according to the time zone rules specified by
the @env{TZ} environment variable, or by the system default rules if
@env{TZ} is not set. @xref{TZ Variable,, Specifying the Time Zone
-with @env{TZ}, libc, The GNU C Library}.
+with @env{TZ}, libc, The GNU C Library Reference Manual}.
@item -e[@var{in-tabchar}[@var{in-tabwidth}]]
@itemx --expand-tabs[=@var{in-tabchar}[@var{in-tabwidth}]]
@@ -2192,12 +2492,11 @@ is 8).
@opindex -F
@opindex -f
@opindex --form-feed
-Use a form feed instead of newlines to separate output pages. The default
-page length of 66 lines is not altered. But the number of lines of text
-per page changes from default 56 to 63 lines.
+Use a form feed instead of newlines to separate output pages. This does
+not alter the default page length of 66 lines.
-@item -h @var{HEADER}
-@itemx --header=@var{HEADER}
+@item -h @var{header}
+@itemx --header=@var{header}
@opindex -h
@opindex --header
Replace the file name in the header with the centered string @var{header}.
@@ -2224,7 +2523,7 @@ Merge lines of full length. Used together with the column options
no column alignment used; may be used with
@option{--sep-string[=@var{string}]}. @option{-J} has been introduced
(together with @option{-W} and @option{--sep-string})
-to disentangle the old (@acronym{POSIX}-compliant) options @option{-w} and
+to disentangle the old (POSIX-compliant) options @option{-w} and
@option{-s} along with the three column options.
@@ -2234,9 +2533,8 @@ to disentangle the old (@acronym{POSIX}-compliant) options @option{-w} and
@opindex --length
Set the page length to @var{page_length} (default 66) lines, including
the lines of the header [and the footer]. If @var{page_length} is less
-than or equal to 10 (or <= 3 with @option{-F}), the header and footer are
-omitted, and all form feeds set in input files are eliminated, as if
-the @option{-T} option had been given.
+than or equal to 10, the header and footer are omitted, as if the
+@option{-t} option had been given.
@item -m
@itemx --merge
@@ -2268,14 +2566,14 @@ first line of the input file (not the first line printed, compare the
Optional argument @var{number-separator} is the character appended to
the line number to separate it from the text followed. The default
separator is the TAB character. In a strict sense a TAB is always
-printed with single column output only. The @var{TAB}-width varies
-with the @var{TAB}-position, e.g., with the left @var{margin} specified
+printed with single column output only. The TAB width varies
+with the TAB position, e.g., with the left @var{margin} specified
by @option{-o} option. With multicolumn output priority is given to
-@samp{equal width of output columns} (a @acronym{POSIX} specification).
-The @var{TAB}-width is fixed to the value of the first column and does
+@samp{equal width of output columns} (a POSIX specification).
+The TAB width is fixed to the value of the first column and does
not change with different values of left @var{margin}. That means a
fixed number of spaces is always printed in the place of the
-@var{number-separator tab}. The tabification depends upon the output
+@var{number-separator} TAB@. The tabification depends upon the output
position.
@item -N @var{line_number}
@@ -2312,10 +2610,10 @@ Separate columns by a single character @var{char}. The default for
character} with @option{-w}. Without @option{-s} the default separator
@samp{space} is set. @option{-s[char]} turns off line truncation of all
three column options (@option{-COLUMN}|@option{-a -COLUMN}|@option{-m}) unless
-@option{-w} is set. This is a @acronym{POSIX}-compliant formulation.
+@option{-w} is set. This is a POSIX-compliant formulation.
-@item -S@var{string}
+@item -S[@var{string}]
@itemx --sep-string[=@var{string}]
@opindex -S
@opindex --sep-string
@@ -2325,8 +2623,8 @@ does not affect line truncation or column alignment.
Without @option{-S}, and with @option{-J}, @command{pr} uses the default output
separator, TAB@.
Without @option{-S} or @option{-J}, @command{pr} uses a @samp{space}
-(same as @option{-S"@w{ }"}). @option{--sep-string} with no
-@samp{=@var{string}} is equivalent to @option{--sep-string=""}.
+(same as @option{-S"@w{ }"}).
+If no @samp{@var{string}} argument is specified, @samp{""} is assumed.
@item -t
@itemx --omit-header
@@ -2358,25 +2656,28 @@ Print nonprinting characters in octal backslash notation.
@opindex -w
@opindex --width
Set page width to @var{page_width} characters for multiple text-column
-output only (default for @var{page_width} is 72). @option{-s[CHAR]} turns
-off the default page width and any line truncation and column alignment.
+output only (default for @var{page_width} is 72). The specified
+@var{page_width} is rounded down so that columns have equal width.
+@option{-s[CHAR]} turns off the default page width and any line truncation
+and column alignment.
Lines of full length are merged, regardless of the column options
set. No @var{page_width} setting is possible with single column output.
-A @acronym{POSIX}-compliant formulation.
+A POSIX-compliant formulation.
@item -W @var{page_width}
@itemx --page_width=@var{page_width}
@opindex -W
@opindex --page_width
-Set the page width to @var{page_width} characters. That's valid with and
-without a column option. Text lines are truncated, unless @option{-J}
-is used. Together with one of the three column options
+Set the page width to @var{page_width} characters, honored with and
+without a column option. With a column option, the specified @var{page_width}
+is rounded down so that columns have equal width. Text lines are truncated,
+unless @option{-J} is used. Together with one of the three column options
(@option{-@var{column}}, @option{-a -@var{column}} or @option{-m}) column
alignment is always used. The separator options @option{-S} or @option{-s}
-don't affect the @option{-W} option. Default is 72 characters. Without
+don't disable the @option{-W} option. Default is 72 characters. Without
@option{-W @var{page_width}} and without any of the column options NO line
truncation is used (defined to keep downward compatibility and to meet
-most frequent tasks). That's equivalent to @option{-W 72 -J}. The header
+most frequent tasks). That's equivalent to @option{-W 72 -J}@. The header
line is never truncated.
@end table
@@ -2453,7 +2754,7 @@ These commands output pieces of the input.
@menu
* head invocation:: Output the first part of files.
* tail invocation:: Output the last part of files.
-* split invocation:: Split a file into fixed-size pieces.
+* split invocation:: Split a file into pieces.
* csplit invocation:: Split a file into context-determined pieces.
@end menu
@@ -2486,23 +2787,23 @@ The program accepts the following options. Also see @ref{Common options}.
@table @samp
-@item -c @var{n}
-@itemx --bytes=@var{n}
+@item -c [-]@var{num}
+@itemx --bytes=[-]@var{num}
@opindex -c
@opindex --bytes
-Print the first @var{n} bytes, instead of initial lines. Appending
-@samp{b} multiplies @var{n} by 512, @samp{k} by 1024, and @samp{m}
-by 1048576.
-However, if @var{n} starts with a @samp{-},
-print all but the last @var{n} bytes of each file.
-
-@itemx -n @var{n}
-@itemx --lines=@var{n}
+Print the first @var{num} bytes, instead of initial lines.
+However, if @var{num} is prefixed with a @samp{-},
+print all but the last @var{num} bytes of each file.
+@multiplierSuffixes{num}
+
+@item -n [-]@var{num}
+@itemx --lines=[-]@var{num}
@opindex -n
@opindex --lines
-Output the first @var{n} lines.
-However, if @var{n} starts with a @samp{-},
-print all but the last @var{n} lines of each file.
+Output the first @var{num} lines.
+However, if @var{num} is prefixed with a @samp{-},
+print all but the last @var{num} lines of each file.
+Size multiplier suffixes are the same as with the @option{-c} option.
@item -q
@itemx --quiet
@@ -2518,15 +2819,17 @@ Never print file name headers.
@opindex --verbose
Always print file name headers.
+@optZeroTerminated
+
@end table
For compatibility @command{head} also supports an obsolete option syntax
-@option{-@var{count}@var{options}}, which is recognized only if it is
-specified first. @var{count} is a decimal number optionally followed
+@option{-[@var{num}][bkm][cqv]}, which is recognized only if it is
+specified first. @var{num} is a decimal number optionally followed
by a size letter (@samp{b}, @samp{k}, @samp{m}) as in @option{-c}, or
@samp{l} to mean count by lines, or other option letters (@samp{cqv}).
-Scripts intended for standard hosts should use @option{-c @var{count}}
-or @option{-n @var{count}} instead. If your script must also run on
+Scripts intended for standard hosts should use @option{-c @var{num}}
+or @option{-n @var{num}} instead. If your script must also run on
hosts that support only the obsolete syntax, it is usually simpler to
avoid @command{head}, e.g., by using @samp{sed 5q} instead of
@samp{head -5}.
@@ -2549,39 +2852,44 @@ tail [@var{option}]@dots{} [@var{file}]@dots{}
@end example
If more than one @var{file} is specified, @command{tail} prints a
-one-line header consisting of:
+one-line header before the output for each @var{file}, consisting of:
@example
==> @var{file name} <==
@end example
-@noindent
-before the output for each @var{file}.
+For further processing of tail output, it can be useful to convert the
+file headers to line prefixes, which can be done like:
+
+@example
+tail @dots{} |
+awk '
+ /^==> .* <==$/ @{prefix=substr($0,5,length-8)":"; next@}
+ @{print prefix$0@}
+' | @dots{}
+@end example
@cindex BSD @command{tail}
-@sc{gnu} @command{tail} can output any amount of data (some other versions of
+GNU @command{tail} can output any amount of data (some other versions of
@command{tail} cannot). It also has no @option{-r} option (print in
reverse), since reversing a file is really a different job from printing
the end of a file; BSD @command{tail} (which is the one with @option{-r}) can
only reverse files that are at most as large as its buffer, which is
typically 32 KiB@. A more reliable and versatile way to reverse files is
-the @sc{gnu} @command{tac} command.
-
-If any option-argument is a number @var{n} starting with a @samp{+},
-@command{tail} begins printing with the @var{n}th item from the start of
-each file, instead of from the end.
+the GNU @command{tac} command.
The program accepts the following options. Also see @ref{Common options}.
@table @samp
-@item -c @var{bytes}
-@itemx --bytes=@var{bytes}
+@item -c [+]@var{num}
+@itemx --bytes=[+]@var{num}
@opindex -c
@opindex --bytes
-Output the last @var{bytes} bytes, instead of final lines. Appending
-@samp{b} multiplies @var{bytes} by 512, @samp{k} by 1024, and @samp{m}
-by 1048576.
+Output the last @var{num} bytes, instead of final lines.
+However, if @var{num} is prefixed with a @samp{+}, start printing with
+byte @var{num} from the start of each file, instead of from the end.
+@multiplierSuffixes{num}
@item -f
@itemx --follow[=@var{how}]
@@ -2603,8 +2911,10 @@ If you'd like to continue to track the end of a growing file even after
it has been unlinked, use @option{--follow=descriptor}. This is the default
behavior, but it is not useful if you're tracking a log file that may be
rotated (removed or renamed, then reopened). In that case, use
-@option{--follow=name} to track the named file by reopening it periodically
-to see if it has been removed and recreated by some other program.
+@option{--follow=name} to track the named file, perhaps by reopening it
+periodically to see if it has been removed and recreated by some other program.
+Note that the inotify-based implementation handles this case without
+the need for any periodic reopening.
No matter which method you use, if the tracked file is determined to have
shrunk, @command{tail} prints a message saying the file has been truncated
@@ -2623,9 +2933,22 @@ growing.
The option values @samp{descriptor} and @samp{name} may be specified only
with the long form of the option, not with @option{-f}.
-@vindex POSIXLY_CORRECT
-If @env{POSIXLY_CORRECT} is set, the @option{-f} option is ignored if
+The @option{-f} option is ignored if
no @var{file} operand is specified and standard input is a FIFO or a pipe.
+Likewise, the @option{-f} option has no effect for any
+operand specified as @samp{-}, when standard input is a FIFO or a pipe.
+
+With kernel inotify support, output is triggered by file changes
+and is generally very prompt.
+Otherwise, @command{tail} sleeps for one second between checks---
+use @option{--sleep-interval=@var{n}} to change that default---which can
+make the output appear slightly less responsive or bursty.
+When using tail without inotify support, you can make it more responsive
+by using a sub-second sleep interval, e.g., via an alias like this:
+
+@example
+alias tail='tail -s.1'
+@end example
@item -F
@opindex -F
@@ -2633,25 +2956,29 @@ This option is the same as @option{--follow=name --retry}. That is, tail
will attempt to reopen a file when it is removed. Should this fail, tail
will keep trying until it becomes accessible again.
-@itemx --retry
-@opindex --retry
-This option is useful mainly when following by name (i.e., with
-@option{--follow=name}).
-Without this option, when tail encounters a file that doesn't
-exist or is otherwise inaccessible, it reports that fact and
-never checks it again.
+@item --max-unchanged-stats=@var{n}
+@opindex --max-unchanged-stats
+When tailing a file by name, if there have been @var{n} (default
+n=@value{DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS}) consecutive
+iterations for which the file has not changed, then
+@code{open}/@code{fstat} the file to determine if that file name is
+still associated with the same device/inode-number pair as before.
+When following a log file that is rotated, this is approximately the
+number of seconds between when tail prints the last pre-rotation lines
+and when it prints the lines that have accumulated in the new log file.
+This option is meaningful only when polling (i.e., without inotify)
+and when following by name.
-@itemx --sleep-interval=@var{number}
-@opindex --sleep-interval
-Change the number of seconds to wait between iterations (the default is 1.0).
-During one iteration, every specified file is checked to see if it has
-changed size.
-Historical implementations of @command{tail} have required that
-@var{number} be an integer. However, GNU @command{tail} accepts
-an arbitrary floating point number (using a period before any
-fractional digits).
+@item -n [+]@var{num}
+@itemx --lines=[+]@var{}
+@opindex -n
+@opindex --lines
+Output the last @var{num} lines.
+However, if @var{num} is prefixed with a @samp{+}, start printing with
+line @var{num} from the start of each file, instead of from the end.
+Size multiplier suffixes are the same as with the @option{-c} option.
-@itemx --pid=@var{pid}
+@item --pid=@var{pid}
@opindex --pid
When following by name or by descriptor, you may specify the process ID,
@var{pid}, of the sole writer of all @var{file} arguments. Then, shortly
@@ -2674,24 +3001,6 @@ terminate until long after the real writer has terminated.
Note that @option{--pid} cannot be supported on some systems; @command{tail}
will print a warning if this is the case.
-@itemx --max-unchanged-stats=@var{n}
-@opindex --max-unchanged-stats
-When tailing a file by name, if there have been @var{n} (default
-n=@value{DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS}) consecutive
-iterations for which the file has not changed, then
-@code{open}/@code{fstat} the file to determine if that file name is
-still associated with the same device/inode-number pair as before.
-When following a log file that is rotated, this is approximately the
-number of seconds between when tail prints the last pre-rotation lines
-and when it prints the lines that have accumulated in the new log file.
-This option is meaningful only when following by name.
-
-@itemx -n @var{n}
-@itemx --lines=@var{n}
-@opindex -n
-@opindex --lines
-Output the last @var{n} lines.
-
@item -q
@itemx --quiet
@itemx --silent
@@ -2700,19 +3009,52 @@ Output the last @var{n} lines.
@opindex --silent
Never print file name headers.
+@item --retry
+@opindex --retry
+Indefinitely try to open the specified file.
+This option is useful mainly when following (and otherwise issues a warning).
+
+When following by file descriptor (i.e., with @option{--follow=descriptor}),
+this option only affects the initial open of the file, as after a successful
+open, @command{tail} will start following the file descriptor.
+
+When following by name (i.e., with @option{--follow=name}), @command{tail}
+infinitely retries to re-open the given files until killed.
+
+Without this option, when @command{tail} encounters a file that doesn't
+exist or is otherwise inaccessible, it reports that fact and
+never checks it again.
+
+@item -s @var{number}
+@itemx --sleep-interval=@var{number}
+@opindex -s
+@opindex --sleep-interval
+Change the number of seconds to wait between iterations (the default is 1.0).
+During one iteration, every specified file is checked to see if it has
+changed size.
+Historical implementations of @command{tail} have required that
+@var{number} be an integer. However, GNU @command{tail} accepts
+an arbitrary floating point number. @xref{Floating point}.
+When @command{tail} uses inotify, this polling-related option
+is usually ignored. However, if you also specify @option{--pid=@var{p}},
+@command{tail} checks whether process @var{p} is alive at least
+every @var{number} seconds.
+
@item -v
@itemx --verbose
@opindex -v
@opindex --verbose
Always print file name headers.
+@optZeroTerminated
+
@end table
For compatibility @command{tail} also supports an obsolete usage
-@samp{tail -[@var{count}][bcl][f] [@var{file}]}, which is recognized
+@samp{tail -[@var{num}][bcl][f] [@var{file}]}, which is recognized
only if it does not conflict with the usage described
above. This obsolete form uses exactly one option and at most one
-file. In the option, @var{count} is an optional decimal number optionally
+file. In the option, @var{num} is an optional decimal number optionally
followed by a size letter (@samp{b}, @samp{c}, @samp{l}) to mean count
by 512-byte blocks, bytes, or lines, optionally followed by @samp{f}
which has the same meaning as @option{-f}.
@@ -2726,8 +3068,8 @@ This obsolete behavior can be enabled or disabled with the
conformance}).
Scripts intended for use on standard hosts should avoid obsolete
-syntax and should use @option{-c @var{count}[b]}, @option{-n
-@var{count}}, and/or @option{-f} instead. If your script must also
+syntax and should use @option{-c @var{num}[b]}, @option{-n
+@var{num}}, and/or @option{-f} instead. If your script must also
run on hosts that support only the obsolete syntax, you can often
rewrite it to avoid problematic usages, e.g., by using @samp{sed -n
'$p'} rather than @samp{tail -1}. If that's not possible, the script
@@ -2735,7 +3077,7 @@ can use a test like @samp{if tail -c +1 </dev/null >/dev/null 2>&1;
then @dots{}} to decide which syntax to use.
Even if your script assumes the standard behavior, you should still
-beware usages whose behaviors differ depending on the @acronym{POSIX}
+beware usages whose behaviors differ depending on the POSIX
version. For example, avoid @samp{tail - main.c}, since it might be
interpreted as either @samp{tail main.c} or as @samp{tail -- -
main.c}; avoid @samp{tail -c 4}, since it might mean either @samp{tail
@@ -2746,15 +3088,15 @@ mean either @samp{tail ./+4} or @samp{tail -n +4}.
@node split invocation
-@section @command{split}: Split a file into fixed-size pieces
+@section @command{split}: Split a file into pieces.
@pindex split
@cindex splitting a file into pieces
@cindex pieces, splitting a file into
-@command{split} creates output files containing consecutive sections of
-@var{input} (standard input if none is given or @var{input} is
-@samp{-}). Synopsis:
+@command{split} creates output files containing consecutive or interleaved
+sections of @var{input} (standard input if none is given or @var{input}
+is @samp{-}). Synopsis:
@example
split [@var{option}] [@var{input} [@var{prefix}]]
@@ -2767,64 +3109,232 @@ left over for the last section), into each output file.
The output files' names consist of @var{prefix} (@samp{x} by default)
followed by a group of characters (@samp{aa}, @samp{ab}, @dots{} by
default), such that concatenating the output files in traditional
-sorted order by file name produces
-the original input file. If the output file names are exhausted,
-@command{split} reports an error without deleting the output files
-that it did create.
+sorted order by file name produces the original input file (except
+@option{-nr/@var{n}}). By default split will initially create files
+with two generated suffix characters, and will increase this width by two
+when the next most significant position reaches the last character.
+(@samp{yz}, @samp{zaaa}, @samp{zaab}, @dots{}). In this way an arbitrary
+number of output files are supported, which sort as described above,
+even in the presence of an @option{--additional-suffix} option.
+If the @option{-a} option is specified and the output file names are
+exhausted, @command{split} reports an error without deleting the
+output files that it did create.
The program accepts the following options. Also see @ref{Common options}.
@table @samp
-@item -a @var{length}
-@itemx --suffix-length=@var{length}
-@opindex -a
-@opindex --suffix-length
-Use suffixes of length @var{length}. The default @var{length} is 2.
-
@item -l @var{lines}
@itemx --lines=@var{lines}
@opindex -l
@opindex --lines
Put @var{lines} lines of @var{input} into each output file.
+If @option{--separator} is specified, then @var{lines} determines
+the number of records.
For compatibility @command{split} also supports an obsolete
-option syntax @option{-@var{lines}}. New scripts should use @option{-l
-@var{lines}} instead.
+option syntax @option{-@var{lines}}. New scripts should use
+@option{-l @var{lines}} instead.
-@item -b @var{bytes}
-@itemx --bytes=@var{bytes}
+@item -b @var{size}
+@itemx --bytes=@var{size}
@opindex -b
@opindex --bytes
-Put the first @var{bytes} bytes of @var{input} into each output file.
-Appending @samp{b} multiplies @var{bytes} by 512, @samp{k} by 1024, and
-@samp{m} by 1048576.
+Put @var{size} bytes of @var{input} into each output file.
+@multiplierSuffixes{size}
-@item -C @var{bytes}
-@itemx --line-bytes=@var{bytes}
+@item -C @var{size}
+@itemx --line-bytes=@var{size}
@opindex -C
@opindex --line-bytes
Put into each output file as many complete lines of @var{input} as
-possible without exceeding @var{bytes} bytes. For lines longer than
-@var{bytes} bytes, put @var{bytes} bytes into each output file until
-less than @var{bytes} bytes of the line are left, then continue
-normally. @var{bytes} has the same format as for the @option{--bytes}
-option.
+possible without exceeding @var{size} bytes. Individual lines or records
+longer than @var{size} bytes are broken into multiple files.
+@var{size} has the same format as for the @option{--bytes} option.
+If @option{--separator} is specified, then @var{lines} determines
+the number of records.
+
+@item --filter=@var{command}
+@opindex --filter
+With this option, rather than simply writing to each output file,
+write through a pipe to the specified shell @var{command} for each output file.
+@var{command} should use the $FILE environment variable, which is set
+to a different output file name for each invocation of the command.
+For example, imagine that you have a 1TiB compressed file
+that, if uncompressed, would be too large to reside on disk,
+yet you must split it into individually-compressed pieces
+of a more manageable size.
+To do that, you might run this command:
+
+@example
+xz -dc BIG.xz | split -b200G --filter='xz > $FILE.xz' - big-
+@end example
+
+Assuming a 10:1 compression ratio, that would create about fifty 20GiB files
+with names @file{big-aa.xz}, @file{big-ab.xz}, @file{big-ac.xz}, etc.
+
+@item -n @var{chunks}
+@itemx --number=@var{chunks}
+@opindex -n
+@opindex --number
+
+Split @var{input} to @var{chunks} output files where @var{chunks} may be:
+
+@example
+@var{n} generate @var{n} files based on current size of @var{input}
+@var{k}/@var{n} only output @var{k}th of @var{n} to stdout
+l/@var{n} generate @var{n} files without splitting lines or records
+l/@var{k}/@var{n} likewise but only output @var{k}th of @var{n} to stdout
+r/@var{n} like @samp{l} but use round robin distribution
+r/@var{k}/@var{n} likewise but only output @var{k}th of @var{n} to stdout
+@end example
+
+Any excess bytes remaining after dividing the @var{input}
+into @var{n} chunks, are assigned to the last chunk.
+Any excess bytes appearing after the initial calculation are discarded
+(except when using @samp{r} mode).
+
+All @var{n} files are created even if there are fewer than @var{n} lines,
+or the @var{input} is truncated.
+
+For @samp{l} mode, chunks are approximately @var{input} size / @var{n}.
+The @var{input} is partitioned into @var{n} equal sized portions, with
+the last assigned any excess. If a line @emph{starts} within a partition
+it is written completely to the corresponding file. Since lines or records
+are not split even if they overlap a partition, the files written
+can be larger or smaller than the partition size, and even empty
+if a line/record is so long as to completely overlap the partition.
+
+For @samp{r} mode, the size of @var{input} is irrelevant,
+and so can be a pipe for example.
+
+@item -a @var{length}
+@itemx --suffix-length=@var{length}
+@opindex -a
+@opindex --suffix-length
+Use suffixes of length @var{length}. If a @var{length} of 0 is specified,
+this is the same as if (any previous) @option{-a} was not specified, and
+thus enables the default behavior, which starts the suffix length at 2,
+and unless @option{-n} or @option{--numeric-suffixes=@var{from}} is
+specified, will auto increase the length by 2 as required.
@item -d
-@itemx --numeric-suffixes
+@itemx --numeric-suffixes[=@var{from}]
@opindex -d
@opindex --numeric-suffixes
-Use digits in suffixes rather than lower-case letters.
+Use digits in suffixes rather than lower-case letters. The numerical
+suffix counts from @var{from} if specified, 0 otherwise.
+
+@var{from} is supported with the long form option, and is used to either set the
+initial suffix for a single run, or to set the suffix offset for independently
+split inputs, and consequently the auto suffix length expansion described above
+is disabled. Therefore you may also want to use option @option{-a} to allow
+suffixes beyond @samp{99}. Note if option @option{--number} is specified and
+the number of files is less than @var{from}, a single run is assumed and the
+minimum suffix length required is automatically determined.
+
+@item --additional-suffix=@var{suffix}
+@opindex --additional-suffix
+Append an additional @var{suffix} to output file names. @var{suffix}
+must not contain slash.
-@itemx --verbose
+@item -e
+@itemx --elide-empty-files
+@opindex -e
+@opindex --elide-empty-files
+Suppress the generation of zero-length output files. This can happen
+with the @option{--number} option if a file is (truncated to be) shorter
+than the number requested, or if a line is so long as to completely
+span a chunk. The output file sequence numbers, always run consecutively
+even when this option is specified.
+
+@item -t @var{separator}
+@itemx --separator=@var{separator}
+@opindex -t
+@opindex --separator
+@cindex line separator character
+@cindex record separator character
+Use character @var{separator} as the record separator instead of the default
+newline character (ASCII LF).
+To specify ASCII NUL as the separator, use the two-character string @samp{\0},
+e.g., @samp{split -t '\0'}.
+
+@item -u
+@itemx --unbuffered
+@opindex -u
+@opindex --unbuffered
+Immediately copy input to output in @option{--number r/@dots{}} mode,
+which is a much slower mode of operation.
+
+@item --verbose
@opindex --verbose
-Write a diagnostic to standard error just before each output file is opened.
+Write a diagnostic just before each output file is opened.
@end table
@exitstatus
+Here are a few examples to illustrate how the
+@option{--number} (@option{-n}) option works:
+
+Notice how, by default, one line may be split onto two or more:
+
+@example
+$ seq -w 6 10 > k; split -n3 k; head xa?
+==> xaa <==
+06
+07
+==> xab <==
+
+08
+0
+==> xac <==
+9
+10
+@end example
+
+Use the "l/" modifier to suppress that:
+
+@example
+$ seq -w 6 10 > k; split -nl/3 k; head xa?
+==> xaa <==
+06
+07
+
+==> xab <==
+08
+09
+
+==> xac <==
+10
+@end example
+
+Use the "r/" modifier to distribute lines in a round-robin fashion:
+
+@example
+$ seq -w 6 10 > k; split -nr/3 k; head xa?
+==> xaa <==
+06
+09
+
+==> xab <==
+07
+10
+
+==> xac <==
+08
+@end example
+
+You can also extract just the Kth chunk.
+This extracts and prints just the 7th "chunk" of 33:
+
+@example
+$ seq 100 > k; split -nl/7/33 k
+20
+21
+22
+@end example
+
@node csplit invocation
@section @command{csplit}: Split a file into context-determined pieces
@@ -2901,19 +3411,20 @@ The program accepts the following options. Also see @ref{Common options}.
@cindex output file name prefix
Use @var{prefix} as the output file name prefix.
-@item -b @var{suffix}
-@itemx --suffix=@var{suffix}
+@item -b @var{format}
+@itemx --suffix-format=@var{format}
@opindex -b
-@opindex --suffix
+@opindex --suffix-format
@cindex output file name suffix
-Use @var{suffix} as the output file name suffix. When this option is
+Use @var{format} as the output file name suffix. When this option is
specified, the suffix string must include exactly one
@code{printf(3)}-style conversion specification, possibly including
format specification flags, a field width, a precision specifications,
or all of these kinds of modifiers. The format letter must convert a
-binary integer argument to readable form; thus, only @samp{d}, @samp{i},
+binary unsigned integer argument to readable form. The format letters
+@samp{d} and @samp{i} are aliases for @samp{u}, and the
@samp{u}, @samp{o}, @samp{x}, and @samp{X} conversions are allowed. The
-entire @var{suffix} is given (with the current output file number) to
+entire @var{format} is given (with the current output file number) to
@code{sprintf(3)} to form the file name suffixes for each of the
individual output files in turn. If this option is used, the
@option{--digits} option is ignored.
@@ -2931,6 +3442,12 @@ long instead of the default 2.
@opindex --keep-files
Do not remove output files when errors are encountered.
+@item --suppress-matched
+@opindex --suppress-matched
+Do not output lines matching the specified @var{pattern}.
+I.e., suppress the boundary line from the start of the second
+and subsequent splits.
+
@item -z
@itemx --elide-empty-files
@opindex -z
@@ -2956,6 +3473,75 @@ Do not print counts of output file sizes.
@exitstatus
+Here is an example of its usage.
+First, create an empty directory for the exercise,
+and cd into it:
+
+@example
+$ mkdir d && cd d
+@end example
+
+Now, split the sequence of 1..14 on lines that end with 0 or 5:
+
+@example
+$ seq 14 | csplit - '/[05]$/' '@{*@}'
+8
+10
+15
+@end example
+
+Each number printed above is the size of an output
+file that csplit has just created.
+List the names of those output files:
+
+@example
+$ ls
+xx00 xx01 xx02
+@end example
+
+Use @command{head} to show their contents:
+
+@example
+$ head xx*
+==> xx00 <==
+1
+2
+3
+4
+
+==> xx01 <==
+5
+6
+7
+8
+9
+
+==> xx02 <==
+10
+11
+12
+13
+14
+@end example
+
+Example of splitting input by empty lines:
+
+@example
+$ csplit --suppress-matched @var{input.txt} '/^$/' '@{*@}'
+@end example
+
+@c
+@c TODO: "uniq" already supports "--group".
+@c when it gets the "--key" option, uncomment this example.
+@c
+@c Example of splitting input file, based on the value of column 2:
+@c
+@c @example
+@c $ cat @var{input.txt} |
+@c sort -k2,2 |
+@c uniq --group -k2,2 |
+@c csplit -m '/^$/' '@{*@}'
+@c @end example
@node Summarizing files
@chapter Summarizing files
@@ -3003,7 +3589,7 @@ Each count is printed right-justified in a field with at least one
space between fields so that the numbers and file names normally line
up nicely in columns. The width of the count fields varies depending
on the inputs, so you should not depend on a particular field width.
-However, as a @acronym{GNU} extension, if only one count is printed,
+However, as a GNU extension, if only one count is printed,
it is guaranteed to be printed without leading spaces.
By default, @command{wc} prints three counts: the newline, words, and byte
@@ -3019,7 +3605,9 @@ prints both the byte counts and the word counts.
With the @option{--max-line-length} option, @command{wc} prints the length
of the longest line per file, and if there is more than one file it
-prints the maximum (not the sum) of those lengths.
+prints the maximum (not the sum) of those lengths. The line lengths here
+are measured in screen columns, according to the current locale and
+assuming tab positions in every 8th column.
The program accepts the following options. Also see @ref{Common options}.
@@ -3053,30 +3641,42 @@ Print only the newline counts.
@itemx --max-line-length
@opindex -L
@opindex --max-line-length
-Print only the maximum line lengths.
-
-@itemx --files0-from=@var{FILE}
-@opindex --files0-from=@var{FILE}
-@cindex including files from @command{du}
-Rather than processing files named on the command line, process those
-named in file @var{FILE}; each name is terminated by a null byte.
-This is useful when
-the list of file names is so long that it may exceed a command line
+Print only the maximum display widths.
+Tabs are set at every 8th column.
+Display widths of wide characters are considered.
+Non-printable characters are given 0 width.
+
+@macro filesZeroFromOption{cmd,withTotalOption,subListOutput}
+@item --files0-from=@var{file}
+@opindex --files0-from=@var{file}
+@c This is commented out to avoid a texi2dvi failure.
+@c texi2dvi (GNU Texinfo 4.11) 1.104
+@c @cindex including files from @command{\cmd\}
+Disallow processing files named on the command line, and instead process
+those named in file @var{file}; each name being terminated by a zero byte
+(ASCII NUL).
+This is useful \withTotalOption\
+when the list of file names is so long that it may exceed a command line
length limitation.
-In such cases, running @command{wc} via @command{xargs} is undesirable
-because it splits the list into pieces and makes @command{wc} print a
-total for each sublist rather than for the entire list.
-One way to produce a list of null-byte-terminated file names is with @sc{gnu}
-@command{find}, using its @option{-print0} predicate. For example, to find
-the length of the longest line in any @file{.c} or @file{.h} file in the
-current hierarchy, do this:
+In such cases, running @command{\cmd\} via @command{xargs} is undesirable
+because it splits the list into pieces and makes @command{\cmd\} print
+\subListOutput\ for each sublist rather than for the entire list.
+One way to produce a list of ASCII NUL terminated file
+names is with GNU
+@command{find}, using its @option{-print0} predicate.
+If @var{file} is @samp{-} then the ASCII NUL terminated
+file names are read from standard input.
+@end macro
+@filesZeroFromOption{wc,,a total}
+
+For example, to find the length of the longest line in any @file{.c} or
+@file{.h} file in the current hierarchy, do this:
@example
-find . -name '*.[ch]' -print0 | wc -L --files0-from=- | tail -n1
+find . -name '*.[ch]' -print0 |
+ wc -L --files0-from=- | tail -n1
@end example
-Do not specify any @var{FILE} on the command line when using this option.
-
@end table
@exitstatus
@@ -3102,7 +3702,7 @@ is given, file names are also printed (by default). (With the
@option{--sysv} option, corresponding file names are printed when there is
at least one file argument.)
-By default, @sc{gnu} @command{sum} computes checksums using an algorithm
+By default, GNU @command{sum} computes checksums using an algorithm
compatible with BSD @command{sum} and prints file sizes in units of
1024-byte blocks.
@@ -3157,7 +3757,7 @@ by comparing the @command{cksum} output for the received files with the
@command{cksum} output for the original files (typically given in the
distribution).
-The CRC algorithm is specified by the @acronym{POSIX} standard. It is not
+The CRC algorithm is specified by the POSIX standard. It is not
compatible with the BSD or System V @command{sum} algorithms (see the
previous section); it is more robust.
@@ -3183,14 +3783,12 @@ options}.
Note: The MD5 digest is more reliable than a simple CRC (provided by
the @command{cksum} command) for detecting accidental file corruption,
as the chances of accidentally having two files with identical MD5
-are vanishingly small. However, it should not be considered truly
-secure against malicious tampering: although finding a file with a
-given MD5 fingerprint, or modifying a file so as to retain its MD5 are
-considered infeasible at the moment, it is known how to produce
-different files with identical MD5 (a ``collision''), something which
-can be a security issue in certain contexts. For more secure hashes,
-consider using SHA-1 or SHA-2. @xref{sha1sum invocation}, and
-@ref{sha2 utilities}.
+are vanishingly small. However, it should not be considered secure
+against malicious tampering: although finding a file with a given MD5
+fingerprint is considered infeasible at the moment, it is known how
+to modify certain files, including digital certificates, so that they
+appear valid when signed with an MD5 digest.
+For more secure hashes, consider using SHA-2. @xref{sha2 utilities}.
If a @var{file} is specified as @samp{-} or if no files are given
@command{md5sum} computes the checksum for the standard input.
@@ -3201,8 +3799,11 @@ consistent. Synopsis:
md5sum [@var{option}]@dots{} [@var{file}]@dots{}
@end example
-For each @var{file}, @samp{md5sum} outputs the MD5 checksum, a flag
-indicating a binary or text input file, and the file name.
+For each @var{file}, @samp{md5sum} outputs by default, the MD5 checksum,
+a space, a flag indicating binary or text input mode, and the file name.
+Binary mode is indicated with @samp{*}, text mode with @samp{ } (space).
+Binary mode is the default on systems where it's significant,
+otherwise text mode is the default.
If @var{file} contains a backslash or newline, the
line is started with a backslash, and each problematic character in
the file name is escaped with a backslash, making the output
@@ -3220,8 +3821,8 @@ The program accepts the following options. Also see @ref{Common options}.
@cindex binary input files
Treat each input file as binary, by reading it in binary mode and
outputting a @samp{*} flag. This is the inverse of @option{--text}.
-On systems like @acronym{GNU} that do not distinguish between binary
-and text files, this option merely flags each input file as binary:
+On systems like GNU that do not distinguish between binary
+and text files, this option merely flags each input mode as binary:
the MD5 checksum is unaffected. This option is the default on systems
like MS-DOS that distinguish between binary and text files, except
for reading standard input when standard input is a terminal.
@@ -3233,9 +3834,11 @@ Read file names and checksum information (not data) from each
whether the checksums match the contents of the named files.
The input to this mode of @command{md5sum} is usually the output of
a prior, checksum-generating run of @samp{md5sum}.
-Each valid line of input consists of an MD5 checksum, a binary/text
-flag, and then a file name.
-Binary files are marked with @samp{*}, text with @samp{ }.
+Three input formats are supported. Either the default output
+format described above, the @option{--tag} output format,
+or the BSD reversed mode format which is similar to the default mode,
+but doesn't use a character to distinguish binary and text modes.
+@sp 1
For each such line, @command{md5sum} reads the named file and computes its
MD5 checksum. Then, if the computed message digest does not match the
one on the line with the file name, the file is noted as having
@@ -3250,7 +3853,24 @@ an MD5 checksum inconsistent with the associated file, or if no valid
line is found, @command{md5sum} exits with nonzero status. Otherwise,
it exits successfully.
-@itemx --status
+@item --ignore-missing
+@opindex --ignore-missing
+@cindex verifying MD5 checksums
+This option is useful only when verifying checksums.
+When verifying checksums, don't fail or report any status
+for missing files. This is useful when verifying a subset
+of downloaded files given a larger list of checksums.
+
+@item --quiet
+@opindex --quiet
+@cindex verifying MD5 checksums
+This option is useful only when verifying checksums.
+When verifying checksums, don't generate an 'OK' message per successfully
+checked file. Files that fail the verification are reported in the
+default one-line-per-file format. If there is any checksum mismatch,
+print a warning summarizing the failures to standard error.
+
+@item --status
@opindex --status
@cindex verifying MD5 checksums
This option is useful only when verifying checksums.
@@ -3262,6 +3882,17 @@ If all listed files are readable and are consistent with the associated
MD5 checksums, exit successfully. Otherwise exit with a status code
indicating there was a failure.
+@item --tag
+@opindex --tag
+@cindex BSD output
+Output BSD style checksums, which indicate the checksum algorithm used.
+As a GNU extension, file names with problematic characters
+are escaped as described above, with the same escaping indicator of @samp{\}
+at the start of the line, being used.
+The @option{--tag} option implies binary mode, and is disallowed with
+@option{--text} mode as supporting that would unnecessarily complicate
+the output format, while providing little benefit.
+
@item -t
@itemx --text
@opindex -t
@@ -3269,10 +3900,10 @@ indicating there was a failure.
@cindex text input files
Treat each input file as text, by reading it in text mode and
outputting a @samp{ } flag. This is the inverse of @option{--binary}.
-This option is the default on systems like @acronym{GNU} that do not
+This option is the default on systems like GNU that do not
distinguish between binary and text files. On other systems, it is
the default for reading standard input when standard input is a
-terminal.
+terminal. This mode is never defaulted to if @option{--tag} is used.
@item -w
@itemx --warn
@@ -3283,6 +3914,13 @@ When verifying checksums, warn about improperly formatted MD5 checksum lines.
This option is useful only if all but a few lines in the checked input
are valid.
+@item --strict
+@opindex --strict
+@cindex verifying MD5 checksums
+When verifying checksums,
+if one or more input line is invalid,
+exit nonzero after all warnings have been issued.
+
@end table
@exitstatus
@@ -3339,12 +3977,10 @@ The commands @command{sha224sum}, @command{sha256sum},
@command{sha384sum} and @command{sha512sum} compute checksums of
various lengths (respectively 224, 256, 384 and 512 bits),
collectively known as the SHA-2 hashes. The usage and options of
-these commands are precisely the same as for @command{md5sum}.
+these commands are precisely the same as for @command{md5sum}
+and @command{sha1sum}.
@xref{md5sum invocation}.
-Note: The SHA384 and SHA512 digests are considerably slower to
-compute, especially on 32-bit computers, than SHA224 or SHA256.
-
@node Operating on sorted files
@chapter Operating on sorted files
@@ -3361,7 +3997,6 @@ These commands work with (or produce) sorted files.
* comm invocation:: Compare two sorted files line by line.
* ptx invocation:: Produce a permuted index of file contents.
* tsort invocation:: Topological sort.
-* tsort background:: Where tsort came from.
@end menu
@@ -3380,6 +4015,42 @@ output. Synopsis:
sort [@var{option}]@dots{} [@var{file}]@dots{}
@end example
+@cindex sort stability
+@cindex sort's last-resort comparison
+Many options affect how @command{sort} compares lines; if the results
+are unexpected, try the @option{--debug} option to see what happened.
+A pair of lines is compared as follows:
+@command{sort} compares each pair of fields, in the
+order specified on the command line, according to the associated
+ordering options, until a difference is found or no fields are left.
+If no key fields are specified, @command{sort} uses a default key of
+the entire line. Finally, as a last resort when all keys compare
+equal, @command{sort} compares entire lines as if no ordering options
+other than @option{--reverse} (@option{-r}) were specified. The
+@option{--stable} (@option{-s}) option disables this @dfn{last-resort
+comparison} so that lines in which all fields compare equal are left
+in their original relative order. The @option{--unique}
+(@option{-u}) option also disables the last-resort comparison.
+@vindex LC_ALL
+@vindex LC_COLLATE
+
+Unless otherwise specified, all comparisons use the character collating
+sequence specified by the @env{LC_COLLATE} locale.@footnote{If you
+use a non-POSIX locale (e.g., by setting @env{LC_ALL}
+to @samp{en_US}), then @command{sort} may produce output that is sorted
+differently than you're accustomed to. In that case, set the @env{LC_ALL}
+environment variable to @samp{C}@. Note that setting only @env{LC_COLLATE}
+has two problems. First, it is ineffective if @env{LC_ALL} is also set.
+Second, it has undefined behavior if @env{LC_CTYPE} (or @env{LANG}, if
+@env{LC_CTYPE} is unset) is set to an incompatible value. For example,
+you get undefined behavior if @env{LC_CTYPE} is @code{ja_JP.PCK} but
+@env{LC_COLLATE} is @code{en_US.UTF-8}.}
+A line's trailing newline is not part of the line for comparison
+purposes. If the final byte of an input file is not a newline, GNU
+@command{sort} silently supplies one. GNU @command{sort} (as
+specified for all GNU utilities) has no limit on input line length or
+restrictions on bytes allowed within lines.
+
@command{sort} has three modes of operation: sort (the default), merge,
and check for sortedness. The following options change the operation
mode:
@@ -3421,41 +4092,6 @@ works.
@end table
-@cindex sort stability
-@cindex sort's last-resort comparison
-A pair of lines is compared as follows:
-@command{sort} compares each pair of fields, in the
-order specified on the command line, according to the associated
-ordering options, until a difference is found or no fields are left.
-If no key fields are specified, @command{sort} uses a default key of
-the entire line. Finally, as a last resort when all keys compare
-equal, @command{sort} compares entire lines as if no ordering options
-other than @option{--reverse} (@option{-r}) were specified. The
-@option{--stable} (@option{-s}) option disables this @dfn{last-resort
-comparison} so that lines in which all fields compare equal are left
-in their original relative order. The @option{--unique}
-(@option{-u}) option also disables the last-resort comparison.
-
-@vindex LC_ALL
-@vindex LC_COLLATE
-Unless otherwise specified, all comparisons use the character collating
-sequence specified by the @env{LC_COLLATE} locale.@footnote{If you
-use a non-@acronym{POSIX} locale (e.g., by setting @env{LC_ALL}
-to @samp{en_US}), then @command{sort} may produce output that is sorted
-differently than you're accustomed to. In that case, set the @env{LC_ALL}
-environment variable to @samp{C}. Note that setting only @env{LC_COLLATE}
-has two problems. First, it is ineffective if @env{LC_ALL} is also set.
-Second, it has undefined behavior if @env{LC_CTYPE} (or @env{LANG}, if
-@env{LC_CTYPE} is unset) is set to an incompatible value. For example,
-you get undefined behavior if @env{LC_CTYPE} is @code{ja_JP.PCK} but
-@env{LC_COLLATE} is @code{en_US.UTF-8}.}
-
-@sc{gnu} @command{sort} (as specified for all @sc{gnu} utilities) has no
-limit on input line length or restrictions on bytes allowed within lines.
-In addition, if the final byte of an input file is not a newline, @sc{gnu}
-@command{sort} silently supplies one. A line's trailing newline is not
-part of the line for comparison purposes.
-
@cindex exit status of @command{sort}
Exit status:
@@ -3475,7 +4111,7 @@ The following options affect the ordering of output lines. They may be
specified globally or as part of a specific key field. If no key
fields are specified, global options apply to comparison of entire
lines; otherwise the global options are inherited by key fields that do
-not specify any special options of their own. In pre-@acronym{POSIX}
+not specify any special options of their own. In pre-POSIX
versions of @command{sort}, global options affect only later key fields,
so portable shell scripts should specify global options first.
@@ -3489,7 +4125,9 @@ so portable shell scripts should specify global options first.
@vindex LC_CTYPE
Ignore leading blanks when finding sort keys in each line.
By default a blank is a space or a tab, but the @env{LC_CTYPE} locale
-can change this.
+can change this. Note blanks may be ignored by your locale's collating
+rules, but without this option they will be significant for character
+positions specified in keys with the @option{-k} option.
@item -d
@itemx --dictionary-order
@@ -3501,7 +4139,7 @@ can change this.
@vindex LC_CTYPE
Sort in @dfn{phone directory} order: ignore all characters except
letters, digits and blanks when sorting.
-By default letters and digits are those of @acronym{ASCII} and a blank
+By default letters and digits are those of ASCII and a blank
is a space or a tab, but the @env{LC_CTYPE} locale can change this.
@item -f
@@ -3514,18 +4152,21 @@ is a space or a tab, but the @env{LC_CTYPE} locale can change this.
Fold lowercase characters into the equivalent uppercase characters when
comparing so that, for example, @samp{b} and @samp{B} sort as equal.
The @env{LC_CTYPE} locale determines character types.
+When used with @option{--unique} those lower case equivalent lines are
+thrown away. (There is currently no way to throw away the upper case
+equivalent instead. (Any @option{--reverse} given would only affect
+the final result, after the throwing away.))
@item -g
@itemx --general-numeric-sort
+@itemx --sort=general-numeric
@opindex -g
@opindex --general-numeric-sort
+@opindex --sort
@cindex general numeric sort
@vindex LC_NUMERIC
-Sort numerically, using the standard C function @code{strtod} to convert
-a prefix of each line to a double-precision floating point number.
-This allows floating point numbers to be specified in scientific notation,
-like @code{1.0e-34} and @code{10e100}.
-The @env{LC_NUMERIC} locale determines the decimal-point character.
+Sort numerically, converting a prefix of each line to a long
+double-precision floating point number. @xref{Floating point}.
Do not report overflow, underflow, or conversion errors.
Use the following collating sequence:
@@ -3547,6 +4188,30 @@ Use this option only if there is no alternative; it is much slower than
@option{--numeric-sort} (@option{-n}) and it can lose information when
converting to floating point.
+@item -h
+@itemx --human-numeric-sort
+@itemx --sort=human-numeric
+@opindex -h
+@opindex --human-numeric-sort
+@opindex --sort
+@cindex human numeric sort
+@vindex LC_NUMERIC
+Sort numerically, first by numeric sign (negative, zero, or positive);
+then by SI suffix (either empty, or @samp{k} or @samp{K}, or
+one of @samp{MGTPEZY}, in that order; @pxref{Block size}); and finally
+by numeric value. For example, @samp{1023M} sorts before @samp{1G}
+because @samp{M} (mega) precedes @samp{G} (giga) as an SI
+suffix. This option sorts values that are consistently scaled to the
+nearest suffix, regardless of whether suffixes denote powers of 1000
+or 1024, and it therefore sorts the output of any single invocation of
+the @command{df}, @command{du}, or @command{ls} commands that are
+invoked with their @option{--human-readable} or @option{--si} options.
+The syntax for numbers is the same as for the @option{--numeric-sort}
+option; the SI suffix must immediately follow the number.
+Note also the @command{numfmt} command, which can be used to reformat
+numbers to human format @emph{after} the sort, thus often allowing
+sort to operate on more accurate numbers.
+
@item -i
@itemx --ignore-nonprinting
@opindex -i
@@ -3561,13 +4226,15 @@ This option has no effect if the stronger @option{--dictionary-order}
@item -M
@itemx --month-sort
+@itemx --sort=month
@opindex -M
@opindex --month-sort
+@opindex --sort
@cindex months, sorting by
@vindex LC_TIME
An initial string, consisting of any amount of blanks, followed
by a month name abbreviation, is folded to UPPER case and
-compared in the order @samp{JAN} < @samp{FEB} < @dots{} < @samp{DEC}.
+compared in the order @samp{JAN} < @samp{FEB} < @dots{} < @samp{DEC}@.
Invalid names compare low to valid names. The @env{LC_TIME} locale
category determines the month spellings.
By default a blank is a space or a tab, but the @env{LC_CTYPE} locale
@@ -3575,8 +4242,10 @@ can change this.
@item -n
@itemx --numeric-sort
+@itemx --sort=numeric
@opindex -n
@opindex --numeric-sort
+@opindex --sort
@cindex numeric sort
@vindex LC_NUMERIC
Sort numerically. The number begins each line and consists
@@ -3594,6 +4263,15 @@ Neither a leading @samp{+} nor exponential notation is recognized.
To compare such strings numerically, use the
@option{--general-numeric-sort} (@option{-g}) option.
+@item -V
+@itemx --version-sort
+@opindex -V
+@opindex --version-sort
+@cindex version number sort
+Sort by version name and number. It behaves like a standard sort,
+except that each sequence of decimal digits is treated numerically
+as an index/version number. (@xref{Details about version sort}.)
+
@item -r
@itemx --reverse
@opindex -r
@@ -3604,8 +4282,10 @@ appear earlier in the output instead of later.
@item -R
@itemx --random-sort
+@itemx --sort=random
@opindex -R
@opindex --random-sort
+@opindex --sort
@cindex random sort
Sort by hashing the input keys and then sorting the hash values.
Choose the hash function at random, ensuring that it is free of
@@ -3636,9 +4316,11 @@ standard input to standard output.
Terminate with an error if @var{prog} exits with nonzero status.
-Whitespace and the backslash character should not appear in
+White space and the backslash character should not appear in
@var{prog}; they are reserved for future use.
+@filesZeroFromOption{sort,,sorted output}
+
@item -k @var{pos1}[,@var{pos2}]
@itemx --key=@var{pos1}[,@var{pos2}]
@opindex -k
@@ -3660,7 +4342,40 @@ according to different rules; see below for details. Keys can span
multiple fields.
Example: To sort on the second field, use @option{--key=2,2}
-(@option{-k 2,2}). See below for more examples.
+(@option{-k 2,2}). See below for more notes on keys and more examples.
+See also the @option{--debug} option to help determine the part
+of the line being used in the sort.
+
+@item --debug
+Highlight the portion of each line used for sorting.
+Also issue warnings about questionable usage to stderr.
+
+@item --batch-size=@var{nmerge}
+@opindex --batch-size
+@cindex number of inputs to merge, nmerge
+Merge at most @var{nmerge} inputs at once.
+
+When @command{sort} has to merge more than @var{nmerge} inputs,
+it merges them in groups of @var{nmerge}, saving the result in
+a temporary file, which is then used as an input in a subsequent merge.
+
+A large value of @var{nmerge} may improve merge performance and decrease
+temporary storage utilization at the expense of increased memory usage
+and I/O@. Conversely a small value of @var{nmerge} may reduce memory
+requirements and I/O at the expense of temporary storage consumption and
+merge performance.
+
+The value of @var{nmerge} must be at least 2. The default value is
+currently 16, but this is implementation-dependent and may change in
+the future.
+
+The value of @var{nmerge} may be bounded by a resource limit for open
+file descriptors. The commands @samp{ulimit -n} or @samp{getconf
+OPEN_MAX} may display limits for your systems; these limits may be
+modified further if your program already has some files open, or if
+the operating system has other limits on the number of open files. If
+the value of @var{nmerge} exceeds the resource limit, @command{sort}
+silently uses a smaller value.
@item -o @var{output-file}
@itemx --output=@var{output-file}
@@ -3670,7 +4385,7 @@ Example: To sort on the second field, use @option{--key=2,2}
Write output to @var{output-file} instead of standard output.
Normally, @command{sort} reads all input before opening
@var{output-file}, so you can safely sort a file in place by using
-commands like @code{sort -o F F} and @code{cat F | sort -o F}.
+commands like @code{sort -o F F} and @code{cat F | sort -o F}@.
However, @command{sort} with @option{--merge} (@option{-m}) can open
the output file before reading all input, so a command like @code{cat
F | sort -m -o F - G} is not safe as @command{sort} might start
@@ -3678,7 +4393,7 @@ writing @file{F} before @command{cat} is done reading it.
@vindex POSIXLY_CORRECT
On newer systems, @option{-o} cannot appear after an input file if
-@env{POSIXLY_CORRECT} is set, e.g., @samp{sort F -o F}. Portable
+@env{POSIXLY_CORRECT} is set, e.g., @samp{sort F -o F}@. Portable
scripts should specify @option{-o @var{output-file}} before any input
files.
@@ -3710,7 +4425,7 @@ Use a main-memory sort buffer of the given @var{size}. By default,
@var{size} to be interpreted as a percentage of physical memory.
Appending @samp{K} multiplies @var{size} by 1024 (the default),
@samp{M} by 1,048,576, @samp{G} by 1,073,741,824, and so on for
-@samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}. Appending
+@samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}@. Appending
@samp{b} causes @var{size} to be interpreted as a byte count, with no
multiplication.
@@ -3740,9 +4455,8 @@ However, fields that extend to the end of the line,
as @option{-k 2}, or fields consisting of a range, as @option{-k 2,3},
retain the field separators present between the endpoints of the range.
-To specify a null character (@acronym{ASCII} @sc{nul}) as
-the field separator, use the two-character string @samp{\0}, e.g.,
-@samp{sort -t '\0'}.
+To specify ASCII NUL as the field separator,
+use the two-character string @samp{\0}, e.g., @samp{sort -t '\0'}.
@item -T @var{tempdir}
@itemx --temporary-directory=@var{tempdir}
@@ -3757,6 +4471,15 @@ have a large sort or merge that is I/O-bound, you can often improve
performance by using this option to specify directories on different
disks and controllers.
+@item --parallel=@var{n}
+@opindex --parallel
+@cindex multithreaded sort
+Set the number of sorts run in parallel to @var{n}. By default,
+@var{n} is set to the number of available processors, but limited
+to 8, as there are diminishing performance gains after that.
+Note also that using @var{n} threads increases the memory usage by
+a factor of log @var{n}. Also see @ref{nproc invocation}.
+
@item -u
@itemx --unique
@opindex -u
@@ -3775,40 +4498,33 @@ For example, @code{sort -n -u} inspects only the value of the initial
numeric string when checking for uniqueness, whereas @code{sort -n |
uniq} inspects the entire line. @xref{uniq invocation}.
-@item -z
-@itemx --zero-terminated
-@opindex -z
-@opindex --zero-terminated
-@cindex sort zero-terminated lines
-Treat the input as a set of lines, each terminated by a null character
-(@acronym{ASCII} @sc{nul}) instead of a line feed
-(@acronym{ASCII} @sc{lf}).
-This option can be useful in conjunction with @samp{perl -0} or
-@samp{find -print0} and @samp{xargs -0} which do the same in order to
-reliably handle arbitrary file names (even those containing blanks
-or other special characters).
+@optZeroTerminated
+@macro newlineFieldSeparator
+Note with @option{-z} the newline character is treated as a field separator.
+@end macro
@end table
Historical (BSD and System V) implementations of @command{sort} have
differed in their interpretation of some options, particularly
-@option{-b}, @option{-f}, and @option{-n}. @sc{gnu} sort follows the @acronym{POSIX}
+@option{-b}, @option{-f}, and @option{-n}.
+GNU sort follows the POSIX
behavior, which is usually (but not always!) like the System V behavior.
-According to @acronym{POSIX}, @option{-n} no longer implies @option{-b}. For
+According to POSIX, @option{-n} no longer implies @option{-b}. For
consistency, @option{-M} has been changed in the same way. This may
affect the meaning of character positions in field specifications in
obscure cases. The only fix is to add an explicit @option{-b}.
A position in a sort field specified with @option{-k} may have any
-of the option letters @samp{Mbdfinr} appended to it, in which case the
-global ordering options are not used for that particular field. The
+of the option letters @samp{MbdfghinRrV} appended to it, in which case no
+global ordering options are inherited by that particular field. The
@option{-b} option may be independently attached to either or both of
the start and end positions of a field specification, and if it is
inherited from the global options it will be attached to both.
If input lines can contain leading or adjacent blanks and @option{-t}
-is not used, then @option{-k} is typically combined with @option{-b},
-@option{-g}, @option{-M}, or @option{-n}; otherwise the varying
-numbers of leading blanks in fields can cause confusing results.
+is not used, then @option{-k} is typically combined with @option{-b} or
+an option that implicitly ignores leading blanks (@samp{Mghn}) as otherwise
+the varying numbers of leading blanks in fields can cause confusing results.
If the start position in a sort field specifier falls after the end of
the line or after the end field, the field is empty. If the @option{-b}
@@ -3819,6 +4535,11 @@ is counted from the first nonblank character of the field.
@vindex POSIXLY_CORRECT
On older systems, @command{sort} supports an obsolete origin-zero
syntax @samp{+@var{pos1} [-@var{pos2}]} for specifying sort keys.
+The obsolete sequence @samp{sort +@var{a}.@var{x} -@var{b}.@var{y}}
+is equivalent to @samp{sort -k @var{a+1}.@var{x+1},@var{b}} if @var{y}
+is @samp{0} or absent, otherwise it is equivalent to @samp{sort -k
+@var{a+1}.@var{x+1},@var{b+1}.@var{y}}.
+
This obsolete behavior can be enabled or disabled with the
@env{_POSIX2_VERSION} environment variable (@pxref{Standards
conformance}); it can also be enabled when @env{POSIXLY_CORRECT} is
@@ -3844,6 +4565,13 @@ sort -n -r
@end example
@item
+Run no more than 4 sorts concurrently, using a buffer size of 10M.
+
+@example
+sort --parallel=4 -S 10M
+@end example
+
+@item
Sort alphabetically, omitting the first and second fields
and the blanks at the start of the third field.
This uses a single key composed of the characters beginning
@@ -3950,10 +4678,24 @@ by the sort operation.
@c and converting each @samp{\0} back to the original record delimiter.
@c
@c @example
-@c printf 'c\n\nb\n\na\n'|perl -0pe 's/\n\n/\n\0/g'|sort -z|perl -0pe 's/\0/\n/g'
+@c printf 'c\n\nb\n\na\n' |
+@c perl -0pe 's/\n\n/\n\0/g' |
+@c sort -z |
+@c perl -0pe 's/\0/\n/g'
@c @end example
@item
+Use the common DSU, Decorate Sort Undecorate idiom to
+sort lines according to their length.
+
+@example
+awk '@{print length, $0@}' /etc/passwd | sort -n | cut -f2- -d' '
+@end example
+
+In general this technique can be used to sort data that the @command{sort}
+command does not support, or is inefficient at, sorting directly.
+
+@item
Shuffle a list of directories, but preserve the order of files within
each directory. For instance, one could use this to generate a music
playlist in which albums are shuffled but the songs of each album are
@@ -4010,12 +4752,12 @@ operation modes:
@table @samp
-@item -n @var{lines}
-@itemx --head-lines=@var{lines}
+@item -n @var{count}
+@itemx --head-count=@var{count}
@opindex -n
-@opindex --head-lines
+@opindex --head-count
@cindex head of output
-Output at most @var{lines} lines. By default, all input lines are
+Output at most @var{count} lines. By default, all input lines are
output.
@item -o @var{output-file}
@@ -4034,18 +4776,19 @@ commands like @code{shuf -o F <F} and @code{cat F | shuf -o F}.
Use @var{file} as a source of random data used to determine which
permutation to generate. @xref{Random sources}.
-@item -z
-@itemx --zero-terminated
-@opindex -z
-@opindex --zero-terminated
-@cindex sort zero-terminated lines
-Treat the input and output as a set of lines, each terminated by a zero byte
-(@acronym{ASCII} @sc{nul} (Null) character) instead of an
-@acronym{ASCII} @sc{lf} (Line Feed).
-This option can be useful in conjunction with @samp{perl -0} or
-@samp{find -print0} and @samp{xargs -0} which do the same in order to
-reliably handle arbitrary file names (even those containing blanks
-or other special characters).
+@item -r
+@itemx --repeat
+@opindex -r
+@opindex --repeat
+@cindex repeat output values
+Repeat output values, that is, select with replacement. With this
+option the output is not a permutation of the input; instead, each
+output line is randomly chosen from all the inputs. This option is
+typically combined with @option{--head-count}; if
+@option{--head-count} is not given, @command{shuf} repeats
+indefinitely.
+
+@optZeroTerminated
@end table
@@ -4098,12 +4841,26 @@ and the command @samp{shuf -i 1-4} might output:
@end example
@noindent
-These examples all have four input lines, so @command{shuf} might
+The above examples all have four input lines, so @command{shuf} might
produce any of the twenty-four possible permutations of the input. In
-general, if there are @var{N} input lines, there are @var{N}! (i.e.,
-@var{N} factorial, or @var{N} * (@var{N} - 1) * @dots{} * 1) possible
+general, if there are @var{n} input lines, there are @var{n}! (i.e.,
+@var{n} factorial, or @var{n} * (@var{n} - 1) * @dots{} * 1) possible
output permutations.
+@noindent
+To output 50 random numbers each in the range 0 through 9, use:
+
+@example
+shuf -r -n 50 -i 0-9
+@end example
+
+@noindent
+To simulate 100 coin flips, use:
+
+@example
+shuf -r -n 100 -e Head Tail
+@end example
+
@exitstatus
@@ -4132,8 +4889,8 @@ duplicate lines, perhaps you want to use @code{sort -u}.
@xref{sort invocation}.
@vindex LC_COLLATE
-Comparisons use the character collating sequence specified by the
-@env{LC_COLLATE} locale category.
+Comparisons honor the rules specified by the @env{LC_COLLATE}
+locale category.
If no @var{output} file is specified, @command{uniq} writes to standard
output.
@@ -4202,8 +4959,9 @@ Do not discard the second and subsequent repeated input lines,
but discard lines that are not repeated.
This option is useful mainly in conjunction with other options e.g.,
to ignore case or to compare only selected fields.
-The optional @var{delimit-method} tells how to delimit
-groups of repeated lines, and must be one of the following:
+The optional @var{delimit-method}, supported with the long form option,
+specifies how to delimit groups of repeated lines, and must be one of the
+following:
@table @samp
@@ -4213,29 +4971,68 @@ This is equivalent to @option{--all-repeated} (@option{-D}).
@item prepend
Output a newline before each group of repeated lines.
+@macro nulOutputNote
+With @option{--zero-terminated} (@option{-z}), use a zero
+byte (ASCII NUL) instead of a newline as the delimiter.
+@end macro
+@nulOutputNote
@item separate
Separate groups of repeated lines with a single newline.
This is the same as using @samp{prepend}, except that
-there is no newline before the first group, and hence
+no delimiter is inserted before the first group, and hence
may be better suited for output direct to users.
+@nulOutputNote
@end table
+@macro ambiguousGroupNote
Note that when groups are delimited and the input stream contains
-two or more consecutive blank lines, then the output is ambiguous.
-To avoid that, filter the input through @samp{tr -s '\n'} to replace
-each sequence of consecutive newlines with a single newline.
+blank lines, then the output is ambiguous.
+To avoid that, filter the input through @samp{tr -s '\\n'} to
+remove blank lines.
+@end macro
+@ambiguousGroupNote
-This is a @sc{gnu} extension.
+This is a GNU extension.
@c FIXME: give an example showing *how* it's useful
+@item --group[=@var{delimit-method}]
+@opindex --group
+@cindex all lines, grouping
+Output all lines, and delimit each unique group.
+@nulOutputNote
+The optional @var{delimit-method} specifies how to delimit
+groups, and must be one of the following:
+
+@table @samp
+
+@item separate
+Separate unique groups with a single delimiter.
+This is the default delimiting method if none is specified,
+and better suited for output direct to users.
+
+@item prepend
+Output a delimiter before each group of unique items.
+
+@item append
+Output a delimiter after each group of unique items.
+
+@item both
+Output a delimiter around each group of unique items.
+@end table
+
+@ambiguousGroupNote
+
+This is a GNU extension.
+
@item -u
@itemx --unique
@opindex -u
@opindex --unique
@cindex unique lines, outputting
-Discard the first repeated line. When used by itself, this option
-causes @command{uniq} to print unique lines, and nothing else.
+Discard the last line that would be output for a repeated input group.
+When used by itself, this option causes @command{uniq} to print unique
+lines, and nothing else.
@item -w @var{n}
@itemx --check-chars=@var{n}
@@ -4245,6 +5042,9 @@ Compare at most @var{n} characters on each line (after skipping any specified
fields and characters). By default the entire rest of the lines are
compared.
+@optZeroTerminated
+@newlineFieldSeparator
+
@end table
@exitstatus
@@ -4279,173 +5079,60 @@ contains lines unique to @var{file1}, column two contains lines unique
to @var{file2}, and column three contains lines common to both files.
Columns are separated by a single TAB character.
@c FIXME: when there's an option to supply an alternative separator
-@c string, append `by default' to the above sentence.
+@c string, append "by default" to the above sentence.
@opindex -1
@opindex -2
@opindex -3
The options @option{-1}, @option{-2}, and @option{-3} suppress printing of
-the corresponding columns. Also see @ref{Common options}.
+the corresponding columns (and separators). Also see @ref{Common options}.
Unlike some other comparison utilities, @command{comm} has an exit
status that does not depend on the result of the comparison.
Upon normal completion @command{comm} produces an exit code of zero.
If there is an error it exits with nonzero status.
+@macro checkOrderOption{cmd}
+If the @option{--check-order} option is given, unsorted inputs will
+cause a fatal error message. If the option @option{--nocheck-order}
+is given, unsorted inputs will never cause an error message. If neither
+of these options is given, wrongly sorted inputs are diagnosed
+only if an input file is found to contain unpairable
+@ifset JOIN_COMMAND
+lines, and when both input files are non empty.
+@end ifset
+@ifclear JOIN_COMMAND
+lines.
+@end ifclear
+If an input file is diagnosed as being unsorted, the @command{\cmd\}
+command will exit with a nonzero status (and the output should not be used).
+
+Forcing @command{\cmd\} to process wrongly sorted input files
+containing unpairable lines by specifying @option{--nocheck-order} is
+not guaranteed to produce any particular output. The output will
+probably not correspond with whatever you hoped it would be.
+@end macro
+@checkOrderOption{comm}
-@node tsort invocation
-@section @command{tsort}: Topological sort
-
-@pindex tsort
-@cindex topological sort
-
-@command{tsort} performs a topological sort on the given @var{file}, or
-standard input if no input file is given or for a @var{file} of
-@samp{-}. For more details and some history, see @ref{tsort background}.
-Synopsis:
-
-@example
-tsort [@var{option}] [@var{file}]
-@end example
-
-@command{tsort} reads its input as pairs of strings, separated by blanks,
-indicating a partial ordering. The output is a total ordering that
-corresponds to the given partial ordering.
-
-For example
-
-@example
-tsort <<EOF
-a b c
-d
-e f
-b c d e
-EOF
-@end example
-
-@noindent
-will produce the output
-
-@example
-a
-b
-c
-d
-e
-f
-@end example
-
-Consider a more realistic example.
-You have a large set of functions all in one file, and they may all be
-declared static except one. Currently that one (say @code{main}) is the
-first function defined in the file, and the ones it calls directly follow
-it, followed by those they call, etc. Let's say that you are determined
-to take advantage of prototypes, so you have to choose between declaring
-all of those functions (which means duplicating a lot of information from
-the definitions) and rearranging the functions so that as many as possible
-are defined before they are used. One way to automate the latter process
-is to get a list for each function of the functions it calls directly.
-Many programs can generate such lists. They describe a call graph.
-Consider the following list, in which a given line indicates that the
-function on the left calls the one on the right directly.
-
-@example
-main parse_options
-main tail_file
-main tail_forever
-tail_file pretty_name
-tail_file write_header
-tail_file tail
-tail_forever recheck
-tail_forever pretty_name
-tail_forever write_header
-tail_forever dump_remainder
-tail tail_lines
-tail tail_bytes
-tail_lines start_lines
-tail_lines dump_remainder
-tail_lines file_lines
-tail_lines pipe_lines
-tail_bytes xlseek
-tail_bytes start_bytes
-tail_bytes dump_remainder
-tail_bytes pipe_bytes
-file_lines dump_remainder
-recheck pretty_name
-@end example
-
-then you can use @command{tsort} to produce an ordering of those
-functions that satisfies your requirement.
-
-@example
-example$ tsort call-graph | tac
-dump_remainder
-start_lines
-file_lines
-pipe_lines
-xlseek
-start_bytes
-pipe_bytes
-tail_lines
-tail_bytes
-pretty_name
-write_header
-tail
-recheck
-parse_options
-tail_file
-tail_forever
-main
-@end example
-
-@command{tsort} detects any cycles in the input and writes the first cycle
-encountered to standard error.
-
-Note that for a given partial ordering, generally there is no unique
-total ordering. In the context of the call graph above, the function
-@code{parse_options} may be placed anywhere in the list as long as it
-precedes @code{main}.
-
-The only options are @option{--help} and @option{--version}. @xref{Common
-options}.
-
-@node tsort background
-@section @command{tsort}: Background
-
-@command{tsort} exists because very early versions of the Unix linker processed
-an archive file exactly once, and in order. As @command{ld} read each object
-in the archive, it decided whether it was needed in the program based on
-whether it defined any symbols which were undefined at that point in
-the link.
+@table @samp
-This meant that dependencies within the archive had to be handled
-specially. For example, @code{scanf} probably calls @code{read}. That means
-that in a single pass through an archive, it was important for @code{scanf.o}
-to appear before read.o, because otherwise a program which calls
-@code{scanf} but not @code{read} might end up with an unexpected unresolved
-reference to @code{read}.
+@item --check-order
+Fail with an error message if either input file is wrongly ordered.
-The way to address this problem was to first generate a set of
-dependencies of one object file on another. This was done by a shell
-script called @command{lorder}. The GNU tools don't provide a version of
-lorder, as far as I know, but you can still find it in BSD
-distributions.
+@item --nocheck-order
+Do not check that both input files are in sorted order.
-Then you ran @command{tsort} over the @command{lorder} output, and you used the
-resulting sort to define the order in which you added objects to the archive.
+Other options are:
-This whole procedure has been obsolete since about 1980, because
-Unix archives now contain a symbol table (traditionally built by
-@command{ranlib}, now generally built by @command{ar} itself), and the Unix
-linker uses the symbol table to effectively make multiple passes over
-an archive file.
+@item --output-delimiter=@var{str}
+Print @var{str} between adjacent output columns,
+rather than the default of a single TAB character.
-Anyhow, that's where tsort came from. To solve an old problem with
-the way the linker handled archive files, which has since been solved
-in different ways.
+The delimiter @var{str} may not be empty.
-@exitstatus
+@optZeroTerminated
+@end table
@node ptx invocation
@section @command{ptx}: Produce permuted indexes
@@ -4461,15 +5148,15 @@ ptx -G [@var{option} @dots{}] [@var{input} [@var{output}]]
@end example
The @option{-G} (or its equivalent: @option{--traditional}) option disables
-all @sc{gnu} extensions and reverts to traditional mode, thus introducing some
+all GNU extensions and reverts to traditional mode, thus introducing some
limitations and changing several of the program's default option values.
-When @option{-G} is not specified, @sc{gnu} extensions are always enabled.
-@sc{gnu} extensions to @command{ptx} are documented wherever appropriate in this
-document. For the full list, see @xref{Compatibility in ptx}.
+When @option{-G} is not specified, GNU extensions are always enabled.
+GNU extensions to @command{ptx} are documented wherever appropriate in this
+document. @xref{Compatibility in ptx}, for the full list.
Individual options are explained in the following sections.
-When @sc{gnu} extensions are enabled, there may be zero, one or several
+When GNU extensions are enabled, there may be zero, one or several
@var{file}s after the options. If there is no @var{file}, the program
reads the standard input. If there is one or several @var{file}s, they
give the name of input files which are all read in turn, as if all the
@@ -4479,7 +5166,7 @@ file names and line numbers refer to individual text input files. In
all cases, the program outputs the permuted index to the standard
output.
-When @sc{gnu} extensions are @emph{not} enabled, that is, when the program
+When GNU extensions are @emph{not} enabled, that is, when the program
operates in traditional mode, there may be zero, one or two parameters
besides the options. If there are no parameters, the program reads the
standard input and outputs the permuted index to the standard output.
@@ -4489,11 +5176,11 @@ respectively the name of the @var{input} file to read and the name of
the @var{output} file to produce. @emph{Be very careful} to note that,
in this case, the contents of file given by the second parameter is
destroyed. This behavior is dictated by System V @command{ptx}
-compatibility; @sc{gnu} Standards normally discourage output parameters not
+compatibility; GNU Standards normally discourage output parameters not
introduced by an option.
Note that for @emph{any} file named as the value of an option or as an
-input text file, a single dash @kbd{-} may be used, in which case
+input text file, a single dash @samp{-} may be used, in which case
standard input is assumed. However, it would not make sense to use this
convention more than once per program invocation.
@@ -4513,7 +5200,7 @@ convention more than once per program invocation.
@item -G
@itemx --traditional
-As already explained, this option disables all @sc{gnu} extensions to
+As already explained, this option disables all GNU extensions to
@command{ptx} and switches to traditional mode.
@item --help
@@ -4534,10 +5221,10 @@ processing.
@c FIXME: People don't necessarily know what an IBM-PC was these days.
As it is set up now, the program assumes that the input file is coded
-using 8-bit @acronym{ISO} 8859-1 code, also known as Latin-1 character set,
+using 8-bit ISO 8859-1 code, also known as Latin-1 character set,
@emph{unless} it is compiled for MS-DOS, in which case it uses the
-character set of the IBM-PC@. (@sc{gnu} @command{ptx} is not known to work on
-smaller MS-DOS machines anymore.) Compared to 7-bit @acronym{ASCII}, the set
+character set of the IBM-PC@. (GNU @command{ptx} is not known to work on
+smaller MS-DOS machines anymore.) Compared to 7-bit ASCII, the set
of characters which are letters is different; this alters the behavior
of regular expression matching. Thus, the default regular expression
for a keyword allows foreign or diacriticized letters. Keyword sorting,
@@ -4548,6 +5235,8 @@ quite blindly.
@item -f
@itemx --ignore-case
+@opindex -f
+@opindex --ignore-case
Fold lower case letters to upper case for sorting.
@end table
@@ -4560,6 +5249,8 @@ Fold lower case letters to upper case for sorting.
@item -b @var{file}
@itemx --break-file=@var{file}
+@opindex -b
+@opindex --break-file
This option provides an alternative (to @option{-W}) method of describing
which characters make up words. It introduces the name of a
@@ -4569,14 +5260,16 @@ is not part of the Break file is a word constituent. If both options
@option{-b} and @option{-W} are specified, then @option{-W} has precedence and
@option{-b} is ignored.
-When @sc{gnu} extensions are enabled, the only way to avoid newline as a
+When GNU extensions are enabled, the only way to avoid newline as a
break character is to write all the break characters in the file with no
-newline at all, not even at the end of the file. When @sc{gnu} extensions
+newline at all, not even at the end of the file. When GNU extensions
are disabled, spaces, tabs and newlines are always considered as break
characters even if not included in the Break file.
@item -i @var{file}
@itemx --ignore-file=@var{file}
+@opindex -i
+@opindex --ignore-file
The file associated with this option contains a list of words which will
never be taken as keywords in concordance output. It is called the
@@ -4586,6 +5279,8 @@ end of line separation of words is not subject to the value of the
@item -o @var{file}
@itemx --only-file=@var{file}
+@opindex -o
+@opindex --only-file
The file associated with this option contains a list of words which will
be retained in concordance output; any word not mentioned in this file
@@ -4599,36 +5294,41 @@ if it is listed in the Only file and not in the Ignore file.
@item -r
@itemx --references
+@opindex -r
+@opindex --references
On each input line, the leading sequence of non-white space characters will be
taken to be a reference that has the purpose of identifying this input
-line in the resulting permuted index. For more information about reference
-production, see @xref{Output formatting in ptx}.
+line in the resulting permuted index.
+@xref{Output formatting in ptx},
+for more information about reference production.
Using this option changes the default value for option @option{-S}.
Using this option, the program does not try very hard to remove
references from contexts in output, but it succeeds in doing so
@emph{when} the context ends exactly at the newline. If option
-@option{-r} is used with @option{-S} default value, or when @sc{gnu} extensions
+@option{-r} is used with @option{-S} default value, or when GNU extensions
are disabled, this condition is always met and references are completely
excluded from the output contexts.
@item -S @var{regexp}
@itemx --sentence-regexp=@var{regexp}
+@opindex -S
+@opindex --sentence-regexp
This option selects which regular expression will describe the end of a
line or the end of a sentence. In fact, this regular expression is not
the only distinction between end of lines or end of sentences, and input
line boundaries have no special significance outside this option. By
-default, when @sc{gnu} extensions are enabled and if @option{-r} option is not
+default, when GNU extensions are enabled and if @option{-r} option is not
used, end of sentences are used. In this case, this @var{regex} is
-imported from @sc{gnu} Emacs:
+imported from GNU Emacs:
@example
[.?!][]\"')@}]*\\($\\|\t\\| \\)[ \t\n]*
@end example
-Whenever @sc{gnu} extensions are disabled or if @option{-r} option is used, end
+Whenever GNU extensions are disabled or if @option{-r} option is used, end
of lines are used; in this case, the default @var{regexp} is just:
@example
@@ -4658,10 +5358,12 @@ corresponding characters by @command{ptx} itself.
@item -W @var{regexp}
@itemx --word-regexp=@var{regexp}
+@opindex -W
+@opindex --word-regexp
This option selects which regular expression will describe each keyword.
-By default, if @sc{gnu} extensions are enabled, a word is a sequence of
-letters; the @var{regexp} used is @samp{\w+}. When @sc{gnu} extensions are
+By default, if GNU extensions are enabled, a word is a sequence of
+letters; the @var{regexp} used is @samp{\w+}. When GNU extensions are
disabled, a word is by default anything which ends with a space, a tab
or a newline; the @var{regexp} used is @samp{[^ \t\n]+}.
@@ -4681,14 +5383,14 @@ the corresponding characters by @command{ptx} itself.
Output format is mainly controlled by the @option{-O} and @option{-T} options
described in the table below. When neither @option{-O} nor @option{-T} are
-selected, and if @sc{gnu} extensions are enabled, the program chooses an
+selected, and if GNU extensions are enabled, the program chooses an
output format suitable for a dumb terminal. Each keyword occurrence is
output to the center of one line, surrounded by its left and right
contexts. Each field is properly justified, so the concordance output
can be readily observed. As a special feature, if automatic
references are selected by option @option{-A} and are output before the
left context, that is, if option @option{-R} is @emph{not} selected, then
-a colon is added after the reference; this nicely interfaces with @sc{gnu}
+a colon is added after the reference; this nicely interfaces with GNU
Emacs @code{next-error} processing. In this default output format, each
white space character, like newline and tab, is merely changed to
exactly one space, with no special attempt to compress consecutive
@@ -4702,16 +5404,20 @@ Output format is further controlled by the following options.
@item -g @var{number}
@itemx --gap-size=@var{number}
+@opindex -g
+@opindex --gap-size
Select the size of the minimum white space gap between the fields on the
output line.
@item -w @var{number}
@itemx --width=@var{number}
+@opindex -w
+@opindex --width
Select the maximum output width of each final line. If references are
used, they are included or excluded from the maximum output width
-depending on the value of option @option{-R}. If this option is not
+depending on the value of option @option{-R}@. If this option is not
selected, that is, when references are output before the left context,
the maximum output width takes into account the maximum length of all
references. If this option is selected, that is, when references are
@@ -4721,6 +5427,8 @@ them.
@item -A
@itemx --auto-reference
+@opindex -A
+@opindex --auto-reference
Select automatic references. Each input line will have an automatic
reference made up of the file name and the line ordinal, with a single
@@ -4731,6 +5439,8 @@ reference is used at output time, overriding the input reference.
@item -R
@itemx --right-side-refs
+@opindex -R
+@opindex --right-side-refs
In the default output format, when option @option{-R} is not used, any
references produced by the effect of options @option{-r} or @option{-A} are
@@ -4741,23 +5451,25 @@ context. For any other output format, option @option{-R} is
ignored, with one exception: with @option{-R} the width of references
is @emph{not} taken into account in total output width given by @option{-w}.
-This option is automatically selected whenever @sc{gnu} extensions are
+This option is automatically selected whenever GNU extensions are
disabled.
@item -F @var{string}
-@itemx --flac-truncation=@var{string}
+@itemx --flag-truncation=@var{string}
+@opindex -F
+@opindex --flag-truncation
This option will request that any truncation in the output be reported
using the string @var{string}. Most output fields theoretically extend
towards the beginning or the end of the current line, or current
-sentence, as selected with option @option{-S}. But there is a maximum
+sentence, as selected with option @option{-S}@. But there is a maximum
allowed output line width, changeable through option @option{-w}, which is
further divided into space for various output fields. When a field has
to be truncated because it cannot extend beyond the beginning or the end of
the current line to fit in, then a truncation occurs. By default,
the string used is a single slash, as in @option{-F /}.
-@var{string} may have more than one character, as in @option{-F ...}.
+@var{string} may have more than one character, as in @option{-F @dots{}}.
Also, in the particular case when @var{string} is empty (@option{-F ""}),
truncation flagging is disabled, and no truncation marks are appended in
this case.
@@ -4768,38 +5480,46 @@ the corresponding characters by @command{ptx} itself.
@item -M @var{string}
@itemx --macro-name=@var{string}
+@opindex -M
+@opindex --macro-name
Select another @var{string} to be used instead of @samp{xx}, while
generating output suitable for @command{nroff}, @command{troff} or @TeX{}.
@item -O
@itemx --format=roff
+@opindex -O
+@opindex --format=roff
Choose an output format suitable for @command{nroff} or @command{troff}
processing. Each output line will look like:
@smallexample
-.xx "@var{tail}" "@var{before}" "@var{keyword_and_after}" "@var{head}" "@var{ref}"
+.xx "@var{tail}" "@var{before}" "@var{keyword_and_after}"@c
+ "@var{head}" "@var{ref}"
@end smallexample
so it will be possible to write a @samp{.xx} roff macro to take care of
-the output typesetting. This is the default output format when @sc{gnu}
+the output typesetting. This is the default output format when GNU
extensions are disabled. Option @option{-M} can be used to change
@samp{xx} to another macro name.
In this output format, each non-graphical character, like newline and
tab, is merely changed to exactly one space, with no special attempt to
-compress consecutive spaces. Each quote character: @kbd{"} is doubled
+compress consecutive spaces. Each quote character @samp{"} is doubled
so it will be correctly processed by @command{nroff} or @command{troff}.
@item -T
@itemx --format=tex
+@opindex -T
+@opindex --format=tex
Choose an output format suitable for @TeX{} processing. Each output
line will look like:
@smallexample
-\xx @{@var{tail}@}@{@var{before}@}@{@var{keyword}@}@{@var{after}@}@{@var{head}@}@{@var{ref}@}
+\xx @{@var{tail}@}@{@var{before}@}@{@var{keyword}@}@c
+@{@var{after}@}@{@var{head}@}@{@var{ref}@}
@end smallexample
@noindent
@@ -4810,16 +5530,16 @@ selected, the last parameter of each @code{\xx} call is inhibited.
Option @option{-M} can be used to change @samp{xx} to another macro
name.
-In this output format, some special characters, like @kbd{$}, @kbd{%},
-@kbd{&}, @kbd{#} and @kbd{_} are automatically protected with a
-backslash. Curly brackets @kbd{@{}, @kbd{@}} are protected with a
+In this output format, some special characters, like @samp{$}, @samp{%},
+@samp{&}, @samp{#} and @samp{_} are automatically protected with a
+backslash. Curly brackets @samp{@{}, @samp{@}} are protected with a
backslash and a pair of dollar signs (to force mathematical mode). The
backslash itself produces the sequence @code{\backslash@{@}}.
Circumflex and tilde diacritical marks produce the sequence @code{^\@{ @}} and
@code{~\@{ @}} respectively. Other diacriticized characters of the
underlying character set produce an appropriate @TeX{} sequence as far
as possible. The other non-graphical characters, like newline and tab,
-and all other characters which are not part of @acronym{ASCII}, are merely
+and all other characters which are not part of ASCII, are merely
changed to exactly one space, with no special attempt to compress
consecutive spaces. Let me know how to improve this special character
processing for @TeX{}.
@@ -4828,13 +5548,13 @@ processing for @TeX{}.
@node Compatibility in ptx
-@subsection The @sc{gnu} extensions to @command{ptx}
+@subsection The GNU extensions to @command{ptx}
This version of @command{ptx} contains a few features which do not exist in
System V @command{ptx}. These extra features are suppressed by using the
@option{-G} command line option, unless overridden by other command line
-options. Some @sc{gnu} extensions cannot be recovered by overriding, so the
-simple rule is to avoid @option{-G} if you care about @sc{gnu} extensions.
+options. Some GNU extensions cannot be recovered by overriding, so the
+simple rule is to avoid @option{-G} if you care about GNU extensions.
Here are the differences between this program and System V @command{ptx}.
@itemize @bullet
@@ -4847,8 +5567,8 @@ or, if a second @var{file} parameter is given on the command, to that
@var{file}.
Having output parameters not introduced by options is a dangerous
-practice which @sc{gnu} avoids as far as possible. So, for using @command{ptx}
-portably between @sc{gnu} and System V, you should always use it with a
+practice which GNU avoids as far as possible. So, for using @command{ptx}
+portably between GNU and System V, you should always use it with a
single input file, and always expect the result on standard output. You
might also want to automatically configure in a @option{-G} option to
@command{ptx} calls in products using @command{ptx}, if the configurator finds
@@ -4857,9 +5577,9 @@ that the installed @command{ptx} accepts @option{-G}.
@item
The only options available in System V @command{ptx} are options @option{-b},
@option{-f}, @option{-g}, @option{-i}, @option{-o}, @option{-r}, @option{-t} and
-@option{-w}. All other options are @sc{gnu} extensions and are not repeated in
+@option{-w}. All other options are GNU extensions and are not repeated in
this enumeration. Moreover, some options have a slightly different
-meaning when @sc{gnu} extensions are enabled, as explained below.
+meaning when GNU extensions are enabled, as explained below.
@item
By default, concordance output is not formatted for @command{troff} or
@@ -4868,29 +5588,30 @@ or @command{nroff} output may still be selected through option @option{-O}.
@item
Unless @option{-R} option is used, the maximum reference width is
-subtracted from the total output line width. With @sc{gnu} extensions
+subtracted from the total output line width. With GNU extensions
disabled, width of references is not taken into account in the output
line width computations.
@item
-All 256 bytes, even null bytes, are always read and processed from
-input file with no adverse effect, even if @sc{gnu} extensions are disabled.
-However, System V @command{ptx} does not accept 8-bit characters, a few
-control characters are rejected, and the tilde @kbd{~} is also rejected.
+All 256 bytes, even ASCII NUL bytes, are always read and
+processed from input file with no adverse effect, even if GNU extensions
+are disabled. However, System V @command{ptx} does not accept 8-bit
+characters, a few control characters are rejected, and the tilde
+@samp{~} is also rejected.
@item
-Input line length is only limited by available memory, even if @sc{gnu}
+Input line length is only limited by available memory, even if GNU
extensions are disabled. However, System V @command{ptx} processes only
the first 200 characters in each line.
@item
The break (non-word) characters default to be every character except all
-letters of the underlying character set, diacriticized or not. When @sc{gnu}
+letters of the underlying character set, diacriticized or not. When GNU
extensions are disabled, the break characters default to space, tab and
newline only.
@item
-The program makes better use of output line width. If @sc{gnu} extensions
+The program makes better use of output line width. If GNU extensions
are disabled, the program rather tries to imitate System V @command{ptx},
but still, there are some slight disposition glitches this program does
not completely reproduce.
@@ -4902,8 +5623,166 @@ allowed with System V @command{ptx}.
@end itemize
-@node Operating on fields within a line
-@chapter Operating on fields within a line
+@node tsort invocation
+@section @command{tsort}: Topological sort
+
+@pindex tsort
+@cindex topological sort
+
+@command{tsort} performs a topological sort on the given @var{file}, or
+standard input if no input file is given or for a @var{file} of
+@samp{-}. For more details and some history, see @ref{tsort background}.
+Synopsis:
+
+@example
+tsort [@var{option}] [@var{file}]
+@end example
+
+@command{tsort} reads its input as pairs of strings, separated by blanks,
+indicating a partial ordering. The output is a total ordering that
+corresponds to the given partial ordering.
+
+For example
+
+@example
+tsort <<EOF
+a b c
+d
+e f
+b c d e
+EOF
+@end example
+
+@noindent
+will produce the output
+
+@example
+a
+b
+c
+d
+e
+f
+@end example
+
+Consider a more realistic example.
+You have a large set of functions all in one file, and they may all be
+declared static except one. Currently that one (say @code{main}) is the
+first function defined in the file, and the ones it calls directly follow
+it, followed by those they call, etc. Let's say that you are determined
+to take advantage of prototypes, so you have to choose between declaring
+all of those functions (which means duplicating a lot of information from
+the definitions) and rearranging the functions so that as many as possible
+are defined before they are used. One way to automate the latter process
+is to get a list for each function of the functions it calls directly.
+Many programs can generate such lists. They describe a call graph.
+Consider the following list, in which a given line indicates that the
+function on the left calls the one on the right directly.
+
+@example
+main parse_options
+main tail_file
+main tail_forever
+tail_file pretty_name
+tail_file write_header
+tail_file tail
+tail_forever recheck
+tail_forever pretty_name
+tail_forever write_header
+tail_forever dump_remainder
+tail tail_lines
+tail tail_bytes
+tail_lines start_lines
+tail_lines dump_remainder
+tail_lines file_lines
+tail_lines pipe_lines
+tail_bytes xlseek
+tail_bytes start_bytes
+tail_bytes dump_remainder
+tail_bytes pipe_bytes
+file_lines dump_remainder
+recheck pretty_name
+@end example
+
+then you can use @command{tsort} to produce an ordering of those
+functions that satisfies your requirement.
+
+@example
+example$ tsort call-graph | tac
+dump_remainder
+start_lines
+file_lines
+pipe_lines
+xlseek
+start_bytes
+pipe_bytes
+tail_lines
+tail_bytes
+pretty_name
+write_header
+tail
+recheck
+parse_options
+tail_file
+tail_forever
+main
+@end example
+
+@command{tsort} detects any cycles in the input and writes the first cycle
+encountered to standard error.
+
+Note that for a given partial ordering, generally there is no unique
+total ordering. In the context of the call graph above, the function
+@code{parse_options} may be placed anywhere in the list as long as it
+precedes @code{main}.
+
+The only options are @option{--help} and @option{--version}. @xref{Common
+options}.
+
+@exitstatus
+
+@menu
+* tsort background:: Where tsort came from.
+@end menu
+
+@node tsort background
+@subsection @command{tsort}: Background
+
+@command{tsort} exists because very early versions of the Unix linker processed
+an archive file exactly once, and in order. As @command{ld} read each object
+in the archive, it decided whether it was needed in the program based on
+whether it defined any symbols which were undefined at that point in
+the link.
+
+This meant that dependencies within the archive had to be handled
+specially. For example, @code{scanf} probably calls @code{read}. That means
+that in a single pass through an archive, it was important for @code{scanf.o}
+to appear before read.o, because otherwise a program which calls
+@code{scanf} but not @code{read} might end up with an unexpected unresolved
+reference to @code{read}.
+
+The way to address this problem was to first generate a set of
+dependencies of one object file on another. This was done by a shell
+script called @command{lorder}. The GNU tools don't provide a version of
+lorder, as far as I know, but you can still find it in BSD
+distributions.
+
+Then you ran @command{tsort} over the @command{lorder} output, and you used the
+resulting sort to define the order in which you added objects to the archive.
+
+This whole procedure has been obsolete since about 1980, because
+Unix archives now contain a symbol table (traditionally built by
+@command{ranlib}, now generally built by @command{ar} itself), and the Unix
+linker uses the symbol table to effectively make multiple passes over
+an archive file.
+
+Anyhow, that's where tsort came from. To solve an old problem with
+the way the linker handled archive files, which has since been solved
+in different ways.
+
+
+@node Operating on fields
+@chapter Operating on fields
@menu
* cut invocation:: Print selected parts of lines.
@@ -4921,7 +5800,7 @@ input file, or standard input if no files are given or for a file name of
@samp{-}. Synopsis:
@example
-cut [@var{option}]@dots{} [@var{file}]@dots{}
+cut @var{option}@dots{} [@var{file}]@dots{}
@end example
In the table which follows, the @var{byte-list}, @var{character-list},
@@ -4968,7 +5847,28 @@ of selected bytes.
Select for printing only the fields listed in @var{field-list}.
Fields are separated by a TAB character by default. Also print any
line that contains no delimiter character, unless the
-@option{--only-delimited} (@option{-s}) option is specified
+@option{--only-delimited} (@option{-s}) option is specified.
+
+Note @command{awk} supports more sophisticated field processing,
+and by default will use (and discard) runs of blank characters to
+separate fields, and ignore leading and trailing blanks.
+@example
+@verbatim
+awk '{print $2}' # print the second field
+awk '{print $NF-1}' # print the penultimate field
+awk '{print $2,$1}' # reorder the first two fields
+@end verbatim
+@end example
+
+In the unlikely event that @command{awk} is unavailable,
+one can use the @command{join} command, to process blank
+characters as @command{awk} does above.
+@example
+@verbatim
+join -a1 -o 1.2 - /dev/null # print the second field
+join -a1 -o 1.2,1.1 - /dev/null # reorder the first two fields
+@end verbatim
+@end example
@item -d @var{input_delim_byte}
@itemx --delimiter=@var{input_delim_byte}
@@ -4999,13 +5899,15 @@ ranges of selected bytes.
@item --complement
@opindex --complement
-This option is a @acronym{GNU} extension.
+This option is a GNU extension.
Select for printing the complement of the bytes, characters or fields
selected with the @option{-b}, @option{-c} or @option{-f} options.
In other words, do @emph{not} print the bytes, characters or fields
specified via those options. This option is useful when you have
many fields and want to print all but a few of them.
+@optZeroTerminated
+
@end table
@exitstatus
@@ -5022,8 +5924,13 @@ corresponding lines of each given file, separated by a TAB character.
Standard input is used for a file name of @samp{-} or if no input files
are given.
-For example:
+Synopsis:
+
+@example
+paste [@var{option}]@dots{} [@var{file}]@dots{}
+@end example
+For example, with:
@example
$ cat num2
1
@@ -5032,16 +5939,37 @@ $ cat let3
a
b
c
+@end example
+
+Take lines sequentially from each file:
+@example
$ paste num2 let3
1 a
2 b
@ c
@end example
-Synopsis:
+Duplicate lines from a file:
+@example
+$ paste num2 let3 num2
+1 a 1
+2 b 2
+ @ c
+@end example
+Intermix lines from stdin:
@example
-paste [@var{option}]@dots{} [@var{file}]@dots{}
+$ paste - let3 - < num2
+1 a 2
+ @ b
+ @ c
+@end example
+
+Join consecutive lines with a space:
+@example
+$ seq 4 | paste -d ' ' - -
+1 2
+3 4
@end example
The program accepts the following options. Also see @ref{Common options}.
@@ -5076,6 +6004,8 @@ $ paste -d '%_' num2 let3 num2
%c_
@end example
+@optZeroTerminated
+
@end table
@exitstatus
@@ -5112,11 +6042,13 @@ locales and options if the output of @command{sort} is fed to
sort a file on its default join field, but if you select a non-default
locale, join field, separator, or comparison options, then you should
do so consistently between @command{join} and @command{sort}.
+If @samp{join -t ''} is specified then the whole line is considered which
+matches the default operation of sort.
-As a @acronym{GNU} extension, if the input has no unpairable lines the
-sort order can be any order that considers two fields to be equal if and
-only if the sort comparison described above considers them to be equal.
-For example:
+If the input has no unpairable lines, a GNU extension is
+available; the sort order can be any order that considers two fields
+to be equal if and only if the sort comparison described above
+considers them to be equal. For example:
@example
$ cat file1
@@ -5133,11 +6065,15 @@ c c1 c2
b b1 b2
@end example
+@set JOIN_COMMAND
+@checkOrderOption{join}
+@clear JOIN_COMMAND
+
The defaults are:
@itemize
@item the join field is the first field in each line;
@item fields in the input are separated by one or more blanks, with leading
- blanks on the line ignored;
+blanks on the line ignored;
@item fields in the output are separated by a space;
@item each output line consists of the join field, the remaining
fields from @var{file1}, then the remaining fields from @var{file2}.
@@ -5152,10 +6088,25 @@ The program accepts the following options. Also see @ref{Common options}.
Print a line for each unpairable line in file @var{file-number} (either
@samp{1} or @samp{2}), in addition to the normal output.
+@item --check-order
+Fail with an error message if either input file is wrongly ordered.
+
+@item --nocheck-order
+Do not check that both input files are in sorted order. This is the default.
+
@item -e @var{string}
@opindex -e
-Replace those output fields that are missing in the input with
-@var{string}.
+Replace those output fields that are missing in the input with @var{string}.
+I.e., missing fields specified with the @option{-12jo} options.
+
+@item --header
+@opindex --header
+Treat the first line of each input file as a header line. The header lines
+will be joined and printed as the first output line. If @option{-o} is used to
+specify output format, the header line will be printed according to the
+specified format. The header lines will not be checked for ordering even if
+@option{--check-order} is specified. Also if the header lines from each file
+do not match, the heading fields from the first file will be used.
@item -i
@itemx --ignore-case
@@ -5177,10 +6128,17 @@ Join on field @var{field} (a positive integer) of file 2.
Equivalent to @option{-1 @var{field} -2 @var{field}}.
@item -o @var{field-list}
-Construct each output line according to the format in @var{field-list}.
-Each element in @var{field-list} is either the single character @samp{0} or
-has the form @var{m.n} where the file number, @var{m}, is @samp{1} or
-@samp{2} and @var{n} is a positive field number.
+@itemx -o auto
+If the keyword @samp{auto} is specified, infer the output format from
+the first line in each file. This is the same as the default output format
+but also ensures the same number of fields are output for each line.
+Missing fields are replaced with the @option{-e} option and extra fields
+are discarded.
+
+Otherwise, construct each output line according to the format in
+@var{field-list}. Each element in @var{field-list} is either the single
+character @samp{0} or has the form @var{m.n} where the file number, @var{m},
+is @samp{1} or @samp{2} and @var{n} is a positive field number.
A field specification of @samp{0} denotes the join field.
In most cases, the functionality of the @samp{0} field spec
@@ -5189,7 +6147,7 @@ to the join field. However, when printing unpairable lines
(using either of the @option{-a} or @option{-v} options), there is no way
to specify the join field using @var{m.n} in @var{field-list}
if there are unpairable lines in both files.
-To give @command{join} that functionality, @acronym{POSIX} invented the @samp{0}
+To give @command{join} that functionality, POSIX invented the @samp{0}
field specification notation.
The elements in @var{field-list}
@@ -5205,12 +6163,18 @@ option---are subject to the specified @var{field-list}.
Use character @var{char} as the input and output field separator.
Treat as significant each occurrence of @var{char} in the input file.
Use @samp{sort -t @var{char}}, without the @option{-b} option of
-@samp{sort}, to produce this ordering.
+@samp{sort}, to produce this ordering. If @samp{join -t ''} is specified,
+the whole line is considered, matching the default operation of sort.
+If @samp{-t '\0'} is specified then the ASCII NUL
+character is used to delimit the fields.
@item -v @var{file-number}
Print a line for each unpairable line in file @var{file-number}
(either @samp{1} or @samp{2}), instead of the normal output.
+@optZeroTerminated
+@newlineFieldSeparator
+
@end table
@exitstatus
@@ -5221,7 +6185,7 @@ Print a line for each unpairable line in file @var{file-number}
@cindex operating on characters
-This commands operate on individual characters.
+These commands operate on individual characters.
@menu
* tr invocation:: Translate, squeeze, and/or delete characters.
@@ -5278,7 +6242,7 @@ options. @xref{Common options}. Options must precede operands.
@menu
* Character sets:: Specifying sets of characters.
* Translating:: Changing one set of characters to another.
-* Squeezing:: Squeezing repeats and deleting.
+* Squeezing and deleting:: Removing characters.
@end menu
@@ -5317,8 +6281,9 @@ Control-I.
@item \v
Control-K.
@item \@var{ooo}
-The character with the value given by @var{ooo}, which is 1 to 3
-octal digits,
+The 8-bit character with the value given by @var{ooo}, which is 1 to 3
+octal digits. Note that @samp{\400} is interpreted as the two-byte
+sequence, @samp{\040} @samp{0}.
@item \\
A backslash.
@end table
@@ -5336,7 +6301,7 @@ from @var{m} through @var{n}, in ascending order. @var{m} should
collate before @var{n}; if it doesn't, an error results. As an example,
@samp{0-9} is the same as @samp{0123456789}.
-@sc{gnu} @command{tr} does not support the System V syntax that uses square
+GNU @command{tr} does not support the System V syntax that uses square
brackets to enclose ranges. Translations specified in that format
sometimes work as expected, since the brackets are often transliterated
to themselves. However, they should be avoided because they sometimes
@@ -5344,10 +6309,10 @@ behave unexpectedly. For example, @samp{tr -d '[0-9]'} deletes brackets
as well as digits.
Many historically common and even accepted uses of ranges are not
-portable. For example, on @acronym{EBCDIC} hosts using the @samp{A-Z}
+portable. For example, on EBCDIC hosts using the @samp{A-Z}
range will not do what most would expect because @samp{A} through @samp{Z}
-are not contiguous as they are in @acronym{ASCII}.
-If you can rely on a @acronym{POSIX} compliant version of @command{tr}, then
+are not contiguous as they are in ASCII@.
+If you can rely on a POSIX compliant version of @command{tr}, then
the best way to work around this is to use character classes (see below).
Otherwise, it is most portable (and most ugly) to enumerate the members
of the ranges.
@@ -5424,7 +6389,7 @@ The syntax @samp{[=@var{c}=]} expands to all of the characters that are
equivalent to @var{c}, in no particular order. Equivalence classes are
a relatively recent invention intended to support non-English alphabets.
But there seems to be no standard way to define them or determine their
-contents. Therefore, they are not fully implemented in @sc{gnu} @command{tr};
+contents. Therefore, they are not fully implemented in GNU @command{tr};
each character's equivalence class consists only of that character,
which is of no particular use.
@@ -5467,14 +6432,14 @@ typically have the same length. If @var{set1} is shorter than
@var{set2}, the extra characters at the end of @var{set2} are ignored.
On the other hand, making @var{set1} longer than @var{set2} is not
-portable; @acronym{POSIX} says that the result is undefined. In this situation,
+portable; POSIX says that the result is undefined. In this situation,
BSD @command{tr} pads @var{set2} to the length of @var{set1} by repeating
the last character of @var{set2} as many times as necessary. System V
@command{tr} truncates @var{set1} to the length of @var{set2}.
-By default, @sc{gnu} @command{tr} handles this case like BSD @command{tr}.
+By default, GNU @command{tr} handles this case like BSD @command{tr}.
When the @option{--truncate-set1} (@option{-t}) option is given,
-@sc{gnu} @command{tr} handles this case like the System V @command{tr}
+GNU @command{tr} handles this case like the System V @command{tr}
instead. This option is ignored for operations other than translation.
Acting like System V @command{tr} in this case breaks the relatively common
@@ -5492,25 +6457,28 @@ newlines.
@noindent
By the way, the above idiom is not portable because it uses ranges, and
it assumes that the octal code for newline is 012.
-Assuming a @acronym{POSIX} compliant @command{tr}, here is a better way to write it:
+Assuming a POSIX compliant @command{tr}, here is a better
+way to write it:
@example
tr -cs '[:alnum:]' '[\n*]'
@end example
-@node Squeezing
+@node Squeezing and deleting
@subsection Squeezing repeats and deleting
@cindex squeezing repeat characters
@cindex deleting characters
+@cindex removing characters
When given just the @option{--delete} (@option{-d}) option, @command{tr}
removes any input characters that are in @var{set1}.
-When given just the @option{--squeeze-repeats} (@option{-s}) option,
-@command{tr} replaces each input sequence of a repeated character that
-is in @var{set1} with a single occurrence of that character.
+When given just the @option{--squeeze-repeats} (@option{-s}) option
+and not translating, @command{tr} replaces each input sequence of a
+repeated character that is in @var{set1} with a single occurrence of
+that character.
When given both @option{--delete} and @option{--squeeze-repeats}, @command{tr}
first performs any deletions using @var{set1}, then squeezes repeats
@@ -5541,7 +6509,8 @@ tr -cs '[:alnum:]' '[\n*]'
@end example
@item
-Convert each sequence of repeated newlines to a single newline:
+Convert each sequence of repeated newlines to a single newline.
+I.e., delete blank lines:
@example
tr -s '\n'
@@ -5669,7 +6638,7 @@ characters) on each line to spaces.
@command{unexpand} writes the contents of each given @var{file}, or
standard input if none are given or for a @var{file} of @samp{-}, to
standard output, converting blanks at the beginning of each line into
-as many tab characters as needed. In the default @acronym{POSIX}
+as many tab characters as needed. In the default POSIX
locale, a @dfn{blank} is a space or a tab; other locales may specify
additional blank characters. Synopsis:
@@ -5748,7 +6717,7 @@ directory, acting as if it had been invoked with a single argument of @samp{.}.
@vindex LC_ALL
By default, the output is sorted alphabetically, according to the locale
-settings in effect.@footnote{If you use a non-@acronym{POSIX}
+settings in effect.@footnote{If you use a non-POSIX
locale (e.g., by setting @env{LC_ALL} to @samp{en_US}), then @command{ls} may
produce output that is sorted differently than you're accustomed to.
In that case, set the @env{LC_ALL} environment variable to @samp{C}.}
@@ -5768,8 +6737,12 @@ Exit status:
@display
0 success
-1 minor problems (e.g., a subdirectory was not found)
-2 serious trouble (e.g., memory exhausted)
+1 minor problems (e.g., failure to access a file or directory not
+ specified as a command line argument. This happens when listing a
+ directory in which entries are actively being removed or renamed.)
+2 serious trouble (e.g., memory exhausted, invalid option, failure
+ to access a file or directory specified as a command line argument
+ or a directory loop)
@end display
Also see @ref{Common options}.
@@ -5778,7 +6751,7 @@ Also see @ref{Common options}.
* Which files are listed::
* What information is listed::
* Sorting the output::
-* More details about version sort::
+* Details about version sort::
* General output formatting::
* Formatting file timestamps::
* Formatting the file names::
@@ -5837,7 +6810,7 @@ command line unless the @option{--dereference-command-line} (@option{-H}),
If a command line argument specifies a symbolic link, show information
for the file the link references rather than for the link itself.
-@itemx --dereference-command-line-symlink-to-dir
+@item --dereference-command-line-symlink-to-dir
@opindex --dereference-command-line-symlink-to-dir
@cindex symbolic links, dereferencing
Do not dereference symbolic links, with one exception:
@@ -5858,6 +6831,8 @@ directories and the files separately using the selected sort key
(see --sort option).
That is, this option specifies a primary sort key,
and the --sort option specifies a secondary key.
+However, any use of @option{--sort=none}
+(@option{-U}) disables this option altogether.
@item --hide=PATTERN
@opindex --hide=@var{pattern}
@@ -5940,7 +6915,7 @@ the main output:
@end example
@noindent
-The @var{begN} and @var{endN} are unsigned integers that record the
+The @var{begn} and @var{endn} are unsigned integers that record the
byte position of the beginning and end of each file name in the output.
This makes it easy for Emacs to find the names, even when they contain
unusual characters such as space or newline, without fancy searching.
@@ -6023,7 +6998,7 @@ $ ls -blog --dired 'a b'
If you use a quoting style that adds quote marks
(e.g., @option{--quoting-style=c}), then the offsets include the quote marks.
So beware that the user may select the quoting style via the environment
-variable @env{QUOTING_STYLE}. Hence, applications using @option{--dired}
+variable @env{QUOTING_STYLE}@. Hence, applications using @option{--dired}
should either specify an explicit @option{--quoting-style=literal} option
(aka @option{-N} or @option{--literal}) on the command line, or else be
prepared to parse the escaped names.
@@ -6043,7 +7018,7 @@ Produce long format directory listings, but don't display owner information.
@opindex -G
@opindex --no-group
Inhibit display of group information in a long format directory listing.
-(This is the default in some non-@sc{gnu} versions of @command{ls}, so we
+(This is the default in some non-GNU versions of @command{ls}, so we
provide this option for compatibility.)
@optHumanReadable
@@ -6164,9 +7139,11 @@ applies to the file. When the character following the file mode bits is a
space, there is no alternate access method. When it is a printing
character, then there is such a method.
-For a file with an extended access control list, a @samp{+} character is
-listed. Basic access control lists are equivalent to the permissions
-listed, and are not considered an alternate access method.
+GNU @command{ls} uses a @samp{.} character to indicate a file
+with a security context, but no other alternate access method.
+
+A file with any other combination of alternate access methods
+is marked with a @samp{+} character.
@item -n
@itemx --numeric-uid-gid
@@ -6204,6 +7181,16 @@ it also affects the HP-UX @command{ls} program.
@optSi
+@item -Z
+@itemx --context
+@opindex -Z
+@opindex --context
+@cindex SELinux
+@cindex security context
+Display the SELinux security context or @samp{?} if none is found.
+When used with the @option{-l} option, print the security context
+to the left of the size column.
+
@end table
@@ -6213,7 +7200,7 @@ it also affects the HP-UX @command{ls} program.
@cindex sorting @command{ls} output
These options change the order in which @command{ls} sorts the information
it outputs. By default, sorting is done by character code
-(e.g., @acronym{ASCII} order).
+(e.g., ASCII order).
@table @samp
@@ -6294,7 +7281,7 @@ directories, since not doing any sorting can be noticeably faster.
@opindex version@r{, sorting option for @command{ls}}
Sort by version name and number, lowest first. It behaves like a default
sort, except that each sequence of decimal digits is treated numerically
-as an index/version number. (@xref{More details about version sort}.)
+as an index/version number. (@xref{Details about version sort}.)
@item -X
@itemx --sort=extension
@@ -6307,43 +7294,59 @@ after the last @samp{.}); files with no extension are sorted first.
@end table
-@node More details about version sort
-@subsection More details about version sort
+@node Details about version sort
+@subsection Details about version sort
-The version sort takes into account the fact that file names frequently include
-indices or version numbers. Standard sorting functions usually do not produce
-the ordering that people expect because comparisons are made on a
-character-by-character basis. The version
-sort addresses this problem, and is especially useful when browsing
-directories that contain many files with indices/version numbers in their
-names:
+Version sorting handles the fact that file names frequently include indices or
+version numbers. Standard sorting usually does not produce the order that one
+expects because comparisons are made on a character-by-character basis.
+Version sorting is especially useful when browsing directories that contain
+many files with indices/version numbers in their names:
@example
$ ls -1 $ ls -1v
-foo.zml-1.gz foo.zml-1.gz
-foo.zml-100.gz foo.zml-2.gz
-foo.zml-12.gz foo.zml-6.gz
-foo.zml-13.gz foo.zml-12.gz
-foo.zml-2.gz foo.zml-13.gz
-foo.zml-25.gz foo.zml-25.gz
-foo.zml-6.gz foo.zml-100.gz
+abc.zml-1.gz abc.zml-1.gz
+abc.zml-12.gz abc.zml-2.gz
+abc.zml-2.gz abc.zml-12.gz
@end example
-Note also that numeric parts with leading zeros are considered as
-fractional one:
+Version-sorted strings are compared such that if @var{ver1} and @var{ver2}
+are version numbers and @var{prefix} and @var{suffix} (@var{suffix} matching
+the regular expression @samp{(\.[A-Za-z~][A-Za-z0-9~]*)*}) are strings then
+@var{ver1} < @var{ver2} implies that the name composed of
+``@var{prefix} @var{ver1} @var{suffix}'' sorts before
+``@var{prefix} @var{ver2} @var{suffix}''.
+
+Note also that leading zeros of numeric parts are ignored:
@example
$ ls -1 $ ls -1v
-abc-1.007.tgz abc-1.007.tgz
-abc-1.012b.tgz abc-1.01a.tgz
+abc-1.007.tgz abc-1.01a.tgz
+abc-1.012b.tgz abc-1.007.tgz
abc-1.01a.tgz abc-1.012b.tgz
@end example
-This functionality is implemented using the @code{strverscmp} function.
-@xref{String/Array Comparison, , , libc, The GNU C Library Reference Manual}.
-One result of that implementation decision is that @code{ls -v} does not
-use the locale category, @env{LC_COLLATE}. As a result, non-numeric prefixes
-are sorted as if @env{LC_COLLATE} were set to @code{C}.
+This functionality is implemented using gnulib's @code{filevercmp} function,
+which has some caveats worth noting.
+
+@itemize @bullet
+@item @env{LC_COLLATE} is ignored, which means @samp{ls -v} and @samp{sort -V}
+will sort non-numeric prefixes as if the @env{LC_COLLATE} locale category
+was set to @samp{C}@.
+@item Some suffixes will not be matched by the regular
+expression mentioned above. Consequently these examples may
+not sort as you expect:
+
+@example
+abc-1.2.3.4.7z
+abc-1.2.3.7z
+@end example
+
+@example
+abc-1.2.3.4.x86_64.rpm
+abc-1.2.3.x86_64.rpm
+@end example
+@end itemize
@node General output formatting
@subsection General output formatting
@@ -6358,7 +7361,8 @@ These options affect the appearance of the overall output.
@opindex --format
@opindex single-column @r{output of files}
List one file per line. This is the default for @command{ls} when standard
-output is not a terminal.
+output is not a terminal. See also the @option{-b} and @option{-q} options
+to suppress direct output of newline characters within a file name.
@item -C
@itemx --format=vertical
@@ -6368,7 +7372,7 @@ output is not a terminal.
List files in columns, sorted vertically. This is the default for
@command{ls} if standard output is a terminal. It is always the default
for the @command{dir} program.
-@sc{gnu} @command{ls} uses variable width columns to display as many files as
+GNU @command{ls} uses variable width columns to display as many files as
possible in the fewest lines.
@item --color [=@var{when}]
@@ -6394,6 +7398,23 @@ Piping a colorized listing through a pager like @command{more} or
@command{less} usually produces unreadable results. However, using
@code{more -f} does seem to work.
+@vindex LS_COLORS
+@vindex SHELL @r{environment variable, and color}
+Note that using the @option{--color} option may incur a noticeable
+performance penalty when run in a directory with very many entries,
+because the default settings require that @command{ls} @code{stat} every
+single file it lists.
+However, if you would like most of the file-type coloring
+but can live without the other coloring options (e.g.,
+executable, orphan, sticky, other-writable, capability), use
+@command{dircolors} to set the @env{LS_COLORS} environment variable like this,
+@example
+eval $(dircolors -p | perl -pe \
+ 's/^((CAP|S[ET]|O[TR]|M|E)\w+).*/$1 00/' | dircolors -)
+@end example
+and on a @code{dirent.d_type}-capable file system, @command{ls}
+will perform only one @code{stat} call per command line argument.
+
@item -F
@itemx --classify
@itemx --indicator-style=classify
@@ -6443,10 +7464,19 @@ Append @samp{*} for executable regular files, otherwise behave as for
@end table
@item -k
+@itemx --kibibytes
@opindex -k
-Print file sizes in 1024-byte blocks, overriding the default block
-size (@pxref{Block size}).
-This option is equivalent to @option{--block-size=1K}.
+@opindex --kibibytes
+Set the default block size to its normal value of 1024 bytes,
+overriding any contrary specification in environment variables
+(@pxref{Block size}). This option is in turn overridden by the
+@option{--block-size}, @option{-h} or @option{--human-readable}, and
+@option{--si} options.
+
+The @option{-k} or @option{--kibibytes} option affects the
+per-directory block count written by the @option{-l} and similar
+options, and the size written by the @option{-s} or @option{--size}
+option. It does not affect the file size written by @option{-l}.
@item -m
@itemx --format=commas
@@ -6480,14 +7510,12 @@ Assume that each tab stop is @var{cols} columns wide. The default is 8.
@command{ls} uses tabs where possible in the output, for efficiency. If
@var{cols} is zero, do not use tabs at all.
-@c FIXME: remove in 2009, if Apple Terminal has been fixed for long enough.
-Some terminal emulators (at least Apple Terminal 1.5 (133) from Mac OS X 10.4.8)
-do not properly align columns to the right of a TAB following a
-non-@acronym{ASCII} byte. If you use such a terminal emulator, use the
-@option{-T0} option or put @code{TABSIZE=0} in your environment to tell
+Some terminal emulators might not properly align columns to the right of a
+TAB following a non-ASCII byte. You can avoid that issue by using the
+@option{-T0} option or put @code{TABSIZE=0} in your environment, to tell
@command{ls} to align using spaces, not tabs.
-@item -w
+@item -w @var{cols}
@itemx --width=@var{cols}
@opindex -w
@opindex --width
@@ -6495,7 +7523,9 @@ non-@acronym{ASCII} byte. If you use such a terminal emulator, use the
Assume the screen is @var{cols} columns wide. The default is taken
from the terminal settings if possible; otherwise the environment
variable @env{COLUMNS} is used if it is set; otherwise the default
-is 80.
+is 80. With a @var{cols} value of @samp{0}, there is no limit on
+the length of the output line, and that single output line will
+be delimited with spaces, not tabs.
@end table
@@ -6503,12 +7533,12 @@ is 80.
@node Formatting file timestamps
@subsection Formatting file timestamps
-By default, file timestamps are listed in abbreviated form. Most
-locales use a timestamp like @samp{2002-03-30 23:45}. However, the
-default @acronym{POSIX} locale uses a date like @samp{Mar 30@ @ 2002}
-for non-recent timestamps, and a date-without-year and time like
-@samp{Mar 30 23:45} for recent timestamps.
+By default, file timestamps are listed in abbreviated form, using
+a date like @samp{Mar 30@ @ 2002} for non-recent timestamps, and a
+date-without-year and time like @samp{Mar 30 23:45} for recent timestamps.
+This format can change depending on the current locale as detailed below.
+@cindex clock skew
A timestamp is considered to be @dfn{recent} if it is less than six
months old, and is not dated in the future. If a timestamp dated
today is not listed in recent form, the timestamp is in the future,
@@ -6519,7 +7549,7 @@ programs like @command{make} that rely on file timestamps.
Time stamps are listed according to the time zone rules specified by
the @env{TZ} environment variable, or by the system default rules if
@env{TZ} is not set. @xref{TZ Variable,, Specifying the Time Zone
-with @env{TZ}, libc, The GNU C Library}.
+with @env{TZ}, libc, The GNU C Library Reference Manual}.
The following option changes how file timestamps are printed.
@@ -6546,25 +7576,25 @@ files; if you want output columns to line up, you may need to insert
spaces in one of the two formats.
@item full-iso
-List timestamps in full using @acronym{ISO} 8601 date, time, and time zone
-format with nanosecond precision, e.g., @samp{2002-03-30
+List timestamps in full using ISO 8601 date, time, and time zone
+components with nanosecond precision, e.g., @samp{2002-03-30
23:45:56.477817180 -0700}. This style is equivalent to
@samp{+%Y-%m-%d %H:%M:%S.%N %z}.
This is useful because the time output includes all the information that
is available from the operating system. For example, this can help
-explain @command{make}'s behavior, since @acronym{GNU} @command{make}
+explain @command{make}'s behavior, since GNU @command{make}
uses the full timestamp to determine whether a file is out of date.
@item long-iso
-List @acronym{ISO} 8601 date and time in minutes, e.g.,
+List ISO 8601 date and time components with minute precision, e.g.,
@samp{2002-03-30 23:45}. These timestamps are shorter than
@samp{full-iso} timestamps, and are usually good enough for everyday
work. This style is equivalent to @samp{+%Y-%m-%d %H:%M}.
@item iso
-List @acronym{ISO} 8601 dates for non-recent timestamps (e.g.,
-@samp{2002-03-30@ }), and @acronym{ISO} 8601 month, day, hour, and
+List ISO 8601 dates for non-recent timestamps (e.g.,
+@samp{2002-03-30@ }), and ISO 8601-like month, day, hour, and
minute for recent timestamps (e.g., @samp{03-30 23:45}). These
timestamps are uglier than @samp{long-iso} timestamps, but they carry
nearly the same information in a smaller space and their brevity helps
@@ -6588,7 +7618,7 @@ are harder for programs to parse because locale conventions vary so
widely, but they are easier for many people to read.
The @env{LC_TIME} locale category specifies the timestamp format. The
-default @acronym{POSIX} locale uses timestamps like @samp{Mar 30@
+default POSIX locale uses timestamps like @samp{Mar 30@
@ 2002} and @samp{Mar 30 23:45}; in this locale, the following two
@command{ls} invocations are equivalent:
@@ -6607,21 +7637,21 @@ and might generate timestamps like @samp{30. M@"ar 2002@ } and
@item posix-@var{style}
@vindex LC_TIME
-List @acronym{POSIX}-locale timestamps if the @env{LC_TIME} locale
-category is @acronym{POSIX}, @var{style} timestamps otherwise. For
+List POSIX-locale timestamps if the @env{LC_TIME} locale
+category is POSIX, @var{style} timestamps otherwise. For
example, the @samp{posix-long-iso} style lists
timestamps like @samp{Mar 30@ @ 2002} and @samp{Mar 30 23:45} when in
-the @acronym{POSIX} locale, and like @samp{2002-03-30 23:45} otherwise.
+the POSIX locale, and like @samp{2002-03-30 23:45} otherwise.
@end table
@end table
@vindex TIME_STYLE
You can specify the default value of the @option{--time-style} option
with the environment variable @env{TIME_STYLE}; if @env{TIME_STYLE} is not set
-the default style is @samp{locale}. @acronym{GNU} Emacs 21.3 and
+the default style is @samp{locale}. GNU Emacs 21.3 and
later use the @option{--dired} option and therefore can parse any date
format, but if you are using Emacs 21.1 or 21.2 and specify a
-non-@acronym{POSIX} locale you may need to set
+non-POSIX locale you may need to set
@samp{TIME_STYLE="posix-long-iso"}.
To avoid certain denial-of-service attacks, timestamps that would be
@@ -6687,11 +7717,17 @@ Output strings as-is; this is the same as the @option{-N} or
@item shell
Quote strings for the shell if they contain shell metacharacters or would
cause ambiguous output.
-The quoting is suitable for @acronym{POSIX}-compatible shells like
+The quoting is suitable for POSIX-compatible shells like
@command{bash}, but it does not always work for incompatible shells
like @command{csh}.
@item shell-always
Quote strings for the shell, even if they would normally not require quoting.
+@item shell-escape
+Like @samp{shell}, but also quoting non-printable characters using the POSIX
+proposed @samp{$''} syntax suitable for most shells.
+@item shell-escape-always
+Like @samp{shell-escape}, but quote strings even if they would
+normally not require quoting.
@item c
Quote strings as for C character string literals, including the
surrounding double-quote characters; this is the same as the
@@ -6708,14 +7744,14 @@ locale.
@c Use @t instead of @samp to avoid duplicate quoting in some output styles.
Quote strings as for C character string literals, except use
surrounding quotation marks appropriate for the locale, and quote
-@t{`like this'} instead of @t{"like
+@t{'like this'} instead of @t{"like
this"} in the default C locale. This looks nicer on many displays.
@end table
You can specify the default value of the @option{--quoting-style} option
-with the environment variable @env{QUOTING_STYLE}. If that environment
-variable is not set, the default value is @samp{literal}, but this
-default may change to @samp{shell} in a future version of this package.
+with the environment variable @env{QUOTING_STYLE}@. If that environment
+variable is not set, the default value is @samp{shell-escape} when the
+output is a terminal, and @samp{literal} otherwise.
@item --show-control-chars
@opindex --show-control-chars
@@ -6749,6 +7785,8 @@ and special characters are represented by backslash escape sequences.
-b}; that is, by default files are listed in long format and special
characters are represented by backslash escape sequences.
+@xref{ls invocation, @command{ls}}.
+
@node dircolors invocation
@section @command{dircolors}: Color setup for @command{ls}
@@ -6761,7 +7799,7 @@ terminal for color output from @command{ls} (and @command{dir}, etc.).
Typical usage:
@example
-eval "`dircolors [@var{option}]@dots{} [@var{file}]`"
+eval "$(dircolors [@var{option}]@dots{} [@var{file}])"
@end example
If @var{file} is specified, @command{dircolors} reads it to determine which
@@ -6769,6 +7807,15 @@ colors to use for which file types and extensions. Otherwise, a
precompiled database is used. For details on the format of these files,
run @samp{dircolors --print-database}.
+To make @command{dircolors} read a @file{~/.dircolors} file if it
+exists, you can put the following lines in your @file{~/.bashrc} (or
+adapt them to your favorite shell):
+
+@example
+d=.dircolors
+test -r $d && eval "$(dircolors $d)"
+@end example
+
@vindex LS_COLORS
@vindex SHELL @r{environment variable, and color}
The output is a shell command to set the @env{LS_COLORS} environment
@@ -6876,13 +7923,27 @@ By default, @command{cp} does not copy directories. However, the
copy recursively by descending into source directories and copying files
to corresponding destination directories.
-By default, @command{cp} follows symbolic links only when not copying
-recursively. This default can be overridden with the
+When copying from a symbolic link, @command{cp} normally follows the
+link only when not copying recursively or when @option{--link}
+(@option{-l}) is used. This default can be overridden with the
@option{--archive} (@option{-a}), @option{-d}, @option{--dereference}
(@option{-L}), @option{--no-dereference} (@option{-P}), and
@option{-H} options. If more than one of these options is specified,
the last one silently overrides the others.
+When copying to a symbolic link, @command{cp} follows the
+link only when it refers to an existing regular file.
+However, when copying to a dangling symbolic link, @command{cp}
+refuses by default, and fails with a diagnostic, since the operation
+is inherently dangerous. This behavior is contrary to historical
+practice and to POSIX@.
+Set @env{POSIXLY_CORRECT} to make @command{cp} attempt to create
+the target of a dangling destination symlink, in spite of the possible risk.
+Also, when an option like
+@option{--backup} or @option{--link} acts to rename or remove the
+destination before copying, @command{cp} renames or removes the
+symbolic link rather than the file it points to.
+
By default, @command{cp} copies the contents of special files only
when not copying recursively. This default can be overridden with the
@option{--copy-contents} option.
@@ -6907,10 +7968,18 @@ Preserve as much as possible of the structure and attributes of the
original files in the copy (but do not attempt to preserve internal
directory structure; i.e., @samp{ls -U} may list the entries in a copied
directory in a different order).
-Equivalent to @option{-dpPR}.
+Try to preserve SELinux security context and extended attributes (xattr),
+but ignore any failure to do that and print no corresponding diagnostic.
+Equivalent to @option{-dR --preserve=all} with the reduced diagnostics.
+
+@item --attributes-only
+@opindex --attributes-only
+Copy only the specified attributes of the source file to the destination.
+If the destination already exists, do not alter its contents.
+See the @option{--preserve} option for controlling which attributes to copy.
@item -b
-@itemx @w{@kbd{--backup}[=@var{method}]}
+@itemx --backup[=@var{method}]
@opindex -b
@opindex --backup
@vindex VERSION_CONTROL
@@ -6925,10 +7994,12 @@ combination of options is this tiny Bourne shell script:
@example
#!/bin/sh
# Usage: backup FILE...
-# Create a @sc{gnu}-style backup of each listed FILE.
+# Create a GNU-style backup of each listed FILE.
+fail=0
for i; do
- cp --backup --force -- "$i" "$i"
+ cp --backup --force --preserve=all -- "$i" "$i" || fail=1
done
+exit $fail
@end example
@item --copy-contents
@@ -6961,16 +8032,19 @@ Equivalent to @option{--no-dereference --preserve=links}.
@opindex -f
@opindex --force
When copying without this option and an existing destination file cannot
-be opened for writing, the copy fails. However, with @option{--force}),
-when a destination file cannot be opened, @command{cp} then unlinks it and
+be opened for writing, the copy fails. However, with @option{--force},
+when a destination file cannot be opened, @command{cp} then removes it and
tries to open it again. Contrast this behavior with that enabled by
@option{--link} and @option{--symbolic-link}, whereby the destination file
-is never opened but rather is unlinked unconditionally. Also see the
+is never opened but rather is removed unconditionally. Also see the
description of @option{--remove-destination}.
This option is independent of the @option{--interactive} or
@option{-i} option: neither cancels the effect of the other.
+This option is ignored when the @option{--no-clobber} or @option{-n} option
+is also used.
+
@item -H
@opindex -H
If a command line argument specifies a symbolic link, then copy the
@@ -6983,7 +8057,8 @@ via recursive traversal.
@opindex -i
@opindex --interactive
When copying a file other than a directory, prompt whether to
-overwrite an existing destination file.
+overwrite an existing destination file. The @option{-i} option overrides
+a previous @option{-n} option.
@item -l
@itemx --link
@@ -6995,7 +8070,18 @@ Make hard links instead of copies of non-directories.
@itemx --dereference
@opindex -L
@opindex --dereference
-Always follow symbolic links.
+Follow symbolic links when copying from them.
+With this option, @command{cp} cannot create a symbolic link.
+For example, a symlink (to regular file) in the source tree will be copied to
+a regular file in the destination tree.
+
+@item -n
+@itemx --no-clobber
+@opindex -n
+@opindex --no-clobber
+Do not overwrite an existing file. The @option{-n} option overrides a previous
+@option{-i} option. This option is mutually exclusive with @option{-b} or
+@option{--backup} option.
@item -P
@itemx --no-dereference
@@ -7003,58 +8089,92 @@ Always follow symbolic links.
@opindex --no-dereference
@cindex symbolic links, copying
Copy symbolic links as symbolic links rather than copying the files that
-they point to.
+they point to. This option affects only symbolic links in the source;
+symbolic links in the destination are always followed if possible.
@item -p
-@itemx @w{@kbd{--preserve}[=@var{attribute_list}]}
+@itemx --preserve[=@var{attribute_list}]
@opindex -p
@opindex --preserve
-@cindex file information, preserving
+@cindex file information, preserving, extended attributes, xattr
Preserve the specified attributes of the original files.
If specified, the @var{attribute_list} must be a comma-separated list
of one or more of the following strings:
@table @samp
-@itemx mode
+@item mode
Preserve the file mode bits and access control lists.
-@itemx ownership
+@item ownership
Preserve the owner and group. On most modern systems,
only users with appropriate privileges may change the owner of a file,
and ordinary users
may preserve the group ownership of a file only if they happen to be
a member of the desired group.
-@itemx timestamps
+@item timestamps
Preserve the times of last access and last modification, when possible.
-In general, it is not possible to preserve these attributes
+On older systems, it is not possible to preserve these attributes
when the affected file is a symbolic link.
-However, FreeBSD now provides the @code{lutimes} function, which makes
-it possibile even for symbolic links. However, this implementation does
-not yet take advantage of that.
-@c FIXME: once we provide lutimes support, update the above.
-@itemx links
+However, many systems now provide the @code{utimensat} function,
+which makes it possible even for symbolic links.
+@item links
Preserve in the destination files
any links between corresponding source files.
-@c Give examples illustrating how hard links are preserved.
-@c Also, show how soft links map to hard links with -L and -H.
-@itemx all
+Note that with @option{-L} or @option{-H}, this option can convert
+symbolic links to hard links. For example,
+@example
+$ mkdir c; : > a; ln -s a b; cp -aH a b c; ls -i1 c
+74161745 a
+74161745 b
+@end example
+@noindent
+Note the inputs: @file{b} is a symlink to regular file @file{a},
+yet the files in destination directory, @file{c/}, are hard-linked.
+Since @option{-a} implies @option{--no-dereference} it would copy the symlink,
+but the later @option{-H} tells @command{cp} to dereference the command line
+arguments where it then sees two files with the same inode number.
+Then the @option{--preserve=links} option also implied by @option{-a}
+will preserve the perceived hard link.
+
+Here is a similar example that exercises @command{cp}'s @option{-L} option:
+@smallexample
+$ mkdir b c; (cd b; : > a; ln -s a b); cp -aL b c; ls -i1 c/b
+74163295 a
+74163295 b
+@end smallexample
+
+@item context
+Preserve SELinux security context of the file, or fail with full diagnostics.
+@item xattr
+Preserve extended attributes of the file, or fail with full diagnostics.
+If @command{cp} is built without xattr support, ignore this option.
+If SELinux context, ACLs or Capabilities are implemented using xattrs,
+they are preserved implicitly by this option as well, i.e., even without
+specifying @option{--preserve=mode} or @option{--preserve=context}.
+@item all
Preserve all file attributes.
-Equivalent to specifying all of the above.
+Equivalent to specifying all of the above, but with the difference
+that failure to preserve SELinux security context or extended attributes
+does not change @command{cp}'s exit status. In contrast to @option{-a},
+all but @samp{Operation not supported} warnings are output.
@end table
Using @option{--preserve} with no @var{attribute_list} is equivalent
to @option{--preserve=mode,ownership,timestamps}.
-In the absence of this option, each destination file is created with the
-mode bits of the corresponding source file, minus the bits set in the
-umask and minus the set-user-ID and set-group-ID bits.
+In the absence of this option, the permissions of existing destination
+files are unchanged. Each new file is created with the mode of the
+corresponding source file minus the set-user-ID, set-group-ID, and
+sticky bits as the create mode; the operating system then applies either
+the umask or a default ACL, possibly resulting in a more restrictive
+file mode.
@xref{File permissions}.
-@itemx @w{@kbd{--no-preserve}=@var{attribute_list}}
+@item --no-preserve=@var{attribute_list}
@cindex file information, preserving
Do not preserve the specified attributes. The @var{attribute_list}
has the same form as for @option{--preserve}.
-@itemx --parents
+@item --parents
@opindex --parents
@cindex parent directories and @command{cp}
Form the name of each destination file by appending to the target
@@ -7070,19 +8190,6 @@ cp --parents a/b/c existing_dir
copies the file @file{a/b/c} to @file{existing_dir/a/b/c}, creating
any missing intermediate directories.
-@itemx @w{@kbd{--reply}=@var{how}}
-@opindex --reply
-@cindex interactivity
-@c FIXME: remove in 2008
-@strong{Deprecated: to be removed in 2008.}@*
-Using @option{--reply=yes} makes @command{cp} act as if @samp{yes} were
-given as a response to every prompt about a destination file. That effectively
-cancels any preceding @option{--interactive} or @option{-i} option.
-Specify @option{--reply=no} to make @command{cp} act as if @samp{no} were
-given as a response to every prompt about a destination file.
-Specify @option{--reply=query} to make @command{cp} prompt the user
-about each existing destination file.
-
@item -R
@itemx -r
@itemx --recursive
@@ -7093,19 +8200,53 @@ about each existing destination file.
@cindex copying directories recursively
@cindex recursively copying directories
@cindex non-directories, copying as special files
-Copy directories recursively. Symbolic links are not followed by
-default; see the @option{--archive} (@option{-a}), @option{-d},
+Copy directories recursively. By default, do not follow symbolic
+links in the source unless used together with the @option{--link}
+(@option{-l}) option; see the @option{--archive} (@option{-a}), @option{-d},
@option{--dereference} (@option{-L}), @option{--no-dereference}
(@option{-P}), and @option{-H} options. Special files are copied by
creating a destination file of the same type as the source; see the
@option{--copy-contents} option. It is not portable to use
@option{-r} to copy symbolic links or special files. On some
-non-@sc{gnu} systems, @option{-r} implies the equivalent of
+non-GNU systems, @option{-r} implies the equivalent of
@option{-L} and @option{--copy-contents} for historical reasons.
Also, it is not portable to use @option{-R} to copy symbolic links
-unless you also specify @option{-P}, as @acronym{POSIX} allows
+unless you also specify @option{-P}, as POSIX allows
implementations that dereference symbolic links by default.
+@item --reflink[=@var{when}]
+@opindex --reflink[=@var{when}]
+@cindex COW
+@cindex clone
+@cindex copy on write
+Perform a lightweight, copy-on-write (COW) copy, if supported by the
+file system. Once it has succeeded, beware that the source and destination
+files share the same disk data blocks as long as they remain unmodified.
+Thus, if a disk I/O error affects data blocks of one of the files,
+the other suffers the same fate.
+
+The @var{when} value can be one of the following:
+
+@table @samp
+@item always
+The default behavior: if the copy-on-write operation is not supported
+then report the failure for each file and exit with a failure status.
+
+@item auto
+If the copy-on-write operation is not supported then fall back
+to the standard copy behavior.
+@end table
+
+This option is overridden by the @option{--link}, @option{--symbolic-link}
+and @option{--attributes-only} options, thus allowing it to be used
+to configure the default data copying behavior for @command{cp}.
+For example, with the following alias, @command{cp} will use the
+minimum amount of space supported by the file system.
+
+@example
+alias cp='cp --reflink=auto --sparse=always'
+@end example
+
@item --remove-destination
@opindex --remove-destination
Remove each existing destination file before attempting to open it
@@ -7177,8 +8318,11 @@ same or newer modification time. If time stamps are being preserved,
the comparison is to the source time stamp truncated to the
resolutions of the destination file system and of the system calls
used to update time stamps; this avoids duplicate work if several
-@samp{cp -pu} commands are executed with the same source and
-destination.
+@samp{cp -pu} commands are executed with the same source and destination.
+If @option{--preserve=links} is also specified (like with @samp{cp -au}
+for example), that will take precedence. Consequently, depending on the
+order that files are processed from the source, newer files in the destination
+may be replaced, to mirror hard links in the source.
@item -v
@itemx --verbose
@@ -7195,6 +8339,25 @@ Skip subdirectories that are on different file systems from the one that
the copy started on.
However, mount point directories @emph{are} copied.
+@macro optContext
+@item -Z
+@itemx --context[=@var{context}]
+@opindex -Z
+@opindex --context
+@cindex SELinux, setting/restoring security context
+@cindex security context
+Without a specified @var{context}, adjust the SELinux security context according
+to the system default type for destination files, similarly to the
+@command{restorecon} command.
+The long form of this option with a specific context specified,
+will set the context for newly created files only.
+With a specified context, if both SELinux and SMACK are disabled, a warning is
+issued.
+@end macro
+@optContext
+This option is mutually exclusive with the @option{--preserve=context}
+option, and overrides the @option{--preserve=all} and @option{-a} options.
+
@end table
@exitstatus
@@ -7216,7 +8379,9 @@ dd @var{option}
@end example
The only options are @option{--help} and @option{--version}.
-@xref{Common options}. @command{dd} accepts the following operands.
+@xref{Common options}. @command{dd} accepts the following operands,
+whose syntax was inspired by the DD (data definition) statement of
+OS/360 JCL.
@table @samp
@@ -7236,6 +8401,7 @@ bytes (or the size specified with @samp{seek=}).
@cindex input block size
Set the input block size to @var{bytes}.
This makes @command{dd} read @var{bytes} per block.
+The default is 512 bytes.
@item obs=@var{bytes}
@opindex obs
@@ -7243,6 +8409,7 @@ This makes @command{dd} read @var{bytes} per block.
@cindex output block size
Set the output block size to @var{bytes}.
This makes @command{dd} write @var{bytes} per block.
+The default is 512 bytes.
@item bs=@var{bytes}
@opindex bs
@@ -7250,6 +8417,9 @@ This makes @command{dd} write @var{bytes} per block.
Set both input and output block sizes to @var{bytes}.
This makes @command{dd} read and write @var{bytes} per block,
overriding any @samp{ibs} and @samp{obs} settings.
+In addition, if no data-transforming @option{conv} option is specified,
+input is copied to the output as soon as it's read,
+even if it is smaller than the block size.
@item cbs=@var{bytes}
@opindex cbs
@@ -7262,18 +8432,57 @@ When converting variable-length records to fixed-length ones
(@option{conv=block}) or the reverse (@option{conv=unblock}),
use @var{bytes} as the fixed record length.
-@item skip=@var{blocks}
+@item skip=@var{n}
@opindex skip
-Skip @var{blocks} @samp{ibs}-byte blocks in the input file before copying.
+Skip @var{n} @samp{ibs}-byte blocks in the input file before copying.
+If @samp{iflag=skip_bytes} is specified, @var{n} is interpreted
+as a byte count rather than a block count.
-@item seek=@var{blocks}
+@item seek=@var{n}
@opindex seek
-Skip @var{blocks} @samp{obs}-byte blocks in the output file before copying.
+Skip @var{n} @samp{obs}-byte blocks in the output file before copying.
+if @samp{oflag=seek_bytes} is specified, @var{n} is interpreted
+as a byte count rather than a block count.
-@item count=@var{blocks}
+@item count=@var{n}
@opindex count
-Copy @var{blocks} @samp{ibs}-byte blocks from the input file, instead
+Copy @var{n} @samp{ibs}-byte blocks from the input file, instead
of everything until the end of the file.
+if @samp{iflag=count_bytes} is specified, @var{n} is interpreted
+as a byte count rather than a block count.
+Note if the input may return short reads as could be the case
+when reading from a pipe for example, @samp{iflag=fullblock}
+will ensure that @samp{count=} corresponds to complete input blocks
+rather than the traditional POSIX specified behavior of counting
+input read operations.
+
+@item status=@var{level}
+@opindex status
+Transfer information is normally output to stderr upon
+receipt of the @samp{INFO} signal or when @command{dd} exits.
+Specifying @var{level} will adjust the amount of information printed,
+with the last @var{level} specified taking precedence.
+
+@table @samp
+
+@item none
+@opindex none @r{dd status=}
+Do not print any informational or warning messages to stderr.
+Error messages are output as normal.
+
+@item noxfer
+@opindex noxfer @r{dd status=}
+Do not print the final transfer rate and volume statistics
+that normally make up the last status line.
+
+@item progress
+@opindex progress @r{dd status=}
+Print the transfer rate and volume statistics on stderr,
+when processing each input block. Statistics are output
+on a single line at most once every second, but updates
+can be delayed when waiting on I/O.
+
+@end table
@item conv=@var{conversion}[,@var{conversion}]@dots{}
@opindex conv
@@ -7286,24 +8495,29 @@ Conversions:
@item ascii
@opindex ascii@r{, converting to}
-Convert @acronym{EBCDIC} to @acronym{ASCII},
-using the conversion table specified by @acronym{POSIX}.
+Convert EBCDIC to ASCII,
+using the conversion table specified by POSIX@.
This provides a 1:1 translation for all 256 bytes.
+This option implies @samp{conv=unblock}; input is converted to
+ASCII before trailing spaces are deleted.
@item ebcdic
@opindex ebcdic@r{, converting to}
-Convert @acronym{ASCII} to @acronym{EBCDIC}.
+Convert ASCII to EBCDIC@.
This is the inverse of the @samp{ascii} conversion.
+This option implies @samp{conv=block}; trailing spaces are added
+before being converted to EBCDIC@.
@item ibm
@opindex alternate ebcdic@r{, converting to}
-Convert @acronym{ASCII} to alternate @acronym{EBCDIC},
-using the alternate conversion table specified by @acronym{POSIX}.
+This acts like @samp{conv=ebcdic}, except it
+uses the alternate conversion table specified by POSIX@.
This is not a 1:1 translation, but reflects common historical practice
for @samp{~}, @samp{[}, and @samp{]}.
The @samp{ascii}, @samp{ebcdic}, and @samp{ibm} conversions are
-mutually exclusive.
+mutually exclusive. If you use any of these options, you should also
+use the @samp{cbs=} option.
@item block
@opindex block @r{(space-padding)}
@@ -7312,8 +8526,8 @@ input newline with a space and padding with spaces as necessary.
@item unblock
@opindex unblock
-Replace trailing spaces in each @samp{cbs}-sized input block with a
-newline.
+Remove any trailing spaces in each @samp{cbs}-sized input block,
+and append a newline.
The @samp{block} and @samp{unblock} conversions are mutually exclusive.
@@ -7327,29 +8541,50 @@ Change lowercase letters to uppercase.
The @samp{lcase} and @samp{ucase} conversions are mutually exclusive.
+@item sparse
+@opindex sparse
+Try to seek rather than write NUL output blocks.
+On a file system that supports sparse files, this will create
+sparse output when extending the output file.
+Be careful when using this option in conjunction with
+@samp{conv=notrunc} or @samp{oflag=append}.
+With @samp{conv=notrunc}, existing data in the output file
+corresponding to NUL blocks from the input, will be untouched.
+With @samp{oflag=append} the seeks performed will be ineffective.
+Similarly, when the output is a device rather than a file,
+NUL input blocks are not copied, and therefore this option
+is most useful with virtual or pre zeroed devices.
+
@item swab
@opindex swab @r{(byte-swapping)}
@cindex byte-swapping
-Swap every pair of input bytes. @sc{gnu} @command{dd}, unlike others, works
+Swap every pair of input bytes. GNU @command{dd}, unlike others, works
when an odd number of bytes are read---the last byte is simply copied
(since there is nothing to swap it with).
-@item noerror
-@opindex noerror
-@cindex read errors, ignoring
-Continue after read errors.
+@item sync
+@opindex sync @r{(padding with ASCII NULs)}
+Pad every input block to size of @samp{ibs} with trailing zero bytes.
+When used with @samp{block} or @samp{unblock}, pad with spaces instead of
+zero bytes.
-@item nocreat
-@opindex nocreat
-@cindex creating output file, avoiding
-Do not create the output file; the output file must already exist.
+@end table
+The following ``conversions'' are really file flags
+and don't affect internal processing:
+
+@table @samp
@item excl
@opindex excl
@cindex creating output file, requiring
Fail if the output file already exists; @command{dd} must create the
output file itself.
+@item nocreat
+@opindex nocreat
+@cindex creating output file, avoiding
+Do not create the output file; the output file must already exist.
+
The @samp{excl} and @samp{nocreat} conversions are mutually exclusive.
@item notrunc
@@ -7357,11 +8592,10 @@ The @samp{excl} and @samp{nocreat} conversions are mutually exclusive.
@cindex truncating output file, avoiding
Do not truncate the output file.
-@item sync
-@opindex sync @r{(padding with nulls)}
-Pad every input block to size of @samp{ibs} with trailing zero bytes.
-When used with @samp{block} or @samp{unblock}, pad with spaces instead of
-zero bytes.
+@item noerror
+@opindex noerror
+@cindex read errors, ignoring
+Continue after read errors.
@item fdatasync
@opindex fdatasync
@@ -7402,10 +8636,22 @@ If you combine this flag with the @samp{of=@var{file}} operand,
you should also specify @samp{conv=notrunc} unless you want the
output file to be truncated before being appended to.
+@item cio
+@opindex cio
+@cindex concurrent I/O
+Use concurrent I/O mode for data. This mode performs direct I/O
+and drops the POSIX requirement to serialize all I/O to the same file.
+A file cannot be opened in CIO mode and with a standard open at the
+same time.
+
@item direct
@opindex direct
@cindex direct I/O
Use direct I/O for data, avoiding the buffer cache.
+Note that the kernel may impose restrictions on read or write buffer sizes.
+For example, with an ext4 destination file system and a Linux-based kernel,
+using @samp{oflag=direct} will cause writes to fail with @code{EINVAL} if the
+output buffer size is not a multiple of 512.
@item directory
@opindex directory
@@ -7428,6 +8674,38 @@ last-access and last-modified time) is not necessarily synchronized.
@cindex synchronized data and metadata I/O
Use synchronized I/O for both data and metadata.
+@item nocache
+@opindex nocache
+@cindex discarding file cache
+Request to discard the system data cache for a file.
+When count=0 all cached data for the file is specified,
+otherwise the cache is dropped for the processed
+portion of the file. Also when count=0,
+failure to discard the cache is diagnosed
+and reflected in the exit status.
+
+Note data that is not already persisted to storage will not
+be discarded from cache, so note the use of the ``sync'' options
+in the examples below, which are used to maximize the
+effectiveness of the @samp{nocache} flag.
+
+Here are some usage examples:
+
+@example
+# Advise to drop cache for whole file
+dd if=ifile iflag=nocache count=0
+
+# Ensure drop cache for the whole file
+dd of=ofile oflag=nocache conv=notrunc,fdatasync count=0
+
+# Drop cache for part of file
+dd if=ifile iflag=nocache skip=10 count=10 of=/dev/null
+
+# Stream data using just the read-ahead cache.
+# See also the @samp{direct} flag.
+dd if=ifile of=ofile iflag=nocache oflag=nocache,sync
+@end example
+
@item nonblock
@opindex nonblock
@cindex nonblocking I/O
@@ -7445,7 +8723,7 @@ idea to test it on your files before relying on it.
@cindex controlling terminal
Do not assign the file to be a controlling terminal for @command{dd}.
This has no effect when the file is not a terminal.
-On many hosts (e.g., @acronym{GNU}/Linux hosts), this option has no effect
+On many hosts (e.g., GNU/Linux hosts), this option has no effect
at all.
@item nofollow
@@ -7461,15 +8739,48 @@ Fail if the file has multiple hard links.
@item binary
@opindex binary
@cindex binary I/O
-Use binary I/O. This option has an effect only on nonstandard
+Use binary I/O@. This option has an effect only on nonstandard
platforms that distinguish binary from text I/O.
@item text
@opindex text
@cindex text I/O
-Use text I/O. Like @samp{binary}, this option has no effect on
+Use text I/O@. Like @samp{binary}, this option has no effect on
standard platforms.
+@item fullblock
+@opindex fullblock
+Accumulate full blocks from input. The @code{read} system call
+may return early if a full block is not available.
+When that happens, continue calling @code{read} to fill the remainder
+of the block.
+This flag can be used only with @code{iflag}.
+This flag is useful with pipes for example
+as they may return short reads. In that case,
+this flag is needed to ensure that a @samp{count=} argument is
+interpreted as a block count rather than a count of read operations.
+
+@item count_bytes
+@opindex count_bytes
+Interpret the @samp{count=} operand as a byte count,
+rather than a block count, which allows specifying
+a length that is not a multiple of the I/O block size.
+This flag can be used only with @code{iflag}.
+
+@item skip_bytes
+@opindex skip_bytes
+Interpret the @samp{skip=} operand as a byte count,
+rather than a block count, which allows specifying
+an offset that is not a multiple of the I/O block size.
+This flag can be used only with @code{iflag}.
+
+@item seek_bytes
+@opindex seek_bytes
+Interpret the @samp{seek=} operand as a byte count,
+rather than a block count, which allows specifying
+an offset that is not a multiple of the I/O block size.
+This flag can be used only with @code{oflag}.
+
@end table
These flags are not supported on all systems, and @samp{dd} rejects
@@ -7482,15 +8793,23 @@ affected file descriptors, even after @command{dd} exits.
@end table
@cindex multipliers after numbers
-The numeric-valued strings above (@var{bytes} and @var{blocks}) can be
-followed by a multiplier: @samp{b}=512, @samp{c}=1,
+The numeric-valued strings above (@var{n} and @var{bytes})
+can be followed by a multiplier: @samp{b}=512, @samp{c}=1,
@samp{w}=2, @samp{x@var{m}}=@var{m}, or any of the
standard block size suffixes like @samp{k}=1024 (@pxref{Block size}).
-Use different @command{dd} invocations to use different block sizes for
-skipping and I/O@. For example, the following shell commands copy data
-in 512 KiB blocks between a disk and a tape, but do not save or restore a
-4 KiB label at the start of the disk:
+Any block size you specify via @samp{bs=}, @samp{ibs=}, @samp{obs=}, @samp{cbs=}
+should not be too large---values larger than a few megabytes
+are generally wasteful or (as in the gigabyte..exabyte case) downright
+counterproductive or error-inducing.
+
+To process data that is at an offset or size that is not a
+multiple of the I/O@ block size, you can use the @samp{skip_bytes},
+@samp{seek_bytes} and @samp{count_bytes} flags. Alternatively
+the traditional method of separate @command{dd} invocations can be used.
+For example, the following shell commands copy data
+in 512 KiB blocks between a disk and a tape, but do not save
+or restore a 4 KiB label at the start of the disk:
@example
disk=/dev/rdsk/c0t1d0s2
@@ -7503,24 +8822,60 @@ tape=/dev/rmt/0
(dd bs=4k seek=1 count=0 && dd bs=512k) <$tape >$disk
@end example
-Sending an @samp{INFO} signal to a running @command{dd}
-process makes it print I/O statistics to standard error
-and then resume copying. In the example below,
-@command{dd} is run in the background to copy 10 million blocks.
+@cindex ddrescue
+@cindex disks, failing
+For failing disks, other tools come with a great variety of extra
+functionality to ease the saving of as much data as possible before the
+disk finally dies, e.g.
+@uref{http://www.gnu.org/software/ddrescue/, GNU @command{ddrescue}}.
+However, in some cases such a tool is not available or the administrator
+feels more comfortable with the handling of @command{dd}.
+As a simple rescue method, call @command{dd} as shown in the following
+example: the options @samp{conv=noerror,sync} are used to continue
+after read errors and to pad out bad reads with NULs, while
+@samp{iflag=fullblock} caters for short reads (which traditionally never
+occur on disk based devices):
+
+@example
+# Rescue data from an (unmounted!) partition of a failing disk.
+dd conv=noerror,sync iflag=fullblock </dev/sda1 > /mnt/rescue.img
+@end example
+
+Sending an @samp{INFO} signal (or @samp{USR1} signal where that is unavailable)
+to a running @command{dd} process makes it print I/O statistics to
+standard error and then resume copying. In the example below,
+@command{dd} is run in the background to copy 5GB of data.
The @command{kill} command makes it output intermediate I/O statistics,
-and when @command{dd} completes, it outputs the final statistics.
+and when @command{dd} completes normally or is killed by the
+@code{SIGINT} signal, it outputs the final statistics.
+
+@example
+# Ignore the signal so we never inadvertently terminate the dd child.
+# Note this is not needed when SIGINFO is available.
+trap '' USR1
+
+# Run dd with the fullblock iflag to avoid short reads
+# which can be triggered by reception of signals.
+dd iflag=fullblock if=/dev/zero of=/dev/null count=5000000 bs=1000 & pid=$!
+
+# Output stats every second.
+while kill -s USR1 $pid 2>/dev/null; do sleep 1; done
+@end example
+
+The above script will output in the following format:
@example
-$ dd if=/dev/zero of=/dev/null count=10MB & pid=$!
-$ kill -s INFO $pid; wait $pid
-3385223+0 records in
-3385223+0 records out
-1733234176 bytes (1.7 GB) copied, 6.42173 seconds, 270 MB/s
-10000000+0 records in
-10000000+0 records out
-5120000000 bytes (5.1 GB) copied, 18.913 seconds, 271 MB/s
+3441325+0 records in
+3441325+0 records out
+3441325000 bytes (3.4 GB, 3.2 GiB) copied, 1.00036 s, 3.4 GB/s
+5000000+0 records in
+5000000+0 records out
+5000000000 bytes (5.0 GB, 4.7 GiB) copied, 1.44433 s, 3.5 GB/s
@end example
+The @samp{status=progress} option periodically updates the last line
+of the transfer statistics above.
+
@vindex POSIXLY_CORRECT
On systems lacking the @samp{INFO} signal @command{dd} responds to the
@samp{USR1} signal instead, unless the @env{POSIXLY_CORRECT}
@@ -7572,16 +8927,40 @@ attributes of destination files. It is typically used in Makefiles to
copy programs into their destination directories. It refuses to copy
files onto themselves.
+@cindex extended attributes, xattr
+@command{install} never preserves extended attributes (xattr).
+
The program accepts the following options. Also see @ref{Common options}.
@table @samp
@optBackup
+@item -C
+@itemx --compare
+@opindex -C
+@opindex --compare
+Compare each pair of source and destination files, and if the destination has
+identical content and any specified owner, group, permissions, and possibly
+SELinux context, then do not modify the destination at all.
+Note this option is best used in conjunction with @option{--user},
+@option{--group} and @option{--mode} options, lest @command{install}
+incorrectly determines the default attributes that installed files would have
+(as it doesn't consider setgid directories and POSIX default ACLs for example).
+This could result in redundant copies or attributes that are not reset to the
+correct defaults.
+
@item -c
@opindex -c
Ignored; for compatibility with old Unix versions of @command{install}.
+@item -D
+@opindex -D
+Create any missing parent directories of @var{dest},
+then copy @var{source} to @var{dest}.
+Explicitly specifying the @option{--target-directory=@var{dir}} will similarly
+ensure the presence of that hierarchy before copying @var{source} arguments.
+
@item -d
@itemx --directory
@opindex -d
@@ -7630,6 +9009,15 @@ ownership of installed files or directories to @var{owner}. The default
is @code{root}. @var{owner} may be either a user name or a numeric user
ID.
+@item --preserve-context
+@opindex --preserve-context
+@cindex SELinux
+@cindex security context
+Preserve the SELinux security context of files and directories.
+Failure to preserve the context in all of the files or directories
+will result in an exit status of 1. If SELinux is disabled then
+print a warning and ignore the option.
+
@item -p
@itemx --preserve-timestamps
@opindex -p
@@ -7651,9 +9039,15 @@ to when they were last installed.
@cindex stripping symbol table information
Strip the symbol tables from installed binary executables.
+@item --strip-program=@var{program}
+@opindex --strip-program
+@cindex symbol table information, stripping, program
+Program used to strip binaries.
+
@optBackupSuffix
@optTargetDirectory
+Also specifying the @option{-D} option will ensure the directory is present.
@optNoTargetDirectory
@@ -7663,6 +9057,10 @@ Strip the symbol tables from installed binary executables.
@opindex --verbose
Print the name of each file before copying it.
+@optContext
+This option is mutually exclusive with the @option{--preserve-context} option.
+
+
@end table
@exitstatus
@@ -7708,6 +9106,11 @@ directory succeeded, but the second didn't, the first would be left on
the destination partition and the second and third would be left on the
original partition.
+@cindex extended attributes, xattr
+@command{mv} always tries to copy extended attributes (xattr), which may
+include SELinux context, ACLs or Capabilities.
+Upon failure all but @samp{Operation not supported} warnings are output.
+
@cindex prompting, and @command{mv}
If a destination file exists but is normally unwritable, standard input
is a terminal, and the @option{-f} or @option{--force} option is not given,
@@ -7715,10 +9118,18 @@ is a terminal, and the @option{-f} or @option{--force} option is not given,
own the file, or have write permission on its directory.) If the
response is not affirmative, the file is skipped.
-@emph{Warning}: If you try to move a symlink that points to a directory,
-and you specify the symlink with a trailing slash, then @command{mv}
-doesn't move the symlink but instead moves the directory referenced
-by the symlink. @xref{Trailing slashes}.
+@emph{Warning}: Avoid specifying a source name with a trailing slash,
+when it might be a symlink to a directory.
+Otherwise, @command{mv} may do something very surprising, since
+its behavior depends on the underlying rename system call.
+On a system with a modern Linux-based kernel, it fails with
+@code{errno=ENOTDIR}@.
+However, on other systems (at least FreeBSD 6.1 and Solaris 10) it silently
+renames not the symlink but rather the directory referenced by the symlink.
+@xref{Trailing slashes}.
+
+@emph{Note}: @command{mv} will only replace empty directories in the
+destination. Conflicting populated directories are skipped with a diagnostic.
The program accepts the following options. Also see @ref{Common options}.
@@ -7732,6 +9143,11 @@ The program accepts the following options. Also see @ref{Common options}.
@opindex --force
@cindex prompts, omitting
Do not prompt the user before removing a destination file.
+@macro mvOptsIfn
+If you specify more than one of the @option{-i}, @option{-f}, @option{-n}
+options, only the final one takes effect.
+@end macro
+@mvOptsIfn
@item -i
@itemx --interactive
@@ -7741,21 +9157,16 @@ Do not prompt the user before removing a destination file.
Prompt whether to overwrite each existing destination file, regardless
of its permissions.
If the response is not affirmative, the file is skipped.
+@mvOptsIfn
-@itemx @w{@kbd{--reply}=@var{how}}
-@opindex --reply
-@cindex interactivity
-@c FIXME: remove in 2008
-@strong{Deprecated: to be removed in 2008.}@*
-Specifying @option{--reply=yes} is equivalent to using @option{--force}.
-Specify @option{--reply=no} to make @command{mv} act as if @samp{no} were
-given as a response to every prompt about a destination file.
-Specify @option{--reply=query} to make @command{mv} prompt the user
-about each existing destination file.
-Note that @option{--reply=no} has an effect only when @command{mv} would prompt
-without @option{-i} or equivalent, i.e., when a destination file exists and is
-not writable, standard input is a terminal, and no @option{-f} (or equivalent)
-option is specified.
+@item -n
+@itemx --no-clobber
+@opindex -n
+@opindex --no-clobber
+@cindex prompts, omitting
+Do not overwrite an existing file.
+@mvOptsIfn
+This option is mutually exclusive with @option{-b} or @option{--backup} option.
@item -u
@itemx --update
@@ -7784,6 +9195,16 @@ Print the name of each file before moving it.
@optNoTargetDirectory
+@item -Z
+@itemx --context
+@opindex -Z
+@opindex --context
+@cindex SELinux, restoring security context
+@cindex security context
+This option functions similarly to the @command{restorecon} command,
+by adjusting the SELinux security context according
+to the system default type for destination files.
+
@end table
@exitstatus
@@ -7816,7 +9237,8 @@ the @option{-f} or @option{--force} option is not given, or the
If the response is not affirmative, the file is skipped.
Any attempt to remove a file whose last file name component is
-@file{.} or @file{..} is rejected without any prompting.
+@file{.} or @file{..} is rejected without any prompting, as mandated
+by POSIX.
@emph{Warning}: If you use @command{rm} to remove a file, it is usually
possible to recover the contents of that file. If you want more assurance
@@ -7826,11 +9248,18 @@ The program accepts the following options. Also see @ref{Common options}.
@table @samp
+@item -d
+@itemx --dir
+@opindex -d
+@opindex --dir
+@cindex directories, removing
+Remove the listed directories if they are empty.
+
@item -f
@itemx --force
@opindex -f
@opindex --force
-Ignore nonexistent files and never prompt the user.
+Ignore nonexistent files and missing operands, and never prompt the user.
Ignore any previous @option{--interactive} (@option{-i}) option.
@item -i
@@ -7847,7 +9276,7 @@ files are named or if a recursive removal is requested. Ignore any
previous @option{--force} (@option{-f}) option. Equivalent to
@option{--interactive=once}.
-@itemx --interactive [=@var{when}]
+@item --interactive [=@var{when}]
@opindex --interactive
Specify when to issue an interactive prompt. @var{when} may be
omitted, or one of:
@@ -7863,15 +9292,16 @@ removal is requested. Equivalent to @option{-I}.
@vindex always @r{interactive option}
- Prompt for every file being removed. Equivalent to @option{-i}.
@end itemize
-Specifying @option{--interactive} and no @var{when} is equivalent to
+@option{--interactive} with no @var{when} is equivalent to
@option{--interactive=always}.
-@itemx --one-file-system
+@item --one-file-system
@opindex --one-file-system
@cindex one file system, restricting @command{rm} to
When removing a hierarchy recursively, skip any directory that is on a
file system different from that of the corresponding command line argument.
+@cindex bind mount
This option is useful when removing a build ``chroot'' hierarchy,
which normally contains no valuable data. However, it is not uncommon
to bind-mount @file{/home} into such a hierarchy, to make it easier to
@@ -7884,7 +9314,7 @@ warn about and skip directories on other file systems.
Of course, this will not save your @file{/home} if it and your
chroot happen to be on the same file system.
-@itemx --preserve-root
+@item --preserve-root
@opindex --preserve-root
@cindex root directory, disallow recursive destruction
Fail upon any attempt to remove the root directory, @file{/},
@@ -7892,7 +9322,7 @@ when used with the @option{--recursive} option.
This is the default behavior.
@xref{Treating / specially}.
-@itemx --no-preserve-root
+@item --no-preserve-root
@opindex --no-preserve-root
@cindex root directory, allow recursive destruction
Do not treat @file{/} specially when removing recursively.
@@ -7920,7 +9350,7 @@ Print the name of each file before removing it.
@cindex files beginning with @samp{-}, removing
@cindex @samp{-}, removing files beginning with
One common question is how to remove files whose names begin with a
-@samp{-}. @sc{gnu} @command{rm}, like every program that uses the @code{getopt}
+@samp{-}. GNU @command{rm}, like every program that uses the @code{getopt}
function to parse its arguments, lets you use the @samp{--} option to
indicate that all following arguments are non-options. To remove a file
called @file{-f} in the current directory, you could type either:
@@ -7938,7 +9368,7 @@ rm ./-f
@opindex - @r{and Unix @command{rm}}
The Unix @command{rm} program's use of a single @samp{-} for this purpose
-predates the development of the getopt standard syntax.
+predates the development of the @code{getopt} standard syntax.
@exitstatus
@@ -7982,7 +9412,7 @@ floppies, the patterns are designed for best effect on hard drives.
For more details, see the source code and Peter Gutmann's paper
@uref{http://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html,
@cite{Secure Deletion of Data from Magnetic and Solid-State Memory}},
-from the proceedings of the Sixth @acronym{USENIX} Security Symposium (San Jose,
+from the proceedings of the Sixth USENIX Security Symposium (San Jose,
California, July 22--25, 1996).
@strong{Please note} that @command{shred} relies on a very important assumption:
@@ -7995,7 +9425,7 @@ assumption. Exceptions include:
@item
Log-structured or journaled file systems, such as those supplied with
AIX and Solaris, and JFS, ReiserFS, XFS, Ext3 (in @code{data=journal} mode),
-BFS, NTFS, etc.@: when they are configured to journal @emph{data}.
+BFS, NTFS, etc., when they are configured to journal @emph{data}.
@item
File systems that write redundant data and carry on even if some writes
@@ -8014,7 +9444,7 @@ Compressed file systems.
In the particular case of ext3 file systems, the above disclaimer applies (and
@command{shred} is thus of limited effectiveness) only in @code{data=journal}
-mode, which journals file data in addition to just metadata. In both
+mode, which journals file data in addition to just metadata. In both
the @code{data=ordered} (default) and @code{data=writeback} modes,
@command{shred} works as usual. Ext3 journaling modes can be changed
by adding the @code{data=something} option to the mount options for a
@@ -8060,16 +9490,15 @@ The program accepts the following options. Also see @ref{Common options}.
@cindex force deletion
Override file permissions if necessary to allow overwriting.
-@item -@var{NUMBER}
-@itemx -n @var{NUMBER}
-@itemx --iterations=@var{NUMBER}
-@opindex -n @var{NUMBER}
-@opindex --iterations=@var{NUMBER}
+@item -n @var{number}
+@itemx --iterations=@var{number}
+@opindex -n @var{number}
+@opindex --iterations=@var{number}
@cindex iterations, selecting the number of
-By default, @command{shred} uses 25 passes of overwrite. This is enough
-for all of the useful overwrite patterns to be used at least once.
-You can reduce this to save time, or increase it if you have a lot of
-time to waste.
+By default, @command{shred} uses @value{SHRED_DEFAULT_PASSES} passes of
+overwrite. You can reduce this to save time, or increase it if you think it's
+appropriate. After 25 passes all of the internal overwrite patterns will have
+been used at least once.
@item --random-source=@var{file}
@opindex --random-source
@@ -8077,35 +9506,50 @@ time to waste.
Use @var{file} as a source of random data used to overwrite and to
choose pass ordering. @xref{Random sources}.
-@item -s @var{BYTES}
-@itemx --size=@var{BYTES}
-@opindex -s @var{BYTES}
-@opindex --size=@var{BYTES}
+@item -s @var{bytes}
+@itemx --size=@var{bytes}
+@opindex -s @var{bytes}
+@opindex --size=@var{bytes}
@cindex size of file to shred
-Shred the first @var{BYTES} bytes of the file. The default is to shred
-the whole file. @var{BYTES} can be followed by a size specification like
+Shred the first @var{bytes} bytes of the file. The default is to shred
+the whole file. @var{bytes} can be followed by a size specification like
@samp{K}, @samp{M}, or @samp{G} to specify a multiple. @xref{Block size}.
@item -u
-@itemx --remove
+@itemx --remove[=@var{how}]
@opindex -u
@opindex --remove
+@opindex --remove=unlink
+@opindex --remove=wipe
+@opindex --remove=wipesync
@cindex removing files after shredding
After shredding a file, truncate it (if possible) and then remove it.
If a file has multiple links, only the named links will be removed.
+Often the file name is less sensitive than the file data, in which case
+the optional @var{how} parameter, supported with the long form option,
+gives control of how to more efficiently remove each directory entry.
+The @samp{unlink} parameter will just use a standard unlink call,
+@samp{wipe} will also first obfuscate bytes in the name, and
+@samp{wipesync} will also sync each obfuscated byte in the name to disk.
+Note @samp{wipesync} is the default method, but can be expensive,
+requiring a sync for every character in every file. This can become
+significant with many files, or is redundant if your file system provides
+synchronous metadata updates.
@item -v
@itemx --verbose
@opindex -v
@opindex --verbose
-Display status updates as sterilization proceeds.
+Display to standard error all status updates as sterilization proceeds.
@item -x
@itemx --exact
@opindex -x
@opindex --exact
By default, @command{shred} rounds the size of a regular file up to the next
-multiple of the file system block size to fully erase the last block of the file.
+multiple of the file system block size to fully erase the slack space in
+the last block of the file. This space may contain portions of the current
+system memory on some systems for example.
Use @option{--exact} to suppress that behavior.
Thus, by default if you shred a 10-byte regular file on a system with 512-byte
blocks, the resulting file will be 512 bytes long. With this option,
@@ -8140,12 +9584,26 @@ your hard disk, you could give a command like this:
shred --verbose /dev/sda5
@end example
+On modern disks, a single pass should be adequate,
+and it will take one third the time of the default three-pass approach.
+
+@example
+# 1 pass, write pseudo-random data; 3x faster than the default
+shred --verbose -n1 /dev/sda5
+@end example
+
+To be on the safe side, use at least one pass that overwrites using
+pseudo-random data. I.e., don't be tempted to use @samp{-n0 --zero},
+in case some disk controller optimizes the process of writing blocks
+of all zeros, and thereby does not clear all bytes in a block.
+Some SSDs may do just that.
+
A @var{file} of @samp{-} denotes standard output.
The intended use of this is to shred a removed temporary file.
For example:
@example
-i=`tempfile -m 0600`
+i=$(mktemp)
exec 3<>"$i"
rm -- "$i"
echo "Hello, world" >&3
@@ -8190,7 +9648,7 @@ Besides directories, other special file types include named pipes
* mkdir invocation:: Make directories.
* mkfifo invocation:: Make FIFOs (named pipes).
* mknod invocation:: Make block or character special files.
-* readlink invocation:: Print the referent of a symbolic link.
+* readlink invocation:: Print value of a symlink or canonical file name.
* rmdir invocation:: Remove empty directories.
* unlink invocation:: Remove files via the unlink syscall
@end menu
@@ -8221,12 +9679,17 @@ must specify a nonexistent entry in an existing directory.
@command{link} simply calls @code{link (@var{filename}, @var{linkname})}
to create the link.
-On a @acronym{GNU} system, this command acts like @samp{ln --directory
+On a GNU system, this command acts like @samp{ln --directory
--no-target-directory @var{filename} @var{linkname}}. However, the
@option{--directory} and @option{--no-target-directory} options are
-not specified by @acronym{POSIX}, and the @command{link} command is
+not specified by POSIX, and the @command{link} command is
more portable in practice.
+If @var{filename} is a symbolic link, it is unspecified whether
+@var{linkname} will be a hard link to the symbolic link or to the
+target of the symbolic link. Use @command{ln -P} or @command{ln -L}
+to specify which behavior is desired.
+
@exitstatus
@@ -8282,9 +9745,11 @@ A @dfn{hard link} is another name for an existing file; the link and the
original are indistinguishable. Technically speaking, they share the
same inode, and the inode contains all the information about a
file---indeed, it is not incorrect to say that the inode @emph{is} the
-file. On all existing implementations, you cannot make a hard link to
-a directory, and hard links cannot cross file system boundaries. (These
-restrictions are not mandated by @acronym{POSIX}, however.)
+file. Most systems prohibit making a hard link to
+a directory; on those where it is allowed, only the super-user can do
+so (and with caution, since creating a cycle will cause problems to many
+other utilities). Hard links cannot cross file system boundaries. (These
+restrictions are not mandated by POSIX, however.)
@cindex dereferencing symbolic links
@cindex symbolic link, defined
@@ -8295,9 +9760,36 @@ refers to a different file, by name. When most operations (opening,
reading, writing, and so on) are passed the symbolic link file, the
kernel automatically @dfn{dereferences} the link and operates on the
target of the link. But some operations (e.g., removing) work on the
-link file itself, rather than on its target. @xref{Symbolic Links,,,
+link file itself, rather than on its target. The owner and group of a
+symlink are not significant to file access performed through
+the link, but do have implications on deleting a symbolic link from a
+directory with the restricted deletion bit set. On the GNU system,
+the mode of a symlink has no significance and cannot be changed, but
+on some BSD systems, the mode can be changed and will affect whether
+the symlink will be traversed in file name resolution. @xref{Symbolic Links,,,
libc, The GNU C Library Reference Manual}.
+Symbolic links can contain arbitrary strings; a @dfn{dangling symlink}
+occurs when the string in the symlink does not resolve to a file.
+There are no restrictions against creating dangling symbolic links.
+There are trade-offs to using absolute or relative symlinks. An
+absolute symlink always points to the same file, even if the directory
+containing the link is moved. However, if the symlink is visible from
+more than one machine (such as on a networked file system), the file
+pointed to might not always be the same. A relative symbolic link is
+resolved in relation to the directory that contains the link, and is
+often useful in referring to files on the same device without regards
+to what name that device is mounted on when accessed via networked
+machines.
+
+When creating a relative symlink in a different location than the
+current directory, the resolution of the symlink will be different
+than the resolution of the same string from the current directory.
+Therefore, many users prefer to first change directories to the
+location where the relative symlink will be created, so that
+tab-completion or other file resolution will find the same target as
+what will be placed in the symlink.
+
The program accepts the following options. Also see @ref{Common options}.
@table @samp
@@ -8329,6 +9821,14 @@ Remove existing destination files.
@cindex prompting, and @command{ln}
Prompt whether to remove existing destination files.
+@item -L
+@itemx --logical
+@opindex -L
+@opindex --logical
+If @option{-s} is not in effect, and the source file is a symbolic
+link, create the hard link to the file referred to by the symbolic
+link, rather than the symbolic link itself.
+
@item -n
@itemx --no-dereference
@opindex -n
@@ -8350,6 +9850,49 @@ just like a directory.
This option is weaker than the @option{--no-target-directory}
(@option{-T}) option, so it has no effect if both options are given.
+@item -P
+@itemx --physical
+@opindex -P
+@opindex --physical
+If @option{-s} is not in effect, and the source file is a symbolic
+link, create the hard link to the symbolic link itself. On platforms
+where this is not supported by the kernel, this option creates a
+symbolic link with identical contents; since symbolic link contents
+cannot be edited, any file name resolution performed through either
+link will be the same as if a hard link had been created.
+
+@item -r
+@itemx --relative
+@opindex -r
+@opindex --relative
+Make symbolic links relative to the link location.
+
+Example:
+
+@smallexample
+ln -srv /a/file /tmp
+'/tmp/file' -> '../a/file'
+@end smallexample
+
+Relative symbolic links are generated based on their canonicalized
+containing directory, and canonicalized targets. I.e., all symbolic
+links in these file names will be resolved.
+@xref{realpath invocation}, which gives greater control
+over relative file name generation, as demonstrated in the following example:
+
+@example
+@verbatim
+ln--relative() {
+ test "$1" = --no-symlinks && { nosym=$1; shift; }
+ target="$1";
+ test -d "$2" && link="$2/." || link="$2"
+ rtarget="$(realpath $nosym -m "$target" \
+ --relative-to "$(dirname "$link")")"
+ ln -s -v "$rtarget" "$link"
+}
+@end verbatim
+@end example
+
@item -s
@itemx --symbolic
@opindex -s
@@ -8371,6 +9914,15 @@ Print the name of each file after linking it successfully.
@end table
+@cindex hard links to symbolic links
+@cindex symbolic links and @command{ln}
+If @option{-L} and @option{-P} are both given, the last one takes
+precedence. If @option{-s} is also given, @option{-L} and @option{-P}
+are silently ignored. If neither option is given, then this
+implementation defaults to @option{-P} if the system @code{link} supports
+hard links to symbolic links (such as the GNU system), and @option{-L}
+if @code{link} follows symbolic links (such as on BSD).
+
@exitstatus
Examples:
@@ -8434,7 +9986,7 @@ in @command{chmod} and uses @samp{a=rwx} (read, write and execute allowed for
everyone) for the point of the departure. @xref{File permissions}.
Normally the directory has the desired file mode bits at the moment it
-is created. As a @acronym{GNU} extension, @var{mode} may also mention
+is created. As a GNU extension, @var{mode} may also mention
special mode bits, but in this case there may be a temporary window
during which the directory exists but its special mode bits are
incorrect. @xref{Directory Setuid and Setgid}, for how the
@@ -8467,6 +10019,9 @@ newly-created parent directories are inherited.
@opindex --verbose
Print a message for each created directory. This is most useful with
@option{--parents}.
+
+@optContext
+
@end table
@exitstatus
@@ -8492,7 +10047,7 @@ to communicate. One process opens the FIFO file for writing, and
another for reading, after which data can flow as with the usual
anonymous pipe in shells or elsewhere.
-The program accepts the following option. Also see @ref{Common options}.
+The program accepts the following options. Also see @ref{Common options}.
@table @samp
@@ -8506,6 +10061,8 @@ Set the mode of created FIFOs to @var{mode}, which is symbolic as in
for the point of departure. @var{mode} should specify only file
permission bits. @xref{File permissions}.
+@optContext
+
@end table
@exitstatus
@@ -8537,6 +10094,9 @@ files of this type. Such devices can be read either a character at a
time or a ``block'' (many characters) at a time, hence we say there are
@dfn{block special} files and @dfn{character special} files.
+@c mknod is a shell built-in at least with OpenBSD's /bin/sh
+@mayConflictWithShellBuiltIn{mknod}
+
The arguments after @var{name} specify the type of file to make:
@table @samp
@@ -8550,7 +10110,7 @@ for a FIFO
for a block special file
@item c
-@c Don't document the `u' option -- it's just a synonym for `c'.
+@c Don't document the 'u' option -- it's just a synonym for 'c'.
@c Do *any* versions of mknod still use it?
@c @itemx u
@opindex c @r{for character special file}
@@ -8565,7 +10125,7 @@ If a major or minor device number begins with @samp{0x} or @samp{0X},
it is interpreted as hexadecimal; otherwise, if it begins with @samp{0},
as octal; otherwise, as decimal.
-The program accepts the following option. Also see @ref{Common options}.
+The program accepts the following options. Also see @ref{Common options}.
@table @samp
@@ -8578,16 +10138,21 @@ Set the mode of created files to @var{mode}, which is symbolic as in
@var{mode} should specify only file permission bits.
@xref{File permissions}.
+@optContext
+
@end table
@exitstatus
@node readlink invocation
-@section @command{readlink}: Print the referent of a symbolic link
+@section @command{readlink}: Print value of a symlink or canonical file name
@pindex readlink
@cindex displaying value of a symbolic link
+@cindex canonical file name
+@cindex canonicalize a file name
+@findex realpath
@command{readlink} may work in one of two supported modes:
@@ -8595,20 +10160,20 @@ Set the mode of created files to @var{mode}, which is symbolic as in
@item Readlink mode
-@command{readlink} outputs the value of the given symbolic link.
+@command{readlink} outputs the value of the given symbolic links.
If @command{readlink} is invoked with an argument other than the name
of a symbolic link, it produces no output and exits with a nonzero exit code.
@item Canonicalize mode
-@command{readlink} outputs the absolute name of the given file which contains
+@command{readlink} outputs the absolute name of the given files which contain
no @file{.}, @file{..} components nor any repeated separators
(@file{/}) or symbolic links.
@end table
@example
-readlink [@var{option}] @var{file}
+readlink [@var{option}]@dots{} @var{file}@dots{}
@end example
By default, @command{readlink} operates in readlink mode.
@@ -8623,7 +10188,8 @@ The program accepts the following options. Also see @ref{Common options}.
@opindex --canonicalize
Activate canonicalize mode.
If any component of the file name except the last one is missing or unavailable,
-@command{readlink} produces no output and exits with a nonzero exit code.
+@command{readlink} produces no output and exits with a nonzero exit
+code. A trailing slash is ignored.
@item -e
@itemx --canonicalize-existing
@@ -8631,7 +10197,8 @@ If any component of the file name except the last one is missing or unavailable,
@opindex --canonicalize-existing
Activate canonicalize mode.
If any component is missing or unavailable, @command{readlink} produces
-no output and exits with a nonzero exit code.
+no output and exits with a nonzero exit code. A trailing slash
+requires that the name resolve to a directory.
@item -m
@itemx --canonicalize-missing
@@ -8645,7 +10212,8 @@ as a directory.
@itemx --no-newline
@opindex -n
@opindex --no-newline
-Do not output the trailing newline.
+Do not print the output delimiter, when a single @var{file} is specified.
+Print a warning if specified along with multiple @var{file}s.
@item -s
@itemx -q
@@ -8663,10 +10231,15 @@ Suppress most error messages.
@opindex --verbose
Report error messages.
+@optZero
+
@end table
The @command{readlink} utility first appeared in OpenBSD 2.1.
+The @command{realpath} command without options, operates like
+@command{readlink} in canonicalize mode.
+
@exitstatus
@@ -8686,7 +10259,7 @@ rmdir [@var{option}]@dots{} @var{directory}@dots{}
If any @var{directory} argument does not refer to an existing empty
directory, it is an error.
-The program accepts the following option. Also see @ref{Common options}.
+The program accepts the following options. Also see @ref{Common options}.
@table @samp
@@ -8768,9 +10341,9 @@ timestamps, and other information. Collectively, we call these a file's
These commands change file attributes.
@menu
+* chown invocation:: Change file owners and groups.
* chgrp invocation:: Change file groups.
* chmod invocation:: Change access permissions.
-* chown invocation:: Change file owners and groups.
* touch invocation:: Change file timestamps.
@end menu
@@ -8789,7 +10362,8 @@ to @var{new-owner} or to the user and group of an existing reference file.
Synopsis:
@example
-chown [@var{option}]@dots{} @{@var{new-owner} | --reference=@var{ref_file}@} @var{file}@dots{}
+chown [@var{option}]@dots{} @{@var{new-owner} | --reference=@var{ref_file}@}@c
+ @var{file}@dots{}
@end example
If used, @var{new-owner} specifies the new owner and/or group as follows
@@ -8833,14 +10407,21 @@ or group ID, then you may specify it with a leading @samp{+}.
@xref{Disambiguating names and IDs}.
Some older scripts may still use @samp{.} in place of the @samp{:} separator.
-@acronym{POSIX} 1003.1-2001 (@pxref{Standards conformance}) does not
-require support for that, but for backward compatibility @acronym{GNU}
+POSIX 1003.1-2001 (@pxref{Standards conformance}) does not
+require support for that, but for backward compatibility GNU
@command{chown} supports @samp{.} so long as no ambiguity results.
New scripts should avoid the use of @samp{.} because it is not
portable, and because it has undesirable results if the entire
@var{owner@samp{.}group} happens to identify a user whose name
contains @samp{.}.
+@macro chownGroupRestrictions
+It is system dependent whether a user can change the group to an arbitrary one,
+or the more portable behavior of being restricted to setting a group of
+which the user is a member.
+@end macro
+@chownGroupRestrictions
+
The @command{chown} command sometimes clears the set-user-ID or
set-group-ID permission bits. This behavior depends on the policy and
functionality of the underlying @code{chown} system call, which may
@@ -8874,7 +10455,7 @@ actually changes.
Do not print error messages about files whose ownership cannot be
changed.
-@itemx @w{@kbd{--from}=@var{old-owner}}
+@item --from=@var{old-owner}
@opindex --from
@cindex symbolic links, changing owner
Change a @var{file}'s ownership only if it has current attributes specified
@@ -8928,14 +10509,14 @@ is a symbolic link.
By default, no diagnostic is issued for symbolic links encountered
during a recursive traversal, but see @option{--verbose}.
-@itemx --preserve-root
+@item --preserve-root
@opindex --preserve-root
@cindex root directory, disallow recursive modification
Fail upon any attempt to recursively change the root directory, @file{/}.
Without @option{--recursive}, this option has no effect.
@xref{Treating / specially}.
-@itemx --no-preserve-root
+@item --no-preserve-root
@opindex --no-preserve-root
@cindex root directory, allow recursive modification
Cancel the effect of any preceding @option{--preserve-root} option.
@@ -9001,16 +10582,20 @@ chown -hR root /u
@command{chgrp} changes the group ownership of each given @var{file}
to @var{group} (which can be either a group name or a numeric group ID)
-or to the group of an existing reference file. Synopsis:
+or to the group of an existing reference file. @xref{chown invocation}.
+Synopsis:
@example
-chgrp [@var{option}]@dots{} @{@var{group} | --reference=@var{ref_file}@} @var{file}@dots{}
+chgrp [@var{option}]@dots{} @{@var{group} | --reference=@var{ref_file}@}@c
+ @var{file}@dots{}
@end example
If @var{group} is intended to represent a
numeric group ID, then you may specify it with a leading @samp{+}.
@xref{Disambiguating names and IDs}.
+@chownGroupRestrictions
+
The program accepts the following options. Also see @ref{Common options}.
@table @samp
@@ -9054,14 +10639,14 @@ is a symbolic link.
By default, no diagnostic is issued for symbolic links encountered
during a recursive traversal, but see @option{--verbose}.
-@itemx --preserve-root
+@item --preserve-root
@opindex --preserve-root
@cindex root directory, disallow recursive modification
Fail upon any attempt to recursively change the root directory, @file{/}.
Without @option{--recursive}, this option has no effect.
@xref{Treating / specially}.
-@itemx --no-preserve-root
+@item --no-preserve-root
@opindex --no-preserve-root
@cindex root directory, allow recursive modification
Cancel the effect of any preceding @option{--preserve-root} option.
@@ -9125,7 +10710,8 @@ chgrp -hR staff /u
@command{chmod} changes the access permissions of the named files. Synopsis:
@example
-chmod [@var{option}]@dots{} @{@var{mode} | --reference=@var{ref_file}@} @var{file}@dots{}
+chmod [@var{option}]@dots{} @{@var{mode} | --reference=@var{ref_file}@}@c
+ @var{file}@dots{}
@end example
@cindex symbolic links, permissions of
@@ -9175,14 +10761,14 @@ actually changes.
Do not print error messages about files whose permissions cannot be
changed.
-@itemx --preserve-root
+@item --preserve-root
@opindex --preserve-root
@cindex root directory, disallow recursive modification
Fail upon any attempt to recursively change the root directory, @file{/}.
Without @option{--recursive}, this option has no effect.
@xref{Treating / specially}.
-@itemx --no-preserve-root
+@item --no-preserve-root
@opindex --no-preserve-root
@cindex root directory, allow recursive modification
Cancel the effect of any preceding @option{--preserve-root} option.
@@ -9229,21 +10815,52 @@ touch [@var{option}]@dots{} @var{file}@dots{}
@end example
@cindex empty files, creating
-Any @var{file} that does not exist is created empty.
-
-A @var{file} of @samp{-} causes @command{touch} to change the
-times of the file associated with standard output.
+Any @var{file} argument that does not exist is created empty, unless
+option @option{--no-create} (@option{-c}) or @option{--no-dereference}
+(@option{-h}) was in effect.
+
+A @var{file} argument string of @samp{-} is handled specially and
+causes @command{touch} to change the times of the file associated with
+standard output.
+
+@cindex clock skew
+By default, @command{touch} sets file timestamps to the current time.
+Because @command{touch} acts on its operands left to right, the
+resulting timestamps of earlier and later operands may disagree.
+Also, the determination of what time is ``current'' depends on the
+platform. Platforms with network file systems often use different
+clocks for the operating system and for file systems; because
+@command{touch} typically uses file systems' clocks by default, clock
+skew can cause the resulting file timestamps to appear to be in a
+program's ``future'' or ``past''.
+
+@cindex file timestamp resolution
+The @command{touch} command sets the file's timestamp to the greatest
+representable value that is not greater than the requested time. This
+can differ from the requested time for several reasons. First, the
+requested time may have a higher resolution than supported. Second, a
+file system may use different resolutions for different types of
+times. Third, file timestamps may use a different resolution than
+operating system timestamps. Fourth, the operating system primitives
+used to update timestamps may employ yet a different resolution. For
+example, in theory a file system might use 10-microsecond resolution
+for access time and 100-nanosecond resolution for modification time,
+and the operating system might use nanosecond resolution for the
+current time and microsecond resolution for the primitive that
+@command{touch} uses to set a file's timestamp to an arbitrary value.
@cindex permissions, for changing file timestamps
-If changing both the access and modification times to the current
-time, @command{touch} can change the timestamps for files that the user
-running it does not own but has write permission for. Otherwise, the
-user must own the files.
+When setting file timestamps to the current time, @command{touch} can
+change the timestamps for files that the user does not own but has
+write permission for. Otherwise, the user must own the files. Some
+older systems have a further restriction: the user must own the files
+unless both the access and modification times are being set to the
+current time.
Although @command{touch} provides options for changing two of the times---the
times of last access and modification---of a file, there is actually
-a third one as well: the inode change time. This is often referred to
-as a file's @code{ctime}.
+a standard third one as well: the inode change time. This is often
+referred to as a file's @code{ctime}.
The inode change time represents the time when the file's meta-information
last changed. One common example of this is when the permissions of a
file change. Changing the permissions doesn't access the file, so
@@ -9255,13 +10872,17 @@ fresh copy of the file, including the new permissions value.
Another operation that modifies a file's ctime without affecting
the others is renaming. In any case, it is not possible, in normal
operations, for a user to change the ctime field to a user-specified value.
+Some operating systems and file systems support a fourth time: the
+birth time, when the file was first created; by definition, this
+timestamp never changes.
@vindex TZ
Time stamps assume the time zone rules specified by the @env{TZ}
environment variable, or by the system default rules if @env{TZ} is
not set. @xref{TZ Variable,, Specifying the Time Zone with @env{TZ},
-libc, The GNU C Library}. You can avoid ambiguities during
-daylight saving transitions by using @sc{utc} time stamps.
+libc, The GNU C Library Reference Manual}.
+You can avoid ambiguities during
+daylight saving transitions by using UTC time stamps.
The program accepts the following options. Also see @ref{Common options}.
@@ -9282,9 +10903,9 @@ Change the access time only.
@itemx --no-create
@opindex -c
@opindex --no-create
-Do not create files that do not exist.
+Do not warn about or create files that do not exist.
-@item -d
+@item -d @var{time}
@itemx --date=@var{time}
@opindex -d
@opindex --date
@@ -9294,7 +10915,7 @@ time zones, @samp{am} and @samp{pm}, @samp{yesterday}, etc. For
example, @option{--date="2004-02-27 14:19:13.489392193 +0530"}
specifies the instant of time that is 489,392,193 nanoseconds after
February 27, 2004 at 2:19:13 PM in a time zone that is 5 hours and 30
-minutes east of @acronym{UTC}. @xref{Date input formats}.
+minutes east of UTC@. @xref{Date input formats}.
File systems that do not support high-resolution time stamps
silently ignore any excess precision here.
@@ -9303,6 +10924,24 @@ silently ignore any excess precision here.
@cindex BSD @command{touch} compatibility
Ignored; for compatibility with BSD versions of @command{touch}.
+@item -h
+@itemx --no-dereference
+@opindex -h
+@opindex --no-dereference
+@cindex symbolic links, changing time
+@findex lutimes
+Attempt to change the timestamps of a symbolic link, rather than what
+the link refers to. When using this option, empty files are not
+created, but option @option{-c} must also be used to avoid warning
+about files that do not exist. Not all systems support changing the
+timestamps of symlinks, since underlying system support for this
+action was not required until POSIX 2008. Also, on some
+systems, the mere act of examining a symbolic link changes the access
+time, such that only changes to the modification time will persist
+long enough to be observable. When coupled with option @option{-r}, a
+reference timestamp is taken from a symbolic link rather than the file
+it refers to.
+
@item -m
@itemx --time=mtime
@itemx --time=modify
@@ -9322,14 +10961,19 @@ If this option is combined with the @option{--date=@var{time}}
the origin for any relative @var{time}s given, but is otherwise ignored.
For example, @samp{-r foo -d '-5 seconds'} specifies a time stamp
equal to five seconds before the corresponding time stamp for @file{foo}.
+If @var{file} is a symbolic link, the reference timestamp is taken
+from the target of the symlink, unless @option{-h} was also in effect.
-@item -t [[@var{CC}]@var{YY}]@var{MMDDhhmm}[.@var{ss}]
+@item -t [[@var{cc}]@var{yy}]@var{mmddhhmm}[.@var{ss}]
+@cindex leap seconds
Use the argument (optional four-digit or two-digit years, months,
days, hours, minutes, optional seconds) instead of the current time.
-If the year is specified with only two digits, then @var{CC}
+If the year is specified with only two digits, then @var{cc}
is 20 for years in the range 0 @dots{} 68, and 19 for years in
69 @dots{} 99. If no digits of the year are specified,
the argument is interpreted as a date in the current year.
+On the atypical systems that support leap seconds, @var{ss} may be
+@samp{60}.
@end table
@@ -9337,8 +10981,8 @@ the argument is interpreted as a date in the current year.
On older systems, @command{touch} supports an obsolete syntax, as follows.
If no timestamp is given with any of the @option{-d}, @option{-r}, or
@option{-t} options, and if there are two or more @var{file}s and the
-first @var{file} is of the form @samp{@var{MMDDhhmm}[@var{YY}]} and this
-would be a valid argument to the @option{-t} option (if the @var{YY}, if
+first @var{file} is of the form @samp{@var{mmddhhmm}[@var{yy}]} and this
+would be a valid argument to the @option{-t} option (if the @var{yy}, if
any, were moved to the front), and if the represented year
is in the range 1969--1999, that argument is interpreted as the time
for the other files instead of as a file name.
@@ -9365,7 +11009,8 @@ file status information, and write buffers to disk.
* df invocation:: Report file system disk space usage.
* du invocation:: Estimate file space usage.
* stat invocation:: Report file or file system status.
-* sync invocation:: Synchronize memory and disk.
+* sync invocation:: Synchronize cached writes to persistent storage.
+* truncate invocation:: Shrink or extend the size of a file.
@end menu
@@ -9391,15 +11036,24 @@ Normally the disk space is printed in units of
1024 bytes, but this can be overridden (@pxref{Block size}).
Non-integer quantities are rounded up to the next higher unit.
+For bind mounts and without arguments, @command{df} only outputs the statistics
+for that device with the shortest mount point name in the list of file systems
+(@var{mtab}), i.e., it hides duplicate entries, unless the @option{-a} option is
+specified.
+
+With the same logic, @command{df} elides a mount entry of a dummy pseudo device
+if there is another mount entry of a real block device for that mount point with
+the same device number, e.g. the early-boot pseudo file system @samp{rootfs} is
+not shown per default when already the real root device has been mounted.
+
@cindex disk device file
@cindex device file, disk
-If an argument @var{file} is a disk device file containing a mounted
-file system, @command{df} shows the space available on that file system
-rather than on the file system containing the device node (i.e., the root
-file system). @sc{gnu} @command{df} does not attempt to determine the disk usage
+If an argument @var{file} resolves to a special file containing
+a mounted file system, @command{df} shows the space available on that
+file system rather than on the file system containing the device node.
+GNU @command{df} does not attempt to determine the disk usage
on unmounted file systems, because on most kinds of systems doing so
-requires extremely nonportable intimate knowledge of file system
-structures.
+requires extremely nonportable intimate knowledge of file system structures.
The program accepts the following options. Also see @ref{Common options}.
@@ -9409,11 +11063,15 @@ The program accepts the following options. Also see @ref{Common options}.
@itemx --all
@opindex -a
@opindex --all
-@cindex automounter file systems
@cindex ignore file systems
-Include in the listing dummy file systems, which
-are omitted by default. Such file systems are typically special-purpose
-pseudo-file-systems, such as automounter entries.
+Include in the listing dummy, duplicate, or inaccessible file systems, which
+are omitted by default. Dummy file systems are typically special purpose
+pseudo file systems such as @samp{/proc}, with no associated storage.
+Duplicate file systems are local or remote file systems that are mounted
+at separate locations in the local file hierarchy, or bind mounted locations.
+Inaccessible file systems are those which are mounted but subsequently
+over-mounted by another file system at that point, or otherwise inaccessible
+due to permissions of the mount point etc.
@item -B @var{size}
@itemx --block-size=@var{size}
@@ -9461,15 +11119,78 @@ This may make @command{df} run significantly faster on systems with many
disks, but on some systems (notably SunOS) the results may be slightly
out of date. This is the default.
+@item --output
+@itemx --output[=@var{field_list}]
+@opindex --output
+Use the output format defined by @var{field_list}, or print all fields if
+@var{field_list} is omitted. In the latter case, the order of the columns
+conforms to the order of the field descriptions below.
+
+The use of the @option{--output} together with each of the options @option{-i},
+@option{-P}, and @option{-T} is mutually exclusive.
+
+FIELD_LIST is a comma-separated list of columns to be included in @command{df}'s
+output and therefore effectively controls the order of output columns.
+Each field can thus be used at the place of choice, but yet must only be
+used once.
+
+Valid field names in the @var{field_list} are:
+@table @samp
+@item source
+The source of the mount point, usually a device.
+@item fstype
+File system type.
+
+@item itotal
+Total number of inodes.
+@item iused
+Number of used inodes.
+@item iavail
+Number of available inodes.
+@item ipcent
+Percentage of @var{iused} divided by @var{itotal}.
+
+@item size
+Total number of blocks.
+@item used
+Number of used blocks.
+@item avail
+Number of available blocks.
+@item pcent
+Percentage of @var{used} divided by @var{size}.
+
+@item file
+The file name if specified on the command line.
+@item target
+The mount point.
+@end table
+
+The fields for block and inodes statistics are affected by the scaling
+options like @option{-h} as usual.
+
+The definition of the @var{field_list} can even be split among several
+@option{--output} uses.
+
+@example
+#!/bin/sh
+# Print the TARGET (i.e., the mount point) along with their percentage
+# statistic regarding the blocks and the inodes.
+df --out=target --output=pcent,ipcent
+
+# Print all available fields.
+df --o
+@end example
+
+
@item -P
@itemx --portability
@opindex -P
@opindex --portability
@cindex one-line output format
-@cindex @acronym{POSIX} output format
+@cindex POSIX output format
@cindex portable output format
@cindex output format, portable
-Use the @acronym{POSIX} output format. This is like the default format except
+Use the POSIX output format. This is like the default format except
for the following:
@enumerate
@@ -9480,7 +11201,7 @@ that if the mount device name is more than 20 characters long (e.g., for
some network mounts), the columns are misaligned.
@item
-The labels in the header output line are changed to conform to @acronym{POSIX}.
+The labels in the header output line are changed to conform to POSIX.
@item
The default block size and output format are unaffected by the
@@ -9500,6 +11221,21 @@ some systems (notably SunOS), doing this yields more up to date results,
but in general this option makes @command{df} much slower, especially when
there are many or very busy file systems.
+@item --total
+@opindex --total
+@cindex grand total of disk size, usage and available space
+Print a grand total of all arguments after all arguments have
+been processed. This can be used to find out the total disk size, usage
+and available space of all listed devices. If no arguments are specified
+df will try harder to elide file systems insignificant to the total
+available space, by suppressing duplicate remote file systems.
+
+For the grand total line, @command{df} prints @samp{"total"} into the
+@var{source} column, and @samp{"-"} into the @var{target} column.
+If there is no @var{source} column (see @option{--output}), then
+@command{df} prints @samp{"total"} into the @var{target} column,
+if present.
+
@item -t @var{fstype}
@itemx --type=@var{fstype}
@opindex -t
@@ -9522,35 +11258,39 @@ the common names (this list is certainly not exhaustive):
@table @samp
@item nfs
-@cindex @acronym{NFS} file system type
-An @acronym{NFS} file system, i.e., one mounted over a network from another
+@cindex NFS file system type
+An NFS file system, i.e., one mounted over a network from another
machine. This is the one type name which seems to be used uniformly by
all systems.
-@item 4.2@r{, }ufs@r{, }efs@dots{}
+@item ext2@r{, }ext3@r{, }ext4@r{, }xfs@r{, }btrfs@dots{}
@cindex Linux file system types
@cindex local file system types
-@opindex 4.2 @r{file system type}
-@opindex ufs @r{file system type}
-@opindex efs @r{file system type}
+@opindex ext2 @r{file system type}
+@opindex ext3 @r{file system type}
+@opindex ext4 @r{file system type}
+@opindex xfs @r{file system type}
+@opindex btrfs @r{file system type}
A file system on a locally-mounted hard disk. (The system might even
support more than one type here; Linux does.)
-@item hsfs@r{, }cdfs
+@item iso9660@r{, }cdfs
@cindex CD-ROM file system type
-@cindex High Sierra file system
-@opindex hsfs @r{file system type}
+@cindex DVD file system type
+@cindex ISO9660 file system type
+@opindex iso9660 @r{file system type}
@opindex cdfs @r{file system type}
-A file system on a CD-ROM drive. HP-UX uses @samp{cdfs}, most other
-systems use @samp{hsfs} (@samp{hs} for ``High Sierra'').
+A file system on a CD or DVD drive. HP-UX uses @samp{cdfs}, most other
+systems use @samp{iso9660}.
-@item pcfs
-@cindex PC file system
+@item ntfs@r{,}fat
+@cindex NTFS file system
@cindex DOS file system
@cindex MS-DOS file system
-@cindex diskette file system
-@opindex pcfs
-An MS-DOS file system, usually on a diskette.
+@cindex MS-Windows file system
+@opindex ntfs @r{file system file}
+@opindex fat @r{file system file}
+File systems used by MS-Windows / MS-DOS.
@end table
@@ -9567,12 +11307,20 @@ Ignored; for compatibility with System V versions of @command{df}.
@end table
+@command{df} is installed only on systems that have usable mount tables,
+so portable scripts should not rely on its existence.
+
@exitstatus
Failure includes the case where no output is generated, so you can
inspect the exit status of a command like @samp{df -t ext3 -t reiserfs
@var{dir}} to test whether @var{dir} is on a file system of type
@samp{ext3} or @samp{reiserfs}.
+Since the list of file systems (@var{mtab}) is needed to determine the
+file system type, failure includes the cases when that list cannot
+be read and one or more of the options @option{-a}, @option{-l}, @option{-t}
+or @option{-x} is used together with a file name argument.
+
@node du invocation
@section @command{du}: Estimate file space usage
@@ -9581,7 +11329,7 @@ inspect the exit status of a command like @samp{df -t ext3 -t reiserfs
@cindex file space usage
@cindex disk usage for files
-@command{du} reports the amount of disk space used by the specified files
+@command{du} reports the amount of disk space used by the set of specified files
and for each subdirectory (of directory arguments). Synopsis:
@example
@@ -9593,17 +11341,24 @@ directory. Normally the disk space is printed in units of
1024 bytes, but this can be overridden (@pxref{Block size}).
Non-integer quantities are rounded up to the next higher unit.
+If two or more hard links point to the same file, only one of the hard
+links is counted. The @var{file} argument order affects which links
+are counted, and changing the argument order may change the numbers
+and entries that @command{du} outputs.
+
The program accepts the following options. Also see @ref{Common options}.
@table @samp
+@optNull
+
@item -a
@itemx --all
@opindex -a
@opindex --all
Show counts for all files, not just directories.
-@itemx --apparent-size
+@item --apparent-size
@opindex --apparent-size
Print apparent sizes, rather than disk usage. The apparent size of a
file is the number of bytes reported by @code{wc -c} on regular files,
@@ -9622,12 +11377,6 @@ dd bs=1 seek=2GiB if=/dev/null of=big
has an apparent size of 2 GiB, yet on most modern
systems, it actually uses almost no disk space.
-@item -b
-@itemx --bytes
-@opindex -b
-@opindex --bytes
-Equivalent to @code{--apparent-size --block-size=1}.
-
@item -B @var{size}
@itemx --block-size=@var{size}
@opindex -B
@@ -9636,6 +11385,12 @@ Equivalent to @code{--apparent-size --block-size=1}.
Scale sizes by @var{size} before printing them (@pxref{Block size}).
For example, @option{-BG} prints sizes in units of 1,073,741,824 bytes.
+@item -b
+@itemx --bytes
+@opindex -b
+@opindex --bytes
+Equivalent to @code{--apparent-size --block-size=1}.
+
@item -c
@itemx --total
@opindex -c
@@ -9654,29 +11409,35 @@ Does not affect other symbolic links. This is helpful for finding
out the disk usage of directories, such as @file{/usr/tmp}, which
are often symbolic links.
-@itemx --files0-from=@var{FILE}
-@opindex --files0-from=@var{FILE}
-@cindex including files from @command{du}
-Rather than processing files named on the command line, process those
-named in file @var{FILE}; each name is terminated by a null byte.
-This is useful with the @option{--total} (@option{-c}) option when
-the list of file names is so long that it may exceed a command line
-length limitation.
-In such cases, running @command{du} via @command{xargs} is undesirable
-because it splits the list into pieces and makes @command{du} print a
-total for each sublist rather than for the entire list.
-One way to produce a list of null-byte-terminated file names is with @sc{gnu}
-@command{find}, using its @option{-print0} predicate.
-Do not specify any @var{FILE} on the command line when using this option.
+@item -d @var{depth}
+@itemx --max-depth=@var{depth}
+@opindex -d @var{depth}
+@opindex --max-depth=@var{depth}
+@cindex limiting output of @command{du}
+Show the total for each directory (and file if --all) that is at
+most MAX_DEPTH levels down from the root of the hierarchy. The root
+is at level 0, so @code{du --max-depth=0} is equivalent to @code{du -s}.
-@optHumanReadable
+@c --files0-from=FILE
+@filesZeroFromOption{du,, with the @option{--total} (@option{-c}) option}
@item -H
@opindex -H
-Currently, @option{-H} is the same as @option{--si},
-except that @option{-H} evokes a warning.
-This option will be changed to be equivalent to
-@option{--dereference-args} (@option{-D}).
+Equivalent to @option{--dereference-args} (@option{-D}).
+
+@optHumanReadable
+
+@item --inodes
+@opindex --inodes
+@cindex inode usage, dereferencing in @command{du}
+List inode usage information instead of block usage.
+This option is useful for finding directories which contain many files, and
+therefore eat up most of the inodes space of a file system (see @command{df},
+option @option{--inodes}).
+It can well be combined with the options @option{-a}, @option{-c},
+@option{-h}, @option{-l}, @option{-s}, @option{-S}, @option{-t} and
+@option{-x}; however, passing other options regarding the block size, for
+example @option{-b}, @option{-m} and @option{--apparent-size}, is ignored.
@item -k
@opindex -k
@@ -9685,14 +11446,6 @@ Print sizes in 1024-byte blocks, overriding the default block size
(@pxref{Block size}).
This option is equivalent to @option{--block-size=1K}.
-@item -l
-@itemx --count-links
-@opindex -l
-@opindex --count-links
-@cindex hard links, counting in @command{du}
-Count the size of all files, even if they have appeared already (as a
-hard link).
-
@item -L
@itemx --dereference
@opindex -L
@@ -9702,6 +11455,14 @@ Dereference symbolic links (show the disk space used by the file
or directory that the link points to instead of the space used by
the link).
+@item -l
+@itemx --count-links
+@opindex -l
+@opindex --count-links
+@cindex hard links, counting in @command{du}
+Count the size of all files, even if they have appeared already (as a
+hard link).
+
@item -m
@opindex -m
@cindex mebibytes for file sizes
@@ -9717,29 +11478,17 @@ This option is equivalent to @option{--block-size=1M}.
For each symbolic links encountered by @command{du},
consider the disk space used by the symbolic link.
-@item --max-depth=@var{DEPTH}
-@opindex --max-depth=@var{DEPTH}
-@cindex limiting output of @command{du}
-Show the total for each directory (and file if --all) that is at
-most MAX_DEPTH levels down from the root of the hierarchy. The root
-is at level 0, so @code{du --max-depth=0} is equivalent to @code{du -s}.
-
-@item -0
-@opindex -0
-@itemx --null
-@opindex --null
-@cindex output null-byte-terminated lines
-Output a null byte at the end of each line, rather than a newline.
-This option enables other programs to parse the output of @command{du}
-even when that output would contain file names with embedded newlines.
+@item -S
+@itemx --separate-dirs
+@opindex -S
+@opindex --separate-dirs
+Normally, in the output of @command{du} (when not using @option{--summarize}),
+the size listed next to a directory name, @var{d}, represents the sum
+of sizes of all entries beneath @var{d} as well as the size of @var{d} itself.
+With @option{--separate-dirs}, the size reported for a directory name,
+@var{d}, will exclude the size of any subdirectories.
-@itemx --si
-@opindex --si
-@cindex SI output
-Append an SI-style abbreviation to each size, such as @samp{MB} for
-megabytes. Powers of 1000 are used, not 1024; @samp{MB} stands for
-1,000,000 bytes. Use the @option{-h} or @option{--human-readable} option if
-you prefer powers of 1024.
+@optSi
@item -s
@itemx --summarize
@@ -9747,20 +11496,61 @@ you prefer powers of 1024.
@opindex --summarize
Display only a total for each argument.
-@item -S
-@itemx --separate-dirs
-@opindex -S
-@opindex --separate-dirs
-Report the size of each directory separately, not including the sizes
-of subdirectories.
+@item -t @var{size}
+@itemx --threshold=@var{size}
+@opindex -t
+@opindex --threshold
+Exclude entries based on a given @var{size}. The @var{size} refers to used
+blocks in normal mode (@pxref{Block size}), or inodes count in conjunction
+with the @option{--inodes} option.
-@itemx --time
+If @var{size} is positive, then @command{du} will only print entries with a size
+greater than or equal to that.
+
+If @var{size} is negative, then @command{du} will only print entries with a size
+smaller than or equal to that.
+
+Although GNU @command{find} can be used to find files of a certain size,
+@command{du}'s @option{--threshold} option can be used to also filter
+directories based on a given size.
+
+Please note that the @option{--threshold} option can be combined with the
+@option{--apparent-size} option, and in this case would elide entries based on
+its apparent size.
+
+Please note that the @option{--threshold} option can be combined with the
+@option{--inodes} option, and in this case would elide entries based on
+its inodes count.
+
+Here's how you would use @option{--threshold} to find directories with a size
+greater than or equal to 200 megabytes:
+
+@example
+du --threshold=200MB
+@end example
+
+Here's how you would use @option{--threshold} to find directories and files -
+note the @option{-a} - with an apparent size smaller than or equal to 500 bytes:
+
+@example
+du -a -t -500 --apparent-size
+@end example
+
+Here's how you would use @option{--threshold} to find directories on the root
+file system with more than 20000 inodes used in the directory tree below:
+
+@example
+du --inodes -x --threshold=20000 /
+@end example
+
+
+@item --time
@opindex --time
@cindex last modified dates, displaying in @command{du}
Show time of the most recent modification of any file in the directory,
or any of its subdirectories.
-@itemx --time=ctime
+@item --time=ctime
@itemx --time=status
@itemx --time=use
@opindex --time
@@ -9770,7 +11560,7 @@ or any of its subdirectories.
Show the most recent status change time (the @samp{ctime} in the inode) of
any file in the directory, instead of the modification time.
-@itemx --time=atime
+@item --time=atime
@itemx --time=access
@opindex --time
@opindex atime@r{, show the most recent}
@@ -9796,19 +11586,19 @@ with @command{date}, @var{format}'s interpretation is affected by the
@env{LC_TIME} locale category.
@item full-iso
-List timestamps in full using @acronym{ISO} 8601 date, time, and time zone
-format with nanosecond precision, e.g., @samp{2002-03-30
+List timestamps in full using ISO 8601 date, time, and time zone
+components with nanosecond precision, e.g., @samp{2002-03-30
23:45:56.477817180 -0700}. This style is equivalent to
@samp{+%Y-%m-%d %H:%M:%S.%N %z}.
@item long-iso
-List @acronym{ISO} 8601 date and time in minutes, e.g.,
+List ISO 8601 date and time components with minute precision, e.g.,
@samp{2002-03-30 23:45}. These timestamps are shorter than
@samp{full-iso} timestamps, and are usually good enough for everyday
work. This style is equivalent to @samp{+%Y-%m-%d %H:%M}.
@item iso
-List @acronym{ISO} 8601 dates for timestamps, e.g., @samp{2002-03-30}.
+List ISO 8601 dates for timestamps, e.g., @samp{2002-03-30}.
This style is equivalent to @samp{+%Y-%m-%d}.
@end table
@@ -9821,6 +11611,22 @@ the newline and any later characters are ignored; if @env{TIME_STYLE}
begins with @samp{posix-} the @samp{posix-} is ignored; and if
@env{TIME_STYLE} is @samp{locale} it is ignored.
+@item -X @var{file}
+@itemx --exclude-from=@var{file}
+@opindex -X @var{file}
+@opindex --exclude-from=@var{file}
+@cindex excluding files from @command{du}
+Like @option{--exclude}, except take the patterns to exclude from @var{file},
+one per line. If @var{file} is @samp{-}, take the patterns from standard
+input.
+
+@item --exclude=@var{pattern}
+@opindex --exclude=@var{pattern}
+@cindex excluding files from @command{du}
+When recursing, skip subdirectories or files matching @var{pattern}.
+For example, @code{du --exclude='*.o'} excludes files whose names
+end in @samp{.o}.
+
@item -x
@itemx --one-file-system
@opindex -x
@@ -9829,22 +11635,6 @@ begins with @samp{posix-} the @samp{posix-} is ignored; and if
Skip directories that are on different file systems from the one that
the argument being processed is on.
-@item --exclude=@var{PATTERN}
-@opindex --exclude=@var{PATTERN}
-@cindex excluding files from @command{du}
-When recursing, skip subdirectories or files matching @var{PATTERN}.
-For example, @code{du --exclude='*.o'} excludes files whose names
-end in @samp{.o}.
-
-@item -X @var{FILE}
-@itemx --exclude-from=@var{FILE}
-@opindex -X @var{FILE}
-@opindex --exclude-from=@var{FILE}
-@cindex excluding files from @command{du}
-Like @option{--exclude}, except take the patterns to exclude from @var{FILE},
-one per line. If @var{FILE} is @samp{-}, take the patterns from standard
-input.
-
@end table
@cindex NFS mounts from BSD to HP-UX
@@ -9875,6 +11665,7 @@ But it also can be used to report the information of the file systems the
given files are located on. If the files are links, @command{stat} can
also give information about the files the links point to.
+@mayConflictWithShellBuiltIn{stat}
@table @samp
@@ -9895,6 +11686,7 @@ Without it, @command{stat} acts on any symbolic link argument directly.
@cindex file systems
Report information about the file systems where the given files are located
instead of information about the files themselves.
+This option implies the @option{-L} option.
@item -c
@itemx --format=@var{format}
@@ -9911,7 +11703,7 @@ $ stat --format=%d:%i / /usr
2057:2
@end example
-@itemx --printf=@var{format}
+@item --printf=@var{format}
@opindex --printf=@var{format}
@cindex output format
Use @var{format} rather than the default format.
@@ -9933,13 +11725,31 @@ $ stat --printf='%d:%i\n' / /usr
@cindex terse output
Print the information in terse form, suitable for parsing by other programs.
-The valid format sequences for files are:
+The output of the following commands are identical and the @option{--format}
+also identifies the items printed (in fuller form) in the default format.
+Note the format string would include another @samp{%C} at the end with an
+active SELinux security context.
+@example
+$ stat --format="%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o" ...
+$ stat --terse ...
+@end example
+
+The same illustrating terse output in @option{--file-system} mode:
+@example
+$ stat -f --format="%n %i %l %t %s %S %b %f %a %c %d" ...
+$ stat -f --terse ...
+@end example
+@end table
+
+The valid @var{format} directives for files with @option{--format} and
+@option{--printf} are:
@itemize @bullet
-@item %a - Access rights in octal
+@item %a - Access rights in octal (note @samp{#} and @samp{0} printf flags)
@item %A - Access rights in human readable form
@item %b - Number of blocks allocated (see @samp{%B})
@item %B - The size in bytes of each block reported by @samp{%b}
+@item %C - The SELinux security context of a file, if available
@item %d - Device number in decimal
@item %D - Device number in hex
@item %f - Raw mode in hex
@@ -9948,23 +11758,78 @@ The valid format sequences for files are:
@item %G - Group name of owner
@item %h - Number of hard links
@item %i - Inode number
+@item %m - Mount point (See note below)
@item %n - File name
@item %N - Quoted file name with dereference if symbolic link
-@item %o - I/O block size
+@item %o - Optimal I/O transfer size hint
@item %s - Total size, in bytes
-@item %t - Major device type in hex
-@item %T - Minor device type in hex
+@item %t - Major device type in hex (see below)
+@item %T - Minor device type in hex (see below)
@item %u - User ID of owner
@item %U - User name of owner
+@item %w - Time of file birth, or @samp{-} if unknown
+@item %W - Time of file birth as seconds since Epoch, or @samp{0}
@item %x - Time of last access
@item %X - Time of last access as seconds since Epoch
-@item %y - Time of last modification
-@item %Y - Time of last modification as seconds since Epoch
-@item %z - Time of last change
-@item %Z - Time of last change as seconds since Epoch
+@item %y - Time of last data modification
+@item %Y - Time of last data modification as seconds since Epoch
+@item %z - Time of last status change
+@item %Z - Time of last status change as seconds since Epoch
@end itemize
-The valid format sequences for file systems are:
+The @samp{%a} format prints the octal mode, and so it is useful
+to control the zero padding of the output with the @samp{#} and @samp{0}
+printf flags. For example to pad to at least 3 wide while making larger
+numbers unambiguously octal, you can use @samp{%#03a}.
+
+The @samp{%t} and @samp{%T} formats operate on the st_rdev member of
+the stat(2) structure, and are only defined for character and block
+special files. On some systems or file types, st_rdev may be used to
+represent other quantities.
+
+The @samp{%W}, @samp{%X}, @samp{%Y}, and @samp{%Z} formats accept a
+precision preceded by a period to specify the number of digits to
+print after the decimal point. For example, @samp{%.3X} outputs the
+last access time to millisecond precision. If a period is given but no
+precision, @command{stat} uses 9 digits, so @samp{%.X} is equivalent to
+@samp{%.9X}@. When discarding excess precision, time stamps are truncated
+toward minus infinity.
+
+@example
+zero pad:
+ $ stat -c '[%015Y]' /usr
+ [000001288929712]
+space align:
+ $ stat -c '[%15Y]' /usr
+ [ 1288929712]
+ $ stat -c '[%-15Y]' /usr
+ [1288929712 ]
+precision:
+ $ stat -c '[%.3Y]' /usr
+ [1288929712.114]
+ $ stat -c '[%.Y]' /usr
+ [1288929712.114951834]
+@end example
+
+The mount point printed by @samp{%m} is similar to that output
+by @command{df}, except that:
+@itemize @bullet
+@item
+stat does not dereference symlinks by default
+(unless @option{-L} is specified)
+@item
+stat does not search for specified device nodes in the
+file system list, instead operating on them directly
+@item
+@cindex bind mount
+stat outputs the alias for a bind mounted file, rather than
+the initial mount point of its backing device.
+One can recursively call stat until there is no change in output,
+to get the current base mount point
+@end itemize
+
+When listing file system information (@option{--file-system} (@option{-f})),
+you must use a different set of @var{format} directives:
@itemize @bullet
@item %a - Free blocks available to non-super-user
@@ -9985,35 +11850,134 @@ The valid format sequences for file systems are:
Time stamps are listed according to the time zone rules specified by
the @env{TZ} environment variable, or by the system default rules if
@env{TZ} is not set. @xref{TZ Variable,, Specifying the Time Zone
-with @env{TZ}, libc, The GNU C Library}.
-@end table
+with @env{TZ}, libc, The GNU C Library Reference Manual}.
@exitstatus
@node sync invocation
-@section @command{sync}: Synchronize data on disk with memory
+@section @command{sync}: Synchronize cached writes to persistent storage
@pindex sync
@cindex synchronize disk and memory
+@cindex Synchronize cached writes to persistent storage
+
+@command{sync} synchronizes in memory files or file systems to persistent
+storage. Synopsis:
+
+@example
+sync [@var{option}] [@var{file}]@dots{}
+@end example
@cindex superblock, writing
@cindex inodes, written buffered
@command{sync} writes any data buffered in memory out to disk. This can
include (but is not limited to) modified superblocks, modified inodes,
and delayed reads and writes. This must be implemented by the kernel;
-The @command{sync} program does nothing but exercise the @code{sync} system
-call.
+The @command{sync} program does nothing but exercise the @code{sync},
+@code{syncfs}, @code{fsync}, and @code{fdatasync} system calls.
@cindex crashes and corruption
The kernel keeps data in memory to avoid doing (relatively slow) disk
reads and writes. This improves performance, but if the computer
crashes, data may be lost or the file system corrupted as a
-result. The @command{sync} command ensures everything in memory
-is written to disk.
+result. The @command{sync} command instructs the kernel to write
+data in memory to persistent storage.
+
+If any argument is specified then only those files will be
+synchronized using the fsync(2) syscall by default.
+
+If at least one file is specified, it is possible to change the
+synchronization method with the following options. Also see
+@ref{Common options}.
+
+@table @samp
+@item -d
+@itemx --data
+@opindex --data
+Use fdatasync(2) to sync only the data for the file,
+and any metadata required to maintain file system consistency.
+
+@item -f
+@itemx --file-system
+@opindex --file-system
+Synchronize all the I/O waiting for the file systems that contain the file,
+using the syscall syncfs(2). Note you would usually @emph{not} specify
+this option if passing a device node like @samp{/dev/sda} for example,
+as that would sync the containing file system rather than the referenced one.
+Note also that depending on the system, passing individual device nodes or files
+may have different sync characteristics than using no arguments.
+I.e., arguments passed to fsync(2) may provide greater guarantees through
+write barriers, than a global sync(2) used when no arguments are provided.
+@end table
+
+@exitstatus
+
+
+@node truncate invocation
+@section @command{truncate}: Shrink or extend the size of a file
+
+@pindex truncate
+@cindex truncating, file sizes
+
+@command{truncate} shrinks or extends the size of each @var{file} to the
+specified size. Synopsis:
+
+@example
+truncate @var{option}@dots{} @var{file}@dots{}
+@end example
+
+@cindex files, creating
+Any @var{file} that does not exist is created.
-Any arguments are ignored, except for a lone @option{--help} or
-@option{--version} (@pxref{Common options}).
+@cindex sparse files, creating
+@cindex holes, creating files with
+If a @var{file} is larger than the specified size, the extra data is lost.
+If a @var{file} is shorter, it is extended and the extended part (or hole)
+reads as zero bytes.
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+
+@item -c
+@itemx --no-create
+@opindex -c
+@opindex --no-create
+Do not create files that do not exist.
+
+@item -o
+@itemx --io-blocks
+@opindex -o
+@opindex --io-blocks
+Treat @var{size} as number of I/O blocks of the @var{file} rather than bytes.
+
+@item -r @var{rfile}
+@itemx --reference=@var{rfile}
+@opindex -r
+@opindex --reference
+Base the size of each @var{file} on the size of @var{rfile}.
+
+@item -s @var{size}
+@itemx --size=@var{size}
+@opindex -s
+@opindex --size
+Set or adjust the size of each @var{file} according to @var{size}.
+@var{size} is in bytes unless @option{--io-blocks} is specified.
+@multiplierSuffixesNoBlocks{size}
+
+@var{size} may also be prefixed by one of the following to adjust
+the size of each @var{file} based on its current size:
+@example
+@samp{+} => extend by
+@samp{-} => reduce by
+@samp{<} => at most
+@samp{>} => at least
+@samp{/} => round down to multiple of
+@samp{%} => round up to multiple of
+@end example
+
+@end table
@exitstatus
@@ -10049,6 +12013,8 @@ space between each and a newline after the last one. Synopsis:
echo [@var{option}]@dots{} [@var{string}]@dots{}
@end example
+@mayConflictWithShellBuiltIn{echo}
+
The program accepts the following options. Also see @ref{Common options}.
Options must precede operands, and the normally-special argument
@samp{--} has no special meaning and is treated like any other
@@ -10071,11 +12037,13 @@ alert (bell)
@item \b
backspace
@item \c
-suppress trailing newline
+produce no further output
+@item \e
+escape
@item \f
form feed
@item \n
-new line
+newline
@item \r
carriage return
@item \t
@@ -10086,10 +12054,12 @@ vertical tab
backslash
@item \0@var{nnn}
the eight-bit value that is the octal number @var{nnn}
-(zero to three octal digits)
+(zero to three octal digits), if @var{nnn} is
+a nine-bit value, the ninth bit is ignored
@item \@var{nnn}
the eight-bit value that is the octal number @var{nnn}
-(one to three octal digits)
+(one to three octal digits), if @var{nnn} is
+a nine-bit value, the ninth bit is ignored
@item \x@var{hh}
the eight-bit value that is the hexadecimal number @var{hh}
(one or two hexadecimal digits)
@@ -10111,7 +12081,7 @@ option-like arguments instead of treating them as options. For
example, @code{echo -ne hello} outputs @samp{-ne hello} instead of
plain @samp{hello}.
-@acronym{POSIX} does not require support for any options, and says
+POSIX does not require support for any options, and says
that the behavior of @command{echo} is implementation-defined if any
@var{string} contains a backslash or if the first argument is
@option{-n}. Portable programs can use the @command{printf} command
@@ -10133,8 +12103,12 @@ printf @var{format} [@var{argument}]@dots{}
@command{printf} prints the @var{format} string, interpreting @samp{%}
directives and @samp{\} escapes to format numeric and string arguments
-in a way that is mostly similar to the C @samp{printf} function. The
-differences are as follows:
+in a way that is mostly similar to the C @samp{printf} function.
+@xref{Output Conversion Syntax,, @command{printf} format directives,
+libc, The GNU C Library Reference Manual}, for details.
+The differences are listed below.
+
+@mayConflictWithShellBuiltIn{printf}
@itemize @bullet
@@ -10163,14 +12137,23 @@ one.
@item
@kindex %b
-@command{printf} has an additional directive, @samp{%b}, which prints its
+An additional directive @samp{%b}, prints its
argument string with @samp{\} escapes interpreted in the same way as in
the @var{format} string, except that octal escapes are of the form
-@samp{\0@var{ooo}} where @var{ooo} is 0 to 3 octal digits.
+@samp{\0@var{ooo}} where @var{ooo} is 0 to 3 octal digits. If
+@samp{\@var{ooo}} is nine-bit value, ignore the ninth bit.
If a precision is also given, it limits the number of bytes printed
from the converted string.
@item
+@kindex %q
+An additional directive @samp{%q}, prints its argument string
+in a format that can be reused as input by most shells.
+Non-printable characters are escaped with the POSIX proposed @samp{$''} syntax,
+and shell metacharacters are quoted appropriately.
+This is an equivalent format to @command{ls --quoting=shell-escape} output.
+
+@item
Numeric arguments must be single C constants, possibly with leading
@samp{+} or @samp{-}. For example, @samp{printf %.4d -3} outputs
@samp{-0003}.
@@ -10182,8 +12165,8 @@ then its value is the numeric value of the immediately following
character. Any remaining characters are silently ignored if the
@env{POSIXLY_CORRECT} environment variable is set; otherwise, a
warning is printed. For example, @samp{printf "%d" "'a"} outputs
-@samp{97} on hosts that use the @acronym{ASCII} character set, since
-@samp{a} has the numeric value 97 in @acronym{ASCII}.
+@samp{97} on hosts that use the ASCII character set, since
+@samp{a} has the numeric value 97 in ASCII.
@end itemize
@@ -10193,13 +12176,17 @@ digits, but is printed according to the @env{LC_NUMERIC} category of the
current locale. For example, in a locale whose radix character is a
comma, the command @samp{printf %g 3.14} outputs @samp{3,14} whereas
the command @samp{printf %g 3,14} is an error.
+@xref{Floating point}.
@kindex \@var{ooo}
@kindex \x@var{hh}
@command{printf} interprets @samp{\@var{ooo}} in @var{format} as an octal number
-(if @var{ooo} is 1 to 3 octal digits) specifying a character to print,
+(if @var{ooo} is 1 to 3 octal digits) specifying a byte to print,
and @samp{\x@var{hh}} as a hexadecimal number (if @var{hh} is 1 to 2 hex
digits) specifying a character to print.
+Note however that when @samp{\@var{ooo}} specifies a number larger than 255,
+@command{printf} ignores the ninth bit.
+For example, @samp{printf '\400'} is equivalent to @samp{printf '\0'}.
@kindex \uhhhh
@kindex \Uhhhhhhhh
@@ -10207,13 +12194,15 @@ digits) specifying a character to print.
@cindex ISO/IEC 10646
@vindex LC_CTYPE
@command{printf} interprets two character syntaxes introduced in
-@acronym{ISO} C 99:
-@samp{\u} for 16-bit Unicode (@acronym{ISO}/@acronym{IEC} 10646)
+ISO C 99:
+@samp{\u} for 16-bit Unicode (ISO/IEC 10646)
characters, specified as
four hexadecimal digits @var{hhhh}, and @samp{\U} for 32-bit Unicode
characters, specified as eight hexadecimal digits @var{hhhhhhhh}.
@command{printf} outputs the Unicode characters
-according to the @env{LC_CTYPE} locale.
+according to the @env{LC_CTYPE} locale. Unicode characters in the ranges
+U+0000@dots{}U+009F, U+D800@dots{}U+DFFF cannot be specified by this syntax,
+except for U+0024 ($), U+0040 (@@), and U+0060 (@`).
The processing of @samp{\u} and @samp{\U} requires a full-featured
@code{iconv} facility. It is activated on systems with glibc 2.2 (or newer),
@@ -10228,26 +12217,26 @@ The Unicode character syntaxes are useful for writing strings in a locale
independent way. For example, a string containing the Euro currency symbol
@example
-$ /usr/local/bin/printf '\u20AC 14.95'
+$ env printf '\u20AC 14.95'
@end example
@noindent
will be output correctly in all locales supporting the Euro symbol
-(@acronym{ISO}-8859-15, UTF-8, and others). Similarly, a Chinese string
+(ISO-8859-15, UTF-8, and others). Similarly, a Chinese string
@example
-$ /usr/local/bin/printf '\u4e2d\u6587'
+$ env printf '\u4e2d\u6587'
@end example
@noindent
will be output correctly in all Chinese locales (GB2312, BIG5, UTF-8, etc).
-Note that in these examples, the full name of @command{printf} has been
-given, to distinguish it from the GNU @code{bash} built-in function
-@command{printf}.
+Note that in these examples, the @command{printf} command has been
+invoked via @command{env} to ensure that we run the program found via
+your shell's search path, and not a shell alias or a built-in function.
For larger strings, you don't need to look up the hexadecimal code
-values of each character one by one. @acronym{ASCII} characters mixed with \u
+values of each character one by one. ASCII characters mixed with \u
escape sequences is also known as the JAVA source file encoding. You can
use GNU recode 3.5c (or newer) to convert strings to this encoding. Here
is how to convert a piece of text into a shell script which will output
@@ -10329,7 +12318,7 @@ exits unsuccessfully, even when invoked with
Portable programs should not assume that the exit status of
@command{false} is 1, as it is greater than 1 on some
-non-@acronym{GNU} hosts.
+non-GNU hosts.
@node true invocation
@@ -10401,15 +12390,12 @@ test
[ @var{option}
@end example
-@cindex conflicts with shell built-ins
-@cindex built-in shell commands, conflicts with
-Because most shells have a built-in @command{test} command, using an
-unadorned @command{test} in a script or interactively may get you
-different functionality than that described here.
+@mayConflictWithShellBuiltIn{test}
If @var{expression} is omitted, @command{test} returns false.
If @var{expression} is a single argument,
-@command{test} returns false if the argument is null and true otherwise. The argument
+@command{test} returns false if the argument is null and true
+otherwise. The argument
can be any string, including strings like @samp{-d}, @samp{-1},
@samp{--}, @samp{--help}, and @samp{--version} that most other
programs would treat as options. To get help and version information,
@@ -10429,7 +12415,7 @@ Exit status:
* File type tests:: -[bcdfhLpSt]
* Access permission tests:: -[gkruwxOG]
* File characteristic tests:: -e -s -nt -ot -ef
-* String tests:: -z -n = !=
+* String tests:: -z -n = == !=
* Numeric tests:: -eq -ne -lt -le -gt -ge
* Connectives for test:: ! -a -o
@end menu
@@ -10620,6 +12606,11 @@ True if the length of @var{string} is nonzero.
@cindex equal string check
True if the strings are equal.
+@item @var{string1} == @var{string2}
+@opindex ==
+@cindex equal string check
+True if the strings are equal (synonym for =).
+
@item @var{string1} != @var{string2}
@opindex !=
@cindex not-equal string check
@@ -10634,9 +12625,9 @@ True if the strings are not equal.
@cindex numeric tests
@cindex arithmetic tests
-Numeric relationals. The arguments must be entirely numeric (possibly
-negative), or the special expression @w{@code{-l @var{string}}}, which
-evaluates to the length of @var{string}.
+Numeric relational operators. The arguments must be entirely numeric
+(possibly negative), or the special expression @w{@code{-l @var{string}}},
+which evaluates to the length of @var{string}.
@table @samp
@@ -10676,25 +12667,55 @@ test 0x100 -eq 1
@cindex logical connectives
@cindex connectives, logical
-The usual logical connectives.
+Note it's preferred to use shell logical primitives
+rather than these logical connectives internal to @command{test},
+because an expression may become ambiguous
+depending on the expansion of its parameters.
+
+For example, this becomes ambiguous when @samp{$1}
+is set to @samp{'!'} and @samp{$2} to the empty string @samp{''}:
+
+@example
+test "$1" -a "$2"
+@end example
+
+and should be written as:
+
+@example
+test "$1" && test "$2"
+@end example
+
+Note the shell logical primitives also benefit from
+short circuit operation, which can be significant
+for file attribute tests.
@table @samp
@item ! @var{expr}
@opindex !
True if @var{expr} is false.
+@samp{!} has lower precedence than all parts of @var{expr}.
+Note @samp{!} needs to be specified to the left
+of a binary expression, I.e., @samp{'!' 1 -gt 2}
+rather than @samp{1 '!' -gt 2}.
+Also @samp{!} is often a shell special character
+and is best used quoted.
+
@item @var{expr1} -a @var{expr2}
@opindex -a
@cindex logical and operator
@cindex and operator
True if both @var{expr1} and @var{expr2} are true.
+@samp{-a} is left associative,
+and has a higher precedence than @samp{-o}.
@item @var{expr1} -o @var{expr2}
@opindex -o
@cindex logical or operator
@cindex or operator
True if either @var{expr1} or @var{expr2} is true.
+@samp{-o} is left associative.
@end table
@@ -10721,7 +12742,7 @@ e.g., spaces. However, regardless of whether it is quoted, a string
operand should not be a parenthesis or any of @command{expr}'s
operators like @code{+}, so you cannot safely pass an arbitrary string
@code{$str} to expr merely by quoting it to the shell. One way to
-work around this is to use the @sc{gnu} extension @code{+},
+work around this is to use the GNU extension @code{+},
(e.g., @code{+ "$str" = foo}); a more portable way is to use
@code{@w{" $str"}} and to adjust the rest of the expression to take
the leading space into account (e.g., @code{@w{" $str" = " foo"}}).
@@ -10739,6 +12760,10 @@ may be used for grouping in the usual manner. You must quote
parentheses and many operators to avoid the shell evaluating them,
however.
+When built with support for the GNU MP library, @command{expr} uses
+arbitrary-precision arithmetic; otherwise, it uses native arithmetic
+types and may fail due to arithmetic overflow.
+
The only options are @option{--help} and @option{--version}. @xref{Common
options}. Options must precede operands.
@@ -10767,7 +12792,7 @@ Exit status:
@cindex expressions, string
@command{expr} supports pattern matching and other string operators. These
-have lower precedence than both the numeric and relational operators (in
+have higher precedence than both the numeric and relational operators (in
the next sections).
@table @samp
@@ -10799,7 +12824,7 @@ expression operators.
In the regular expression, @code{\+}, @code{\?}, and @code{\|} are
operators which respectively match one or more, zero or one, or separate
alternatives. SunOS and other @command{expr}'s treat these as regular
-characters. (@acronym{POSIX} allows either behavior.)
+characters. (POSIX allows either behavior.)
@xref{Top, , Regular Expression Library, regex, Regex}, for details of
regular expression syntax. Some examples are in @ref{Examples of expr}.
@@ -10831,7 +12856,7 @@ or an operator like @code{/}.
This makes it possible to test @code{expr length + "$x"} or
@code{expr + "$x" : '.*/\(.\)'} and have it do the right thing even if
the value of @var{$x} happens to be (for example) @code{/} or @code{index}.
-This operator is a @acronym{GNU} extension. Portable shell scripts should use
+This operator is a GNU extension. Portable shell scripts should use
@code{@w{" $token"} : @w{' \(.*\)'}} instead of @code{+ "$token"}.
@end table
@@ -10847,8 +12872,9 @@ To make @command{expr} interpret keywords as strings, you must use the
@cindex expressions, numeric
@command{expr} supports the usual numeric operators, in order of increasing
-precedence. The string operators (previous section) have lower precedence,
-the connectives (next section) have higher.
+precedence. These numeric operators have lower precedence than the
+string operators described in the previous section, and higher precedence
+than the connectives (next section).
@table @samp
@@ -10881,7 +12907,7 @@ integers; an error occurs if this cannot be done.
@cindex relations, numeric or string
@command{expr} supports the usual logical connectives and relations. These
-are higher precedence than either the string or numeric operators
+have lower precedence than the string and numeric operators
(previous sections). Here is the list, lowest-precedence operator first.
@table @samp
@@ -10930,7 +12956,7 @@ Here are a few examples, including quoting for shell metacharacters.
To add 1 to the shell variable @code{foo}, in Bourne-compatible shells:
@example
-foo=`expr $foo + 1`
+foo=$(expr $foo + 1)
@end example
To print the non-directory part of the file name stored in
@@ -10954,7 +12980,7 @@ expr index abcdef cz
@result{} 3
expr index index a
@error{} expr: syntax error
-expr index quote index a
+expr index + index a
@result{} 0
@end example
@@ -10971,12 +12997,12 @@ useful redirection is performed by a separate command, not by the shell;
it's described here.
@menu
-* tee invocation:: Redirect output to multiple files.
+* tee invocation:: Redirect output to multiple files or processes.
@end menu
@node tee invocation
-@section @command{tee}: Redirect output to multiple files
+@section @command{tee}: Redirect output to multiple files or processes
@pindex tee
@cindex pipe fitting
@@ -10995,9 +13021,11 @@ 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 @option{-a} option is used.
-A @var{file} of @samp{-} causes @command{tee} to send another copy of
-input to standard output, but this is typically not that useful as the
-copies are interleaved.
+In previous versions of GNU coreutils (v5.3.0 - v8.23), a @var{file} of @samp{-}
+caused @command{tee} to send another copy of input to standard output.
+However, as the interleaved output was not very useful, @command{tee} now
+conforms to POSIX which explicitly mandates it to treat @samp{-} as a file
+with such name.
The program accepts the following options. Also see @ref{Common options}.
@@ -11015,8 +13043,158 @@ them.
@opindex --ignore-interrupts
Ignore interrupt signals.
+@item -p
+@itemx --output-error[=@var{mode}]
+@opindex -p
+@opindex --output-error
+Adjust the behavior with errors on the outputs,
+with the long form option supporting selection
+between the following @var{mode}s:
+
+@table @samp
+@item warn
+Warn on error opening or writing any output, including pipes.
+Writing is continued to still open files/pipes.
+Exit status indicates failure if any output has an error.
+
+@item warn-nopipe
+This is the default @var{mode} when not specified,
+or when the short form @option{-p} is used.
+Warn on error opening or writing any output, except pipes.
+Writing is continued to still open files/pipes.
+Exit status indicates failure if any non pipe output had an error.
+
+@item exit
+Exit on error opening or writing any output, including pipes.
+
+@item exit-nopipe
+Exit on error opening or writing any output, except pipes.
+@end table
+
@end table
+The @command{tee} command is useful when you happen to be transferring a large
+amount of data and also want to summarize that data without reading
+it a second time. For example, when you are downloading a DVD image,
+you often want to verify its signature or checksum right away.
+The inefficient way to do it is simply:
+
+@example
+wget http://example.com/some.iso && sha1sum some.iso
+@end example
+
+One problem with the above is that it makes you wait for the
+download to complete before starting the time-consuming SHA1 computation.
+Perhaps even more importantly, the above requires reading
+the DVD image a second time (the first was from the network).
+
+The efficient way to do it is to interleave the download
+and SHA1 computation. Then, you'll get the checksum for
+free, because the entire process parallelizes so well:
+
+@example
+# slightly contrived, to demonstrate process substitution
+wget -O - http://example.com/dvd.iso \
+ | tee >(sha1sum > dvd.sha1) > dvd.iso
+@end example
+
+That makes @command{tee} write not just to the expected output file,
+but also to a pipe running @command{sha1sum} and saving the final
+checksum in a file named @file{dvd.sha1}.
+
+Note, however, that this example relies on a feature of modern shells
+called @dfn{process substitution}
+(the @samp{>(command)} syntax, above;
+@xref{Process Substitution,,Process Substitution, bash,
+The Bash Reference Manual}.),
+so it works with @command{zsh}, @command{bash}, and @command{ksh},
+but not with @command{/bin/sh}. So if you write code like this
+in a shell script, be sure to start the script with @samp{#!/bin/bash}.
+
+Note also that if any of the process substitutions (or piped stdout)
+might exit early without consuming all the data, the @option{-p} option
+is needed to allow @command{tee} to continue to process the input
+to any remaining outputs.
+
+Since the above example writes to one file and one process,
+a more conventional and portable use of @command{tee} is even better:
+
+@example
+wget -O - http://example.com/dvd.iso \
+ | tee dvd.iso | sha1sum > dvd.sha1
+@end example
+
+You can extend this example to make @command{tee} write to two processes,
+computing MD5 and SHA1 checksums in parallel. In this case,
+process substitution is required:
+
+@example
+wget -O - http://example.com/dvd.iso \
+ | tee >(sha1sum > dvd.sha1) \
+ >(md5sum > dvd.md5) \
+ > dvd.iso
+@end example
+
+This technique is also useful when you want to make a @emph{compressed}
+copy of the contents of a pipe.
+Consider a tool to graphically summarize disk usage data from @samp{du -ak}.
+For a large hierarchy, @samp{du -ak} can run for a long time,
+and can easily produce terabytes of data, so you won't want to
+rerun the command unnecessarily. Nor will you want to save
+the uncompressed output.
+
+Doing it the inefficient way, you can't even start the GUI
+until after you've compressed all of the @command{du} output:
+
+@example
+du -ak | gzip -9 > /tmp/du.gz
+gzip -d /tmp/du.gz | xdiskusage -a
+@end example
+
+With @command{tee} and process substitution, you start the GUI
+right away and eliminate the decompression completely:
+
+@example
+du -ak | tee >(gzip -9 > /tmp/du.gz) | xdiskusage -a
+@end example
+
+Finally, if you regularly create more than one type of
+compressed tarball at once, for example when @code{make dist} creates
+both @command{gzip}-compressed and @command{bzip2}-compressed tarballs,
+there may be a better way.
+Typical @command{automake}-generated @file{Makefile} rules create
+the two compressed tar archives with commands in sequence, like this
+(slightly simplified):
+
+@example
+tardir=your-pkg-M.N
+tar chof - "$tardir" | gzip -9 -c > your-pkg-M.N.tar.gz
+tar chof - "$tardir" | bzip2 -9 -c > your-pkg-M.N.tar.bz2
+@end example
+
+However, if the hierarchy you are archiving and compressing is larger
+than a couple megabytes, and especially if you are using a multi-processor
+system with plenty of memory, then you can do much better by reading the
+directory contents only once and running the compression programs in parallel:
+
+@example
+tardir=your-pkg-M.N
+tar chof - "$tardir" \
+ | tee >(gzip -9 -c > your-pkg-M.N.tar.gz) \
+ | bzip2 -9 -c > your-pkg-M.N.tar.bz2
+@end example
+
+If you want to further process the output from process substitutions,
+and those processes write atomically (i.e., write less than the system's
+PIPE_BUF size at a time), that's possible with a construct like:
+
+@example
+tardir=your-pkg-M.N
+tar chof - "$tardir" \
+ | tee >(md5sum --tag) > >(sha256sum --tag) \
+ | sort | gpg --clearsign > your-pkg-M.N.tar.sig
+@end example
+
@exitstatus
@@ -11031,8 +13209,10 @@ This section describes commands that manipulate file names.
@menu
* basename invocation:: Strip directory and suffix from a file name.
-* dirname invocation:: Strip non-directory suffix from a file name.
-* pathchk invocation:: Check file name portability.
+* dirname invocation:: Strip last file name component.
+* pathchk invocation:: Check file name validity and portability.
+* mktemp invocation:: Create temporary file or directory.
+* realpath invocation:: Print resolved file names.
@end menu
@@ -11051,6 +13231,7 @@ This section describes commands that manipulate file names.
@example
basename @var{name} [@var{suffix}]
+basename @var{option}@dots{} @var{name}@dots{}
@end example
If @var{suffix} is specified and is identical to the end of @var{name},
@@ -11068,14 +13249,35 @@ for everything except file names containing a trailing newline.
@end macro
@basenameAndDirname
-@acronym{POSIX} allows the implementation to define the results if
-@var{name} is empty or @samp{//}. In the former case, @acronym{GNU}
+POSIX allows the implementation to define the results if
+@var{name} is empty or @samp{//}. In the former case, GNU
@command{basename} returns the empty string. In the latter case, the
result is @samp{//} on platforms where @var{//} is distinct from
@var{/}, and @samp{/} on platforms where there is no difference.
-The only options are @option{--help} and @option{--version}. @xref{Common
-options}. Options must precede operands.
+The program accepts the following options. Also see @ref{Common options}.
+Options must precede operands.
+
+@table @samp
+
+@item -a
+@itemx --multiple
+@opindex -a
+@opindex --multiple
+Support more than one argument. Treat every argument as a @var{name}.
+With this, an optional @var{suffix} must be specified using the
+@option{-s} option.
+
+@item -s @var{suffix}
+@itemx --suffix=@var{suffix}
+@opindex -s
+@opindex --suffix
+Remove a trailing @var{suffix}.
+This option implies the @option{-a} option.
+
+@optZero
+
+@end table
@exitstatus
@@ -11087,36 +13289,50 @@ basename /usr/bin/sort
# Output "stdio".
basename include/stdio.h .h
+
+# Output "stdio".
+basename -s .h include/stdio.h
+
+# Output "stdio" followed by "stdlib"
+basename -a -s .h include/stdio.h include/stdlib.h
@end smallexample
@node dirname invocation
-@section @command{dirname}: Strip non-directory suffix from a file name
+@section @command{dirname}: Strip last file name component
@pindex dirname
@cindex directory components, printing
@cindex stripping non-directory suffix
@cindex non-directory suffix, stripping
-@command{dirname} prints all but the final slash-delimited component of
-a string (presumably a file name). Synopsis:
+@command{dirname} prints all but the final slash-delimited component
+of each @var{name}. Slashes on either side of the final component are
+also removed. If the string contains no slash, @command{dirname}
+prints @samp{.} (meaning the current directory). Synopsis:
@example
-dirname @var{name}
+dirname [@var{option}] @var{name}@dots{}
@end example
-If @var{name} is a single component, @command{dirname} prints @samp{.}
-(meaning the current directory).
+@var{name} need not be a file name, but if it is, this operation
+effectively lists the directory that contains the final component,
+including the case when the final component is itself a directory.
@basenameAndDirname
-@acronym{POSIX} allows the implementation to define the results if
-@var{name} is @samp{//}. With @acronym{GNU} @command{dirname}, the
+POSIX allows the implementation to define the results if
+@var{name} is @samp{//}. With GNU @command{dirname}, the
result is @samp{//} on platforms where @var{//} is distinct from
@var{/}, and @samp{/} on platforms where there is no difference.
-The only options are @option{--help} and @option{--version}. @xref{Common
-options}.
+The program accepts the following option. Also see @ref{Common options}.
+
+@table @samp
+
+@optZero
+
+@end table
@exitstatus
@@ -11125,6 +13341,10 @@ Examples:
@smallexample
# Output "/usr/bin".
dirname /usr/bin/sort
+dirname /usr/bin//.//
+
+# Output "dir1" followed by "dir2"
+dirname dir1/str dir2/str
# Output ".".
dirname stdio.h
@@ -11132,20 +13352,20 @@ dirname stdio.h
@node pathchk invocation
-@section @command{pathchk}: Check file name portability
+@section @command{pathchk}: Check file name validity and portability
@pindex pathchk
@cindex file names, checking validity and portability
@cindex valid file names, checking for
@cindex portable file names, checking for
-@command{pathchk} checks portability of file names. Synopsis:
+@command{pathchk} checks validity and portability of file names. Synopsis:
@example
pathchk [@var{option}]@dots{} @var{name}@dots{}
@end example
-For each @var{name}, @command{pathchk} prints a message if any of
+For each @var{name}, @command{pathchk} prints an error message if any of
these conditions is true:
@enumerate
@@ -11171,30 +13391,30 @@ Options must precede operands.
@item -p
@opindex -p
Instead of performing checks based on the underlying file system,
-print a message if any of these conditions is true:
+print an error message if any of these conditions is true:
@enumerate
@item
A file name is empty.
@item
-The length of a file name or one of its components exceeds the
-@acronym{POSIX} minimum limits for portability.
+A file name contains a character outside the POSIX portable file
+name character set, namely, the ASCII letters and digits, @samp{.},
+@samp{_}, @samp{-}, and @samp{/}.
@item
-A file name contains a character outside the portable file name
-character set, namely, the ASCII letters and digits, @samp{-},
-@samp{.}, @samp{/}, and @samp{_}.
+The length of a file name or one of its components exceeds the
+POSIX minimum limits for portability.
@end enumerate
@item -P
@opindex -P
-Print a message if a file name is empty, or if it contains a component
+Print an error message if a file name is empty, or if it contains a component
that begins with @samp{-}.
@item --portability
@opindex --portability
-Print a message if a file name is not portable to all @acronym{POSIX}
+Print an error message if a file name is not portable to all POSIX
hosts. This option is equivalent to @samp{-p -P}.
@end table
@@ -11207,6 +13427,293 @@ Exit status:
1 otherwise.
@end display
+@node mktemp invocation
+@section @command{mktemp}: Create temporary file or directory
+
+@pindex mktemp
+@cindex file names, creating temporary
+@cindex directory, creating temporary
+@cindex temporary files and directories
+
+@command{mktemp} manages the creation of temporary files and
+directories. Synopsis:
+
+@example
+mktemp [@var{option}]@dots{} [@var{template}]
+@end example
+
+Safely create a temporary file or directory based on @var{template},
+and print its name. If given, @var{template} must include at least
+three consecutive @samp{X}s in the last component. If omitted, the template
+@samp{tmp.XXXXXXXXXX} is used, and option @option{--tmpdir} is
+implied. The final run of @samp{X}s in the @var{template} will be replaced
+by alpha-numeric characters; thus, on a case-sensitive file system,
+and with a @var{template} including a run of @var{n} instances of @samp{X},
+there are @samp{62**@var{n}} potential file names.
+
+Older scripts used to create temporary files by simply joining the
+name of the program with the process id (@samp{$$}) as a suffix.
+However, that naming scheme is easily predictable, and suffers from a
+race condition where the attacker can create an appropriately named
+symbolic link, such that when the script then opens a handle to what
+it thought was an unused file, it is instead modifying an existing
+file. Using the same scheme to create a directory is slightly safer,
+since the @command{mkdir} will fail if the target already exists, but
+it is still inferior because it allows for denial of service attacks.
+Therefore, modern scripts should use the @command{mktemp} command to
+guarantee that the generated name will be unpredictable, and that
+knowledge of the temporary file name implies that the file was created
+by the current script and cannot be modified by other users.
+
+When creating a file, the resulting file has read and write
+permissions for the current user, but no permissions for the group or
+others; these permissions are reduced if the current umask is more
+restrictive.
+
+Here are some examples (although note that if you repeat them, you
+will most likely get different file names):
+
+@itemize @bullet
+
+@item
+Create a temporary file in the current directory.
+@example
+$ mktemp file.XXXX
+file.H47c
+@end example
+
+@item
+Create a temporary file with a known suffix.
+@example
+$ mktemp --suffix=.txt file-XXXX
+file-H08W.txt
+$ mktemp file-XXXX-XXXX.txt
+file-XXXX-eI9L.txt
+@end example
+
+@item
+Create a secure fifo relative to the user's choice of @env{TMPDIR},
+but falling back to the current directory rather than @file{/tmp}.
+Note that @command{mktemp} does not create fifos, but can create a
+secure directory in which the fifo can live. Exit the shell if the
+directory or fifo could not be created.
+@example
+$ dir=$(mktemp -p "$@{TMPDIR:-.@}" -d dir-XXXX) || exit 1
+$ fifo=$dir/fifo
+$ mkfifo "$fifo" || @{ rmdir "$dir"; exit 1; @}
+@end example
+
+@item
+Create and use a temporary file if possible, but ignore failure. The
+file will reside in the directory named by @env{TMPDIR}, if specified,
+or else in @file{/tmp}.
+@example
+$ file=$(mktemp -q) && @{
+> # Safe to use $file only within this block. Use quotes,
+> # since $TMPDIR, and thus $file, may contain whitespace.
+> echo ... > "$file"
+> rm "$file"
+> @}
+@end example
+
+@item
+Act as a semi-random character generator (it is not fully random,
+since it is impacted by the contents of the current directory). To
+avoid security holes, do not use the resulting names to create a file.
+@example
+$ mktemp -u XXX
+Gb9
+$ mktemp -u XXX
+nzC
+@end example
+
+@end itemize
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+
+@item -d
+@itemx --directory
+@opindex -d
+@opindex --directory
+Create a directory rather than a file. The directory will have read,
+write, and search permissions for the current user, but no permissions
+for the group or others; these permissions are reduced if the current
+umask is more restrictive.
+
+@item -q
+@itemx --quiet
+@opindex -q
+@opindex --quiet
+Suppress diagnostics about failure to create a file or directory. The
+exit status will still reflect whether a file was created.
+
+@item -u
+@itemx --dry-run
+@opindex -u
+@opindex --dry-run
+Generate a temporary name that does not name an existing file, without
+changing the file system contents. Using the output of this command
+to create a new file is inherently unsafe, as there is a window of
+time between generating the name and using it where another process
+can create an object by the same name.
+
+@item -p @var{dir}
+@itemx --tmpdir[=@var{dir}]
+@opindex -p
+@opindex --tmpdir
+Treat @var{template} relative to the directory @var{dir}. If
+@var{dir} is not specified (only possible with the long option
+@option{--tmpdir}) or is the empty string, use the value of
+@env{TMPDIR} if available, otherwise use @samp{/tmp}. If this is
+specified, @var{template} must not be absolute. However,
+@var{template} can still contain slashes, although intermediate
+directories must already exist.
+
+@item --suffix=@var{suffix}
+@opindex --suffix
+Append @var{suffix} to the @var{template}. @var{suffix} must not
+contain slash. If @option{--suffix} is specified, @var{template} must
+end in @samp{X}; if it is not specified, then an appropriate
+@option{--suffix} is inferred by finding the last @samp{X} in
+@var{template}. This option exists for use with the default
+@var{template} and for the creation of a @var{suffix} that starts with
+@samp{X}.
+
+@item -t
+@opindex -t
+Treat @var{template} as a single file relative to the value of
+@env{TMPDIR} if available, or to the directory specified by
+@option{-p}, otherwise to @samp{/tmp}. @var{template} must not
+contain slashes. This option is deprecated; the use of @option{-p}
+without @option{-t} offers better defaults (by favoring the command
+line over @env{TMPDIR}) and more flexibility (by allowing intermediate
+directories).
+
+@end table
+
+@cindex exit status of @command{mktemp}
+Exit status:
+
+@display
+0 if the file was created,
+1 otherwise.
+@end display
+
+
+@node realpath invocation
+@section @command{realpath}: Print the resolved file name.
+
+@pindex realpath
+@cindex file names, canonicalization
+@cindex symlinks, resolution
+@cindex canonical file name
+@cindex canonicalize a file name
+@pindex realpath
+@findex realpath
+
+@command{realpath} expands all symbolic links and resolves references to
+@samp{/./}, @samp{/../} and extra @samp{/} characters. By default,
+all but the last component of the specified files must exist. Synopsis:
+
+@example
+realpath [@var{option}]@dots{} @var{file}@dots{}
+@end example
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+
+@item -e
+@itemx --canonicalize-existing
+@opindex -e
+@opindex --canonicalize-existing
+Ensure that all components of the specified file names exist.
+If any component is missing or unavailable, @command{realpath} will output
+a diagnostic unless the @option{-q} option is specified, and exit with a
+nonzero exit code. A trailing slash requires that the name resolve to a
+directory.
+
+@item -m
+@itemx --canonicalize-missing
+@opindex -m
+@opindex --canonicalize-missing
+If any component of a specified file name is missing or unavailable,
+treat it as a directory.
+
+@item -L
+@itemx --logical
+@opindex -L
+@opindex --logical
+Symbolic links are resolved in the specified file names,
+but they are resolved after any subsequent @samp{..} components are processed.
+
+@item -P
+@itemx --physical
+@opindex -P
+@opindex --physical
+Symbolic links are resolved in the specified file names,
+and they are resolved before any subsequent @samp{..} components are processed.
+This is the default mode of operation.
+
+@item -q
+@itemx --quiet
+@opindex -q
+@opindex --quiet
+Suppress diagnostic messages for specified file names.
+
+@item --relative-to=@var{file}
+@opindex --relative-to
+@cindex relpath
+Print the resolved file names relative to the specified file.
+Note this option honors the @option{-m} and @option{-e} options
+pertaining to file existence.
+
+@item --relative-base=@var{base}
+@opindex --relative-base
+This option is valid when used with @option{--relative-to}, and will restrict
+the output of @option{--relative-to} so that relative names are output,
+only when @var{file}s are descendants of @var{base}. Otherwise output the
+absolute file name. If @option{--relative-to} was not specified, then
+the descendants of @var{base} are printed relative to @var{base}. If
+@option{--relative-to} is specified, then that directory must be a
+descendant of @var{base} for this option to have an effect.
+Note: this option honors the @option{-m} and @option{-e}
+options pertaining to file existence. For example:
+
+@example
+realpath --relative-to=/usr /tmp /usr/bin
+@result{} ../tmp
+@result{} bin
+realpath --relative-base=/usr /tmp /usr/bin
+@result{} /tmp
+@result{} bin
+@end example
+
+@item -s
+@itemx --strip
+@itemx --no-symlinks
+@opindex -s
+@opindex --strip
+@opindex --no-symlinks
+Do not resolve symbolic links. Only resolve references to
+@samp{/./}, @samp{/../} and remove extra @samp{/} characters.
+When combined with the @option{-m} option, realpath operates
+only on the file name, and does not touch any actual file.
+
+@optZero
+
+@end table
+
+@cindex exit status of @command{realpath}
+Exit status:
+
+@display
+0 if all file names were printed without issue.
+1 otherwise.
+@end display
+
@node Working context
@chapter Working context
@@ -11234,19 +13741,41 @@ so forth. See also the user-related commands in the next section.
@cindex current working directory, printing
@cindex working directory, printing
-@cindex symbolic links and @command{pwd}
-@command{pwd} 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.
-@cindex conflicts with shell built-ins
-@cindex built-in shell commands, conflicts with
-Because most shells have a built-in @command{pwd} command, using an
-unadorned @command{pwd} in a script or interactively may get you
-different functionality than that described here.
+@command{pwd} prints the name of the current directory. Synopsis:
-The only options are a lone @option{--help} or
-@option{--version}. @xref{Common options}.
+@example
+pwd [@var{option}]@dots{}
+@end example
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+@item -L
+@itemx --logical
+@opindex -L
+@opindex --logical
+If the contents of the environment variable @env{PWD} provide an
+absolute name of the current directory with no @samp{.} or @samp{..}
+components, but possibly with symbolic links, then output those
+contents. Otherwise, fall back to default @option{-P} handling.
+
+@item -P
+@itemx --physical
+@opindex -P
+@opindex --physical
+Print a fully resolved name for the current directory. That is, all
+components of the printed name will be actual directory names---none
+will be symbolic links.
+@end table
+
+@cindex symbolic links and @command{pwd}
+If @option{-L} and @option{-P} are both given, the last one takes
+precedence. If neither option is given, then this implementation uses
+@option{-P} as the default unless the @env{POSIXLY_CORRECT}
+environment variable is set.
+
+@mayConflictWithShellBuiltIn{pwd}
@exitstatus
@@ -11293,8 +13822,9 @@ be used in combination with any line settings.
@opindex --file
Set the line opened by the file name specified in @var{device} instead of
the tty line connected to standard input. This option is necessary
-because opening a @acronym{POSIX} tty requires use of the @code{O_NONDELAY} flag to
-prevent a @acronym{POSIX} tty from blocking until the carrier detect line is high if
+because opening a POSIX tty requires use of the
+@code{O_NONDELAY} flag to prevent a POSIX tty from blocking
+until the carrier detect line is high if
the @code{clocal} flag is not set. Hence, it is not always possible
to allow the shell to open the device in the traditional manner.
@@ -11315,12 +13845,17 @@ description. The descriptions themselves refer to the positive
case, that is, when @emph{not} negated (unless stated otherwise,
of course).
-Some settings are not available on all @acronym{POSIX} systems, since they use
-extensions. Such arguments are marked below with ``Non-@acronym{POSIX}'' in their
-description. On non-@acronym{POSIX} systems, those or other settings also may not
+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.
+@command{stty} is installed only on platforms with the POSIX terminal
+interface, so portable scripts should not rely on its existence on
+non-POSIX platforms.
+
@exitstatus
@menu
@@ -11353,6 +13888,16 @@ May be negated.
@cindex even parity
Set odd parity (even if negated). May be negated.
+@item cmspar
+@opindex cmspar
+@cindex constant parity
+@cindex stick parity
+@cindex mark parity
+@cindex space parity
+Use "stick" (mark/space) parity. If parodd is set, the parity bit is
+always 1; if parodd is not set, the parity bit is always zero.
+Non-POSIX@. May be negated.
+
@item cs5
@itemx cs6
@itemx cs7
@@ -11387,7 +13932,14 @@ Disable modem control signals. May be negated.
@cindex hardware flow control
@cindex flow control, hardware
@cindex RTS/CTS flow control
-Enable RTS/CTS flow control. Non-@acronym{POSIX}. May be negated.
+Enable RTS/CTS flow control. Non-POSIX@. May be negated.
+
+@item cdtrdsr
+@opindex cdtrdsr
+@cindex hardware flow control
+@cindex flow control, hardware
+@cindex DTR/DSR flow control
+Enable DTR/DSR flow control. Non-POSIX@. May be negated.
@end table
@@ -11395,6 +13947,7 @@ Enable RTS/CTS flow control. Non-@acronym{POSIX}. May be negated.
@subsection Input settings
@cindex input settings
+These settings control operations on data received from the terminal.
@table @samp
@item ignbrk
@@ -11450,7 +14003,7 @@ Assume input characters are UTF-8 encoded. May be negated.
@opindex ixon
@kindex C-s/C-q flow control
@cindex XON/XOFF flow control
-Enable XON/XOFF flow control (that is, @kbd{CTRL-S}/@kbd{CTRL-Q}). May
+Enable XON/XOFF flow control (that is, @kbd{Ctrl-S}/@kbd{Ctrl-Q}). May
be negated.
@item ixoff
@@ -11466,19 +14019,20 @@ empty again. May be negated.
@item iuclc
@opindex iuclc
@cindex uppercase, translating to lowercase
-Translate uppercase characters to lowercase. Non-@acronym{POSIX}. May be
-negated.
+Translate uppercase characters to lowercase. Non-POSIX@. May be
+negated. Note ilcuc is not implemented, as one would not be able to issue
+almost any (lowercase) Unix command, after invoking it.
@item ixany
@opindex ixany
Allow any character to restart output (only the start character
-if negated). Non-@acronym{POSIX}. May be negated.
+if negated). Non-POSIX@. May be negated.
@item imaxbel
@opindex imaxbel
@cindex beeping at input buffer full
Enable beeping and not flushing input buffer if a character arrives
-when the input buffer is full. Non-@acronym{POSIX}. May be negated.
+when the input buffer is full. Non-POSIX@. May be negated.
@end table
@@ -11486,7 +14040,7 @@ when the input buffer is full. Non-@acronym{POSIX}. May be negated.
@subsection Output settings
@cindex output settings
-These arguments specify output-related operations.
+These settings control operations on data sent to the terminal.
@table @samp
@item opost
@@ -11496,74 +14050,76 @@ Postprocess output. May be negated.
@item olcuc
@opindex olcuc
@cindex lowercase, translating to output
-Translate lowercase characters to uppercase. Non-@acronym{POSIX}. May be
-negated.
+Translate lowercase characters to uppercase. Non-POSIX@. May be
+negated. (Note ouclc is not currently implemented.)
@item ocrnl
@opindex ocrnl
@cindex return, translating to newline
-Translate carriage return to newline. Non-@acronym{POSIX}. May be negated.
+Translate carriage return to newline. Non-POSIX@. May be negated.
@item onlcr
@opindex onlcr
@cindex newline, translating to crlf
-Translate newline to carriage return-newline. Non-@acronym{POSIX}. May be
+Translate newline to carriage return-newline. Non-POSIX@. May be
negated.
@item onocr
@opindex onocr
-Do not print carriage returns in the first column. Non-@acronym{POSIX}.
+Do not print carriage returns in the first column. Non-POSIX@.
May be negated.
@item onlret
@opindex onlret
-Newline performs a carriage return. Non-@acronym{POSIX}. May be negated.
+Newline performs a carriage return. Non-POSIX@. May be negated.
@item ofill
@opindex ofill
@cindex pad instead of timing for delaying
-Use fill (padding) characters instead of timing for delays. Non-@acronym{POSIX}.
+Use fill (padding) characters instead of timing for delays.
+Non-POSIX@.
May be negated.
@item ofdel
@opindex ofdel
@cindex pad character
-Use delete characters for fill instead of null characters. Non-@acronym{POSIX}.
+Use ASCII DEL characters for fill instead of
+ASCII NUL characters. Non-POSIX@.
May be negated.
@item nl1
@itemx nl0
@opindex nl@var{n}
-Newline delay style. Non-@acronym{POSIX}.
+Newline delay style. Non-POSIX.
@item cr3
@itemx cr2
@itemx cr1
@itemx cr0
@opindex cr@var{n}
-Carriage return delay style. Non-@acronym{POSIX}.
+Carriage return delay style. Non-POSIX.
@item tab3
@itemx tab2
@itemx tab1
@itemx tab0
@opindex tab@var{n}
-Horizontal tab delay style. Non-@acronym{POSIX}.
+Horizontal tab delay style. Non-POSIX.
@item bs1
@itemx bs0
@opindex bs@var{n}
-Backspace delay style. Non-@acronym{POSIX}.
+Backspace delay style. Non-POSIX.
@item vt1
@itemx vt0
@opindex vt@var{n}
-Vertical tab delay style. Non-@acronym{POSIX}.
+Vertical tab delay style. Non-POSIX.
@item ff1
@itemx ff0
@opindex ff@var{n}
-Form feed delay style. Non-@acronym{POSIX}.
+Form feed delay style. Non-POSIX.
@end table
@@ -11585,7 +14141,7 @@ special characters. May be negated.
@item iexten
@opindex iexten
-Enable non-@acronym{POSIX} special characters. May be negated.
+Enable non-POSIX special characters. May be negated.
@item echo
@opindex echo
@@ -11619,12 +14175,12 @@ characters. May be negated.
@cindex case translation
Enable input and output of uppercase characters by preceding their
lowercase equivalents with @samp{\}, when @code{icanon} is set.
-Non-@acronym{POSIX}. May be negated.
+Non-POSIX@. May be negated.
@item tostop
@opindex tostop
@cindex background jobs, stopping at terminal write
-Stop background jobs that try to write to the terminal. Non-@acronym{POSIX}.
+Stop background jobs that try to write to the terminal. Non-POSIX@.
May be negated.
@item echoprt
@@ -11632,7 +14188,7 @@ May be negated.
@opindex echoprt
@opindex prterase
Echo erased characters backward, between @samp{\} and @samp{/}.
-Non-@acronym{POSIX}. May be negated.
+Non-POSIX@. May be negated.
@item echoctl
@itemx ctlecho
@@ -11641,7 +14197,7 @@ Non-@acronym{POSIX}. May be negated.
@cindex control characters, using @samp{^@var{c}}
@cindex hat notation for control characters
Echo control characters in hat notation (@samp{^@var{c}}) instead
-of literally. Non-@acronym{POSIX}. May be negated.
+of literally. Non-POSIX@. May be negated.
@item echoke
@itemx crtkill
@@ -11649,7 +14205,23 @@ of literally. Non-@acronym{POSIX}. May be negated.
@opindex crtkill
Echo the @code{kill} special character by erasing each character on
the line as indicated by the @code{echoprt} and @code{echoe} settings,
-instead of by the @code{echoctl} and @code{echok} settings. Non-@acronym{POSIX}.
+instead of by the @code{echoctl} and @code{echok} settings.
+Non-POSIX@.
+May be negated.
+
+@item extproc
+@opindex extproc
+Enable @samp{LINEMODE}, which is used to avoid echoing
+each character over high latency links. See also
+@uref{ftp://ftp.rfc-editor.org/in-notes/rfc1116.txt, Internet RFC 1116}.
+Non-POSIX@.
+May be negated.
+
+@item flusho
+@opindex flusho
+Discard output.
+Note this setting is currently ignored on GNU/Linux systems.
+Non-POSIX@.
May be negated.
@end table
@@ -11689,11 +14261,11 @@ Same as:
@c This is too long to write inline.
@example
-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
+cread -ignbrk brkint -inlcr -igncr icrnl
+icanon iexten echo echoe echok -echonl -noflsh
+-ixoff -iutf8 -iuclc -ixany imaxbel -xcase -olcuc -ocrnl
+opost -ofill onlcr -onocr -onlret nl0 cr0 tab0 bs0 vt0 ff0
+isig -tostop -ofdel -echoprt echoctl echoke -extproc
@end example
@noindent
@@ -11712,8 +14284,8 @@ Same as:
@example
-ignbrk -brkint -ignpar -parmrk -inpck -istrip
--inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany
--imaxbel -opost -isig -icanon -xcase min 1 time 0
+-inlcr -igncr -icrnl -ixon -ixoff -icanon -opost
+-isig -iuclc -ixany -imaxbel -xcase min 1 time 0
@end example
@noindent
@@ -11737,18 +14309,19 @@ If negated, same as @code{parenb istrip opost cs7}.
@item decctlq
@opindex decctlq
-Same as @option{-ixany}. Non-@acronym{POSIX}. May be negated.
+Same as @option{-ixany}. Non-POSIX@. May be negated.
@item tabs
@opindex tabs
-Same as @code{tab0}. Non-@acronym{POSIX}. May be negated. If negated, same
+Same as @code{tab0}. Non-POSIX@. May be negated. If negated, same
as @code{tab3}.
@item lcase
@itemx LCASE
@opindex lcase
@opindex LCASE
-Same as @code{xcase iuclc olcuc}. Non-@acronym{POSIX}. May be negated.
+Same as @code{xcase iuclc olcuc}. Non-POSIX@. May be negated.
+(Used for terminals with uppercase characters only.)
@item crt
@opindex crt
@@ -11809,11 +14382,20 @@ End the line.
@item eol2
@opindex eol2
-Alternate character to end the line. Non-@acronym{POSIX}.
+Alternate character to end the line. Non-POSIX.
+
+@item discard
+@opindex discard
+@opindex flush
+Alternate character to toggle discarding of output. Non-POSIX.
@item swtch
@opindex swtch
-Switch to a different shell layer. Non-@acronym{POSIX}.
+Switch to a different shell layer. Non-POSIX.
+
+@item status
+@opindex status
+Send an info signal. Not currently supported on Linux. Non-POSIX.
@item start
@opindex start
@@ -11829,20 +14411,20 @@ Send a terminal stop signal.
@item dsusp
@opindex dsusp
-Send a terminal stop signal after flushing the input. Non-@acronym{POSIX}.
+Send a terminal stop signal after flushing the input. Non-POSIX.
@item rprnt
@opindex rprnt
-Redraw the current line. Non-@acronym{POSIX}.
+Redraw the current line. Non-POSIX.
@item werase
@opindex werase
-Erase the last word typed. Non-@acronym{POSIX}.
+Erase the last word typed. Non-POSIX.
@item lnext
@opindex lnext
Enter the next character typed literally, even if it is a special
-character. Non-@acronym{POSIX}.
+character. Non-POSIX.
@end table
@@ -11872,13 +14454,27 @@ Set the output speed to @var{n}.
@item rows @var{n}
@opindex rows
-Tell the tty kernel driver that the terminal has @var{n} rows. Non-@acronym{POSIX}.
+Tell the tty kernel driver that the terminal has @var{n} rows.
+Non-POSIX.
@item cols @var{n}
@itemx columns @var{n}
@opindex cols
@opindex columns
-Tell the kernel that the terminal has @var{n} columns. Non-@acronym{POSIX}.
+Tell the kernel that the terminal has @var{n} columns. Non-POSIX.
+
+@item drain
+@opindex drain
+@cindex nonblocking @command{stty} setting
+Apply settings after first waiting for pending output to be transmitted.
+This is enabled by default for GNU @command{stty}.
+It is useful to disable this option
+in cases where the system may be in a state where serial transmission
+is not possible.
+For example, if the system has received the @samp{DC3} character
+with @code{ixon} (software flow control) enabled, then @command{stty} would
+block without @code{-drain} being specified.
+May be negated. Non-POSIX.
@item size
@opindex size
@@ -11888,11 +14484,11 @@ Print the number of rows and columns that the kernel thinks the
terminal has. (Systems that don't support rows and columns in the kernel
typically use the environment variables @env{LINES} and @env{COLUMNS}
instead; however, GNU @command{stty} does not know anything about them.)
-Non-@acronym{POSIX}.
+Non-POSIX.
@item line @var{n}
@opindex line
-Use line discipline @var{n}. Non-@acronym{POSIX}.
+Use line discipline @var{n}. Non-POSIX.
@item speed
@opindex speed
@@ -11900,13 +14496,29 @@ Print the terminal speed.
@item @var{n}
@cindex baud rate, setting
-@c FIXME: Is this still true that the baud rate can't be set
-@c higher than 38400?
-Set the input and output speeds to @var{n}. @var{n} can be one
-of: 0 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600
-19200 38400 @code{exta} @code{extb}. @code{exta} is the same as
-19200; @code{extb} is the same as 38400. 0 hangs up the line if
-@option{-clocal} is set.
+Set the input and output speeds to @var{n}. @var{n} can be one of: 0
+50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600 19200
+38400 @code{exta} @code{extb}. @code{exta} is the same as 19200;
+@code{extb} is the same as 38400. Many systems, including GNU/Linux,
+support higher speeds. The @command{stty} command includes support
+for speeds of
+57600,
+115200,
+230400,
+460800,
+500000,
+576000,
+921600,
+1000000,
+1152000,
+1500000,
+2000000,
+2500000,
+3000000,
+3500000,
+or
+4000000 where the system supports these.
+0 hangs up the line if @option{-clocal} is set.
@end table
@@ -11927,8 +14539,13 @@ If no @var{variable}s are specified, @command{printenv} prints the value of
every environment variable. Otherwise, it prints the value of each
@var{variable} that is set, and nothing for those that are not set.
-The only options are a lone @option{--help} or @option{--version}.
-@xref{Common options}.
+The program accepts the following option. Also see @ref{Common options}.
+
+@table @samp
+
+@optNull
+
+@end table
@cindex exit status of @command{printenv}
Exit status:
@@ -12011,12 +14628,20 @@ logins, groups, and so forth.
running it if no user is specified. Synopsis:
@example
-id [@var{option}]@dots{} [@var{username}]
+id [@var{option}]@dots{} [@var{user}]
@end example
+@var{user} can be either a user ID or a name, with name look-up
+taking precedence unless the ID is specified with a leading @samp{+}.
+@xref{Disambiguating names and IDs}.
+
+@vindex POSIXLY_CORRECT
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.
+In addition, if SELinux
+is enabled and the @env{POSIXLY_CORRECT} environment variable is not set,
+then print @samp{context=@var{c}}, where @var{c} is the security context.
Each of these numeric values is preceded by an identifying string and
followed by the corresponding user or group name in parentheses.
@@ -12048,7 +14673,7 @@ Print the user or group name instead of the ID number. Requires
@itemx --real
@opindex -r
@opindex --real
-Print the real, instead of effective, user or group ID. Requires
+Print the real, instead of effective, user or group ID@. Requires
@option{-u}, @option{-g}, or @option{-G}.
@item -u
@@ -12057,10 +14682,43 @@ Print the real, instead of effective, user or group ID. Requires
@opindex --user
Print only the user ID.
+@item -Z
+@itemx --context
+@opindex -Z
+@opindex --context
+@cindex SELinux
+@cindex security context
+Print only the security context of the process, which is generally
+the user's security context inherited from the parent process.
+If neither SELinux or SMACK is enabled then print a warning and
+set the exit status to 1.
+
+@item -z
+@itemx --zero
+@opindex -z
+@opindex --zero
+Delimit output items with NUL characters.
+This option is not permitted when using the default format.
+
+Example:
+@example
+$ id -Gn --zero
+users <NUL> devs <NUL>
+@end example
+
@end table
-@exitstatus
+@macro primaryAndSupplementaryGroups{cmd,arg}
+Primary and supplementary groups for a process are normally inherited
+from its parent and are usually unchanged since login. This means
+that if you change the group database after logging in, @command{\cmd\}
+will not reflect your changes within your existing login session.
+Running @command{\cmd\} with a \arg\ causes the user and group
+database to be consulted afresh, and so will give a different result.
+@end macro
+@primaryAndSupplementaryGroups{id,user argument}
+@exitstatus
@node logname invocation
@section @command{logname}: Print current login name
@@ -12091,7 +14749,7 @@ options}.
@cindex printing the effective user ID
@command{whoami} prints the user name associated with the current
-effective user ID. It is equivalent to the command @samp{id -un}.
+effective user ID@. It is equivalent to the command @samp{id -un}.
The only options are @option{--help} and @option{--version}. @xref{Common
options}.
@@ -12110,7 +14768,8 @@ options}.
groups for each given @var{username}, or the current process if no names
are given. If more than one name is given, the name of each user is
printed before
-the list of that user's groups. Synopsis:
+the list of that user's groups and the user name is separated from the
+group list by a colon. Synopsis:
@example
groups [@var{username}]@dots{}
@@ -12121,8 +14780,9 @@ The group lists are equivalent to the output of the command @samp{id -Gn}.
The only options are @option{--help} and @option{--version}. @xref{Common
options}.
-@exitstatus
+@primaryAndSupplementaryGroups{groups,list of users}
+@exitstatus
@node users invocation
@section @command{users}: Print login names of users currently logged in
@@ -12152,6 +14812,10 @@ that file instead. A common choice is @file{/var/log/wtmp}.
The only options are @option{--help} and @option{--version}. @xref{Common
options}.
+The @command{users} command is installed only on platforms with the
+POSIX @code{<utmpx.h>} include file or equivalent, so portable scripts
+should not rely on its existence on non-POSIX platforms.
+
@exitstatus
@@ -12195,7 +14859,7 @@ i}, as in @samp{who am i}.
Time stamps are listed according to the time zone rules specified by
the @env{TZ} environment variable, or by the system default rules if
@env{TZ} is not set. @xref{TZ Variable,, Specifying the Time Zone
-with @env{TZ}, libc, The GNU C Library}.
+with @env{TZ}, libc, The GNU C Library Reference Manual}.
The program accepts the following options. Also see @ref{Common options}.
@@ -12223,12 +14887,31 @@ Print information corresponding to dead processes.
@itemx --heading
@opindex -H
@opindex --heading
-Print column headings.
+Print a line of column headings.
+
+@item -l
+@itemx --login
+@opindex -l
+@opindex --login
+List only the entries that correspond to processes via which the
+system is waiting for a user to login. The user name is always @samp{LOGIN}.
+
+@item --lookup
+@opindex --lookup
+Attempt to canonicalize hostnames found in utmp through a DNS lookup. This
+is not the default because it can cause significant delays on systems with
+automatic dial-up internet access.
@item -m
@opindex -m
Same as @samp{who am i}.
+@item -p
+@itemx --process
+@opindex -p
+@opindex --process
+List active processes spawned by init.
+
@item -q
@itemx --count
@opindex -q
@@ -12236,36 +14919,29 @@ Same as @samp{who am i}.
Print only the login names and the number of users logged on.
Overrides all other options.
+@item -r
+@itemx --runlevel
+@opindex -r
+@opindex --runlevel
+Print the current (and maybe previous) run-level of the init process.
+
@item -s
@opindex -s
Ignored; for compatibility with other versions of @command{who}.
-@itemx -u
+@item -t
+@itemx --time
+@opindex -t
+@opindex --time
+Print last system clock change.
+
+@item -u
@opindex -u
@cindex idle time
After the login time, print the number of hours and minutes that the
user has been idle. @samp{.} means the user was active in the last minute.
@samp{old} means the user has been idle for more than 24 hours.
-@item -l
-@itemx --login
-@opindex -l
-@opindex --login
-List only the entries that correspond to processes via which the
-system is waiting for a user to login. The user name is always @samp{LOGIN}.
-
-@itemx --lookup
-@opindex --lookup
-Attempt to canonicalize hostnames found in utmp through a DNS lookup. This
-is not the default because it can cause significant delays on systems with
-automatic dial-up internet access.
-
-@item -H
-@itemx --heading
-@opindex -H
-@opindex --heading
-Print a line of column headings.
-
@item -w
@itemx -T
@itemx --mesg
@@ -12288,6 +14964,10 @@ After each login name print a character indicating the user's message status:
@end table
+The @command{who} command is installed only on platforms with the
+POSIX @code{<utmpx.h>} include file or equivalent, so portable scripts
+should not rely on its existence on non-POSIX platforms.
+
@exitstatus
@@ -12303,12 +14983,14 @@ information.
@menu
* date invocation:: Print or set system date and time.
+* arch invocation:: Print machine hardware name.
+* nproc invocation:: Print the number of processors.
* uname invocation:: Print system information.
* hostname invocation:: Print or set system name.
* hostid invocation:: Print numeric host identifier.
+* uptime invocation:: Print system uptime and load.
@end menu
-
@node date invocation
@section @command{date}: Print or set system date and time
@@ -12334,7 +15016,7 @@ so the output looks like @samp{Thu Mar @ 3 13:47:51 PST 2005}.
Normally, @command{date} uses the time zone rules indicated by the
@env{TZ} environment variable, or the system default rules if @env{TZ}
is not set. @xref{TZ Variable,, Specifying the Time Zone with
-@env{TZ}, libc, The GNU C Library}.
+@env{TZ}, libc, The GNU C Library Reference Manual}.
@findex strftime @r{and @command{date}}
@cindex time formats
@@ -12356,6 +15038,9 @@ described below.
* Padding and other flags:: Pad with zeros, spaces, etc.
* Setting the time:: Changing the system clock.
* Options for date:: Instead of the current time.
+@detailmenu
+* Date input formats:: Specifying date strings.
+@end detailmenu
* Examples of date:: Examples.
@end menu
@@ -12373,37 +15058,38 @@ hour (@samp{00}@dots{}@samp{23})
@item %I
hour (@samp{01}@dots{}@samp{12})
@item %k
-hour (@samp{ 0}@dots{}@samp{23}).
-This is a @acronym{GNU} extension.
+hour, space padded (@samp{ 0}@dots{}@samp{23}); equivalent to @samp{%_H}@.
+This is a GNU extension.
@item %l
-hour (@samp{ 1}@dots{}@samp{12}).
-This is a @acronym{GNU} extension.
+hour, space padded (@samp{ 1}@dots{}@samp{12}); equivalent to @samp{%_I}@.
+This is a GNU extension.
@item %M
minute (@samp{00}@dots{}@samp{59})
@item %N
nanoseconds (@samp{000000000}@dots{}@samp{999999999}).
-This is a @acronym{GNU} extension.
+This is a GNU extension.
@item %p
locale's equivalent of either @samp{AM} or @samp{PM};
blank in many locales.
Noon is treated as @samp{PM} and midnight as @samp{AM}.
@item %P
like @samp{%p}, except lower case.
-This is a @acronym{GNU} extension.
+This is a GNU extension.
@item %r
locale's 12-hour clock time (e.g., @samp{11:11:04 PM})
@item %R
24-hour hour and minute. Same as @samp{%H:%M}.
-This is a @acronym{GNU} extension.
@item %s
@cindex epoch, seconds since
@cindex seconds since the epoch
@cindex beginning of time
-seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC.
+@cindex leap seconds
+seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC@.
Leap seconds are not counted unless leap second support is available.
@xref{%s-examples}, for examples.
-This is a @acronym{GNU} extension.
+This is a GNU extension.
@item %S
+@cindex leap seconds
second (@samp{00}@dots{}@samp{60}).
This may be @samp{60} if leap seconds are supported.
@item %T
@@ -12411,29 +15097,28 @@ This may be @samp{60} if leap seconds are supported.
@item %X
locale's time representation (e.g., @samp{23:13:48})
@item %z
-@w{@acronym{RFC} 2822/@acronym{ISO} 8601} style numeric time zone
+@w{RFC 2822/ISO 8601} style numeric time zone
(e.g., @samp{-0600} or @samp{+0530}), or nothing if no
time zone is determinable. This value reflects the numeric time zone
appropriate for the current time, using the time zone rules specified
by the @env{TZ} environment variable.
The time (and optionally, the time zone rules) can be overridden
by the @option{--date} option.
-This is a @acronym{GNU} extension.
@item %:z
-@w{@acronym{RFC} 3339/@acronym{ISO} 8601} style numeric time zone with
+@w{RFC 3339/ISO 8601} style numeric time zone with
@samp{:} (e.g., @samp{-06:00} or @samp{+05:30}), or nothing if no time
zone is determinable.
-This is a @acronym{GNU} extension.
+This is a GNU extension.
@item %::z
Numeric time zone to the nearest second with @samp{:} (e.g.,
@samp{-06:00:00} or @samp{+05:30:00}), or nothing if no time zone is
determinable.
-This is a @acronym{GNU} extension.
+This is a GNU extension.
@item %:::z
Numeric time zone with @samp{:} using the minimum necessary precision
(e.g., @samp{-06}, @samp{+05:30}, or @samp{-04:56:02}), or nothing if
no time zone is determinable.
-This is a @acronym{GNU} extension.
+This is a GNU extension.
@item %Z
alphabetic time zone abbreviation (e.g., @samp{EDT}), or nothing if no
time zone is determinable. See @samp{%z} for how it is determined.
@@ -12471,28 +15156,25 @@ date; same as @samp{%m/%d/%y}
@item %e
day of month, space padded; same as @samp{%_d}
@item %F
-full date in @acronym{ISO} 8601 format; same as @samp{%Y-%m-%d}.
+full date in ISO 8601 format; same as @samp{%Y-%m-%d}.
This is a good choice for a date format, as it is standard and
is easy to sort in the usual case where years are in the range
0000@dots{}9999.
-This is a @acronym{GNU} extension.
@item %g
-year corresponding to the @acronym{ISO} week number, but without the century
+year corresponding to the ISO week number, but without the century
(range @samp{00} through @samp{99}). This has the same format and value
-as @samp{%y}, except that if the @acronym{ISO} week number (see
+as @samp{%y}, except that if the ISO week number (see
@samp{%V}) belongs
to the previous or next year, that year is used instead.
-This is a @acronym{GNU} extension.
@item %G
-year corresponding to the @acronym{ISO} week number. This has the
-same format and value as @samp{%Y}, except that if the @acronym{ISO}
+year corresponding to the ISO week number. This has the
+same format and value as @samp{%Y}, except that if the ISO
week number (see
@samp{%V}) belongs to the previous or next year, that year is used
instead.
It is normally useful only if @samp{%V} is also used;
for example, the format @samp{%G-%m-%d} is probably a mistake,
since it combines the ISO week number year with the conventional month and day.
-This is a @acronym{GNU} extension.
@item %h
same as @samp{%b}
@item %j
@@ -12506,12 +15188,12 @@ week number of year, with Sunday as the first day of the week
(@samp{00}@dots{}@samp{53}).
Days in a new year preceding the first Sunday are in week zero.
@item %V
-@acronym{ISO} week number, that is, the
+ISO week number, that is, the
week number of year, with Monday as the first day of the week
(@samp{01}@dots{}@samp{53}).
If the week containing January 1 has four or more days in
the new year, then it is considered week 1; otherwise, it is week 53 of
-the previous year, and the next week is week 1. (See the @acronym{ISO} 8601
+the previous year, and the next week is week 1. (See the ISO 8601
standard.)
@item %w
day of week (@samp{0}@dots{}@samp{6}) with 0 corresponding to Sunday
@@ -12561,7 +15243,7 @@ example, numeric months are always output as two digits.
Seconds since the epoch are not padded, though,
since there is no natural width for them.
-As a @acronym{GNU} extension, @command{date} recognizes any of the
+As a GNU extension, @command{date} recognizes any of the
following optional flags after the @samp{%}:
@table @samp
@@ -12593,9 +15275,9 @@ date +%_d/%_m -d "Feb 1"
@result{} 1/ 2
@end example
-As a @acronym{GNU} extension, you can specify the field width
+As a GNU extension, you can specify the field width
(after any flag, if present) as a decimal number. If the natural size of the
-output is of the field has less than the specified number of characters,
+output of the field has less than the specified number of characters,
the result is written right adjusted and padded to the given
size. For example, @samp{%9B} prints the right adjusted month name in
a field of width 9.
@@ -12630,11 +15312,9 @@ is available, it is ignored.
If given an argument that does not start with @samp{+}, @command{date} sets
the system clock to the date and time specified by that argument (as
described below). You must have appropriate privileges to set the
-system clock. The @option{--date} and @option{--set} options may not be
-used with such an argument. The @option{--universal} option may be used
-with such an argument to indicate that the specified date and time are
-relative to Coordinated Universal Time rather than to the local time
-zone.
+system clock. Note for changes to persist across a reboot, the
+hardware clock may need to be updated from the system clock, which
+might not happen automatically on your system.
The argument must consist entirely of digits, which have the following
meaning:
@@ -12656,7 +15336,10 @@ last two digits of year (optional)
second (optional)
@end table
-The @option{--set} option also sets the system clock; see the next section.
+Note, the @option{--date} and @option{--set} options may not be used with an
+argument in the above format. The @option{--universal} option may be used
+with such an argument to indicate that the specified date and time are
+relative to Coordinated Universal Time rather than to the local time zone.
@node Options for date
@@ -12686,7 +15369,12 @@ format. It can contain month names, time zones, @samp{am} and @samp{pm},
@samp{yesterday}, etc. For example, @option{--date="2004-02-27
14:19:13.489392193 +0530"} specifies the instant of time that is
489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a
-time zone that is 5 hours and 30 minutes east of @acronym{UTC}.
+time zone that is 5 hours and 30 minutes east of UTC.@*
+Note: input currently must be in locale independent format. E.g., the
+LC_TIME=C below is needed to print back the correct date in many locales:
+@example
+date -d "$(LC_TIME=C date)"
+@end example
@xref{Date input formats}.
@item -f @var{datefile}
@@ -12699,6 +15387,40 @@ input. This is useful when you have many dates to process, because the
system overhead of starting up the @command{date} executable many times can
be considerable.
+@item -I[@var{timespec}]
+@itemx --iso-8601[=@var{timespec}]
+@opindex -I[@var{timespec}]
+@opindex --iso-8601[=@var{timespec}]
+Display the date using the ISO 8601 format, @samp{%Y-%m-%d}.
+
+The argument @var{timespec} specifies the number of additional
+terms of the time to include. It can be one of the following:
+@table @samp
+@item auto
+Print just the date. This is the default if @var{timespec} is omitted.
+
+@item hours
+Append the hour of the day to the date.
+
+@item minutes
+Append the hours and minutes.
+
+@item seconds
+Append the hours, minutes and seconds.
+
+@item ns
+Append the hours, minutes, seconds and nanoseconds.
+@end table
+
+If showing any time terms, then include the time zone using the format
+@samp{%:z}.
+@macro dateParseNote
+This format is always suitable as input
+for the @option{--date} (@option{-d}) and @option{--file}
+(@option{-f}) options, regardless of the current locale.
+@end macro
+@dateParseNote
+
@item -r @var{file}
@itemx --reference=@var{file}
@opindex -r
@@ -12722,7 +15444,7 @@ Fri, 09 Sep 2005 13:51:39 -0700
This format conforms to
@uref{ftp://ftp.rfc-editor.org/in-notes/rfc2822.txt, Internet
-@acronym{RFCs} 2822} and
+RFCs 2822} and
@uref{ftp://ftp.rfc-editor.org/in-notes/rfc822.txt, 822}, the
current and previous standards for Internet email.
@@ -12730,12 +15452,10 @@ current and previous standards for Internet email.
@opindex --rfc-3339=@var{timespec}
Display the date using a format specified by
@uref{ftp://ftp.rfc-editor.org/in-notes/rfc3339.txt, Internet
-@acronym{RFC} 3339}. This is a subset of the @acronym{ISO} 8601
+RFC 3339}. This is a subset of the ISO 8601
format, except that it also permits applications to use a space rather
-than a @samp{T} to separate dates from times. Unlike the other
-standard formats, @acronym{RFC} 3339 format is always suitable as
-input for the @option{--date} (@option{-d}) and @option{--file}
-(@option{-f}) options, regardless of the current locale.
+than a @samp{T} to separate dates from times.
+@dateParseNote
The argument @var{timespec} specifies how much of the time to include.
It can be one of the following:
@@ -12749,7 +15469,7 @@ This is equivalent to the format @samp{%Y-%m-%d}.
Print the full-date and full-time separated by a space, e.g.,
@samp{2005-09-14 00:56:06+05:30}. The output ends with a numeric
time-offset; here the @samp{+05:30} means that local time is five
-hours and thirty minutes east of @acronym{UTC}. This is equivalent to
+hours and thirty minutes east of UTC@. This is equivalent to
the format @samp{%Y-%m-%d %H:%M:%S%:z}.
@item ns
@@ -12764,6 +15484,7 @@ This is equivalent to the format @samp{%Y-%m-%d %H:%M:%S.%N%:z}.
@opindex -s
@opindex --set
Set the date and time to @var{datestr}. See @option{-d} above.
+See also @ref{Setting the time}.
@item -u
@itemx --utc
@@ -12775,12 +15496,15 @@ Set the date and time to @var{datestr}. See @option{-d} above.
@cindex UTC
@cindex Greenwich Mean Time
@cindex GMT
+@cindex leap seconds
@vindex TZ
-Use Coordinated Universal Time (@acronym{UTC}) by operating as if the
+Use Coordinated Universal Time (UTC) by operating as if the
@env{TZ} environment variable were set to the string @samp{UTC0}.
Coordinated
-Universal Time is often called ``Greenwich Mean Time'' (@sc{gmt}) for
+Universal Time is often called ``Greenwich Mean Time'' (GMT) for
historical reasons.
+Typically, systems ignore leap seconds and thus implement an
+approximation to UTC rather than true UTC.
@end table
@@ -12828,7 +15552,7 @@ for example @samp{date -d 1may '+%B %d'} will print @samp{May 01}.
@item
To print a date without the leading zero for one-digit days
-of the month, you can use the (@acronym{GNU} extension)
+of the month, you can use the (GNU extension)
@samp{-} flag to suppress
the padding altogether:
@@ -12838,7 +15562,7 @@ date -d 1may '+%B %-d
@item
To print the current date and time in the format required by many
-non-@acronym{GNU} versions of @command{date} when setting the system clock:
+non-GNU versions of @command{date} when setting the system clock:
@example
date +%m%d%H%M%Y.%S
@@ -12852,7 +15576,7 @@ date --set='+2 minutes'
@end example
@item
-To print the date in @acronym{RFC} 2822 format,
+To print the date in RFC 2822 format,
use @samp{date --rfc-2822}. Here is some example output:
@example
@@ -12931,9 +15655,99 @@ date -u -d '1970-01-01 946684800 seconds' +"%Y-%m-%d %T %z"
2000-01-01 00:00:00 +0000
@end smallexample
+@item
+@cindex leap seconds
+Typically the seconds count omits leap seconds, but some systems are
+exceptions. Because leap seconds are not predictable, the mapping
+between the seconds count and a future timestamp is not reliable on
+the atypical systems that include leap seconds in their counts.
+
+Here is how the two kinds of systems handle the leap second at
+2012-06-30 23:59:60 UTC:
+
+@example
+# Typical systems ignore leap seconds:
+date --date='2012-06-30 23:59:59 +0000' +%s
+1341100799
+date --date='2012-06-30 23:59:60 +0000' +%s
+date: invalid date '2012-06-30 23:59:60 +0000'
+date --date='2012-07-01 00:00:00 +0000' +%s
+1341100800
+@end example
+
+@example
+# Atypical systems count leap seconds:
+date --date='2012-06-30 23:59:59 +0000' +%s
+1341100823
+date --date='2012-06-30 23:59:60 +0000' +%s
+1341100824
+date --date='2012-07-01 00:00:00 +0000' +%s
+1341100825
+@end example
+
@end itemize
+@node arch invocation
+@section @command{arch}: Print machine hardware name
+
+@pindex arch
+@cindex print machine hardware name
+@cindex system information, printing
+
+@command{arch} prints the machine hardware name,
+and is equivalent to @samp{uname -m}.
+Synopsis:
+
+@example
+arch [@var{option}]
+@end example
+
+The program accepts the @ref{Common options} only.
+
+@command{arch} is not installed by default, so portable scripts should
+not rely on its existence.
+
+@exitstatus
+
+
+@node nproc invocation
+@section @command{nproc}: Print the number of available processors
+
+@pindex nproc
+@cindex Print the number of processors
+@cindex system information, printing
+
+Print the number of processing units available to the current process,
+which may be less than the number of online processors.
+If this information is not accessible, then print the number of
+processors installed. If the @env{OMP_NUM_THREADS} environment variable is
+set, then it will determine the returned value. The result is guaranteed to be
+greater than zero. Synopsis:
+
+@example
+nproc [@var{option}]
+@end example
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+
+@item --all
+@opindex --all
+Print the number of installed processors on the system, which may
+be greater than the number online or available to the current process.
+The @env{OMP_NUM_THREADS} environment variable is not honored in this case.
+
+@item --ignore=@var{number}
+@opindex --ignore
+If possible, exclude this @var{number} of processing units.
+
+@end table
+
+@exitstatus
+
+
@node uname invocation
@section @command{uname}: Print system information
@@ -12963,7 +15777,8 @@ parsed reliably. In the following example, @var{release} is
@smallexample
uname -a
-@result{} Linux dum 2.2.18 #4 SMP Tue Jun 5 11:24:08 PDT 2001 i686 unknown unknown GNU/Linux
+@result{} Linux dumdum 2.2.18 #4 SMP Tue Jun 5 11:24:08 PDT 2001 i686@c
+ unknown unknown GNU/Linux
@end smallexample
@@ -12987,8 +15802,8 @@ and the hardware platform name if they are unknown.
@cindex platform, hardware
Print the hardware platform name
(sometimes called the hardware implementation).
-Print @samp{unknown} if the kernel does not make this information
-easily available, as is the case with Linux kernels.
+Print @samp{unknown} if this information is not available.
+Note this is non-portable (even across GNU/Linux distributions).
@item -m
@itemx --machine
@@ -13016,8 +15831,8 @@ Print the network node hostname.
@cindex host processor type
Print the processor type (sometimes called the instruction set
architecture or ISA).
-Print @samp{unknown} if the kernel does not make this information
-easily available, as is the case with Linux kernels.
+Print @samp{unknown} if this information is not available.
+Note this is non-portable (even across GNU/Linux distributions).
@item -o
@itemx --operating-system
@@ -13041,9 +15856,9 @@ Print the kernel release.
@cindex kernel name
@cindex name of kernel
Print the kernel name.
-@acronym{POSIX} 1003.1-2001 (@pxref{Standards conformance}) calls this
+POSIX 1003.1-2001 (@pxref{Standards conformance}) calls this
``the implementation of the operating system'', because the
-@acronym{POSIX} specification itself has no notion of ``kernel''.
+POSIX specification itself has no notion of ``kernel''.
The kernel name might be the same as the operating system name printed
by the @option{-o} or @option{--operating-system} option, but it might
differ. Some operating systems (e.g., FreeBSD, HP-UX) have the same
@@ -13084,11 +15899,15 @@ hostname [@var{name}]
The only options are @option{--help} and @option{--version}. @xref{Common
options}.
+@command{hostname} is not installed by default, and other packages
+also supply a @command{hostname} command, so portable scripts should
+not rely on its existence or on the exact behavior documented above.
+
@exitstatus
@node hostid invocation
-@section @command{hostid}: Print numeric host identifier.
+@section @command{hostid}: Print numeric host identifier
@pindex hostid
@cindex printing the host identifier
@@ -13109,8 +15928,240 @@ On that system, the 32-bit quantity happens to be closely
related to the system's Internet address, but that isn't always
the case.
+@command{hostid} is installed only on systems that have the
+@code{gethostid} function, so portable scripts should not rely on its
+existence.
+
+@exitstatus
+
+@node uptime invocation
+@section @command{uptime}: Print system uptime and load
+
+@pindex uptime
+@cindex printing the system uptime and load
+
+@command{uptime} prints the current time, the system's uptime, the
+number of logged-in users and the current load average.
+
+If an argument is specified, it is used as the file to be read
+to discover how many users are logged in. If no argument is
+specified, a system default is used (@command{uptime --help} indicates
+the default setting).
+
+The only options are @option{--help} and @option{--version}.
+@xref{Common options}.
+
+For example, here's what it prints right now on one system I use:
+
+@example
+$ uptime
+ 14:07 up 3:35, 3 users, load average: 1.39, 1.15, 1.04
+@end example
+
+The precise method of calculation of load average varies somewhat
+between systems. Some systems calculate it as the average number of
+runnable processes over the last 1, 5 and 15 minutes, but some systems
+also include processes in the uninterruptible sleep state (that is,
+those processes which are waiting for disk I/O). The Linux kernel
+includes uninterruptible processes.
+
+@command{uptime} is installed only on platforms with infrastructure
+for obtaining the boot time, and other packages also supply an
+@command{uptime} command, so portable scripts should not rely on its
+existence or on the exact behavior documented above.
+
+@exitstatus
+
+@node SELinux context
+@chapter SELinux context
+
+@cindex SELinux context
+@cindex SELinux, context
+@cindex commands for SELinux context
+
+This section describes commands for operations with SELinux
+contexts.
+
+@menu
+* chcon invocation:: Change SELinux context of file
+* runcon invocation:: Run a command in specified SELinux context
+@end menu
+
+@node chcon invocation
+@section @command{chcon}: Change SELinux context of file
+
+@pindex chcon
+@cindex changing security context
+@cindex change SELinux context
+
+@command{chcon} changes the SELinux security context of the selected files.
+Synopses:
+
+@smallexample
+chcon [@var{option}]@dots{} @var{context} @var{file}@dots{}
+chcon [@var{option}]@dots{} [-u @var{user}] [-r @var{role}] [-l @var{range}]@c
+ [-t @var{type}] @var{file}@dots{}
+chcon [@var{option}]@dots{} --reference=@var{rfile} @var{file}@dots{}
+@end smallexample
+
+Change the SELinux security context of each @var{file} to @var{context}.
+With @option{--reference}, change the security context of each @var{file}
+to that of @var{rfile}.
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+
+@item --dereference
+@opindex --dereference
+Do not affect symbolic links but what they refer to; this is the default.
+
+@item -h
+@itemx --no-dereference
+@opindex -h
+@opindex --no-dereference
+@cindex no dereference
+Affect the symbolic links themselves instead of any referenced file.
+
+@item --reference=@var{rfile}
+@opindex --reference
+@cindex reference file
+Use @var{rfile}'s security context rather than specifying a @var{context} value.
+
+@item -R
+@itemx --recursive
+@opindex -R
+@opindex --recursive
+Operate on files and directories recursively.
+
+@item --preserve-root
+@opindex --preserve-root
+Refuse to operate recursively on the root directory, @file{/},
+when used together with the @option{--recursive} option.
+@xref{Treating / specially}.
+
+@item --no-preserve-root
+@opindex --no-preserve-root
+Do not treat the root directory, @file{/}, specially when operating
+recursively; this is the default.
+@xref{Treating / specially}.
+
+@choptH
+@xref{Traversing symlinks}.
+
+@choptL
+@xref{Traversing symlinks}.
+
+@choptP
+@xref{Traversing symlinks}.
+
+@item -v
+@itemx --verbose
+@opindex -v
+@opindex --verbose
+@cindex diagnostic
+Output a diagnostic for every file processed.
+
+@item -u @var{user}
+@itemx --user=@var{user}
+@opindex -u
+@opindex --user
+Set user @var{user} in the target security context.
+
+@item -r @var{role}
+@itemx --role=@var{role}
+@opindex -r
+@opindex --role
+Set role @var{role} in the target security context.
+
+@item -t @var{type}
+@itemx --type=@var{type}
+@opindex -t
+@opindex --type
+Set type @var{type} in the target security context.
+
+@item -l @var{range}
+@itemx --range=@var{range}
+@opindex -l
+@opindex --range
+Set range @var{range} in the target security context.
+
+@end table
+
@exitstatus
+@node runcon invocation
+@section @command{runcon}: Run a command in specified SELinux context
+
+@pindex runcon
+@cindex run with security context
+
+
+@command{runcon} runs file in specified SELinux security context.
+
+Synopses:
+@smallexample
+runcon @var{context} @var{command} [@var{args}]
+runcon [ -c ] [-u @var{user}] [-r @var{role}] [-t @var{type}]@c
+ [-l @var{range}] @var{command} [@var{args}]
+@end smallexample
+
+Run @var{command} with completely-specified @var{context}, or with
+current or transitioned security context modified by one or more of @var{level},
+@var{role}, @var{type} and @var{user}.
+
+If none of @option{-c}, @option{-t}, @option{-u}, @option{-r}, or @option{-l}
+is specified, the first argument is used as the complete context.
+Any additional arguments after @var{command}
+are interpreted as arguments to the command.
+
+With neither @var{context} nor @var{command}, print the current
+security context.
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+
+@item -c
+@itemx --compute
+@opindex -c
+@opindex --compute
+Compute process transition context before modifying.
+
+@item -u @var{user}
+@itemx --user=@var{user}
+@opindex -u
+@opindex --user
+Set user @var{user} in the target security context.
+
+@item -r @var{role}
+@itemx --role=@var{role}
+@opindex -r
+@opindex --role
+Set role @var{role} in the target security context.
+
+@item -t @var{type}
+@itemx --type=@var{type}
+@opindex -t
+@opindex --type
+Set type @var{type} in the target security context.
+
+@item -l @var{range}
+@itemx --range=@var{range}
+@opindex -l
+@opindex --range
+Set range @var{range} in the target security context.
+
+@end table
+
+@cindex exit status of @command{runcon}
+Exit status:
+
+@display
+126 if @var{command} is found but cannot be invoked
+127 if @command{runcon} itself fails or if @var{command} cannot be found
+the exit status of @var{command} otherwise
+@end display
@node Modified command invocation
@chapter Modified command invocation
@@ -13128,7 +16179,8 @@ user, etc.
* env invocation:: Modify environment variables.
* nice invocation:: Modify niceness.
* nohup invocation:: Immunize to hangups.
-* su invocation:: Modify user and group ID.
+* stdbuf invocation:: Modify buffering of standard streams.
+* timeout invocation:: Run with time limit.
@end menu
@@ -13140,25 +16192,70 @@ user, etc.
@cindex root directory, running a program in a specified
@command{chroot} runs a command with a specified root directory.
-On many systems, only the super-user can do this.
+On many systems, only the super-user can do this.@footnote{However,
+some systems (e.g., FreeBSD) can be configured to allow certain regular
+users to use the @code{chroot} system call, and hence to run this program.
+Also, on Cygwin, anyone can run the @command{chroot} command, because the
+underlying function is non-privileged due to lack of support in MS-Windows.
+Furthermore, the @command{chroot} command avoids the @code{chroot} system call
+when @var{newroot} is identical to the old @file{/} directory for consistency
+with systems where this is allowed for non-privileged users.}.
Synopses:
@example
-chroot @var{newroot} [@var{command} [@var{args}]@dots{}]
+chroot @var{option} @var{newroot} [@var{command} [@var{args}]@dots{}]
chroot @var{option}
@end example
Ordinarily, file names are looked up starting at the root of the
directory structure, i.e., @file{/}. @command{chroot} changes the root to
-the directory @var{newroot} (which must exist) and then runs
-@var{command} with optional @var{args}. If @var{command} is not
-specified, the default is the value of the @env{SHELL} environment
-variable or @command{/bin/sh} if not set, invoked with the @option{-i} option.
+the directory @var{newroot} (which must exist), then changes the working
+directory to @file{/}, and finally runs @var{command} with optional @var{args}.
+If @var{command} is not specified, the default is the value of the @env{SHELL}
+environment variable or @command{/bin/sh} if not set, invoked with the
+@option{-i} option.
@var{command} must not be a special built-in utility
(@pxref{Special built-in utilities}).
-The only options are @option{--help} and @option{--version}. @xref{Common
-options}. Options must precede operands.
+The program accepts the following options. Also see @ref{Common options}.
+Options must precede operands.
+
+@table @samp
+
+@item --groups=@var{groups}
+@opindex --groups
+Use this option to override the supplementary @var{groups} to be
+used by the new process.
+The items in the list (names or numeric IDs) must be separated by commas.
+Use @samp{--groups=''} to disable the supplementary group look-up
+implicit in the @option{--userspec} option.
+
+@item --userspec=@var{user}[:@var{group}]
+@opindex --userspec
+By default, @var{command} is run with the same credentials
+as the invoking process.
+Use this option to run it as a different @var{user} and/or with a
+different primary @var{group}.
+If a @var{user} is specified then the supplementary groups
+are set according to the system defined list for that user,
+unless overridden with the @option{--groups} option.
+
+@item --skip-chdir
+@opindex --skip-chdir
+Use this option to not change the working directory to @file{/} after changing
+the root directory to @var{newroot}, i.e., inside the chroot.
+This option is only permitted when @var{newroot} is the old @file{/} directory,
+and therefore is mostly useful together with the @option{--groups} and
+@option{--userspec} options to retain the previous working directory.
+
+@end table
+
+The user and group name look-up performed by the @option{--userspec}
+and @option{--groups} options, is done both outside and inside
+the chroot, with successful look-ups inside the chroot taking precedence.
+If the specified user or group items are intended to represent a numeric ID,
+then a name to ID resolving step is avoided by specifying a leading @samp{+}.
+@xref{Disambiguating names and IDs}.
Here are a few tips to help avoid common problems in using chroot.
To start with a simple example, make @var{command} refer to a statically
@@ -13188,11 +16285,15 @@ files to the required positions under your intended new root directory.
Finally, if the executable requires any other files (e.g., data, state,
device files), copy them into place, too.
+@command{chroot} is installed only on systems that have the
+@code{chroot} function, so portable scripts should not rely on its
+existence.
+
@cindex exit status of @command{chroot}
Exit status:
@display
-1 if @command{chroot} itself fails
+125 if @command{chroot} itself fails
126 if @var{command} is found but cannot be invoked
127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@@ -13223,9 +16324,9 @@ These operands are evaluated left-to-right, so if two operands
mention the same variable the earlier is ignored.
Environment variable names can be empty, and can contain any
-characters other than @samp{=} and the null character (@acronym{ASCII}
-@sc{nul}). However, it is wise to limit yourself to names that
-consist solely of underscores, digits, and @acronym{ASCII} letters,
+characters other than @samp{=} and ASCII NUL.
+However, it is wise to limit yourself to names that
+consist solely of underscores, digits, and ASCII letters,
and that begin with a non-digit, as applications like the shell do not
work well with other names.
@@ -13237,17 +16338,89 @@ remaining arguments are passed as arguments to that program.
The program should not be a special built-in utility
(@pxref{Special built-in utilities}).
+Modifications to @env{PATH} take effect prior to searching for
+@var{command}. Use caution when reducing @env{PATH}; behavior is
+not portable when @env{PATH} is undefined or omits key directories
+such as @file{/bin}.
+
+In the rare case that a utility contains a @samp{=} in the name, the
+only way to disambiguate it from a variable assignment is to use an
+intermediate command for @var{command}, and pass the problematic
+program name via @var{args}. For example, if @file{./prog=} is an
+executable in the current @env{PATH}:
+
+@example
+env prog= true # runs 'true', with prog= in environment
+env ./prog= true # runs 'true', with ./prog= in environment
+env -- prog= true # runs 'true', with prog= in environment
+env sh -c '\prog= true' # runs 'prog=' with argument 'true'
+env sh -c 'exec "$@@"' sh prog= true # also runs 'prog='
+@end example
+
@cindex environment, printing
If no command name is specified following the environment
specifications, the resulting environment is printed. This is like
specifying the @command{printenv} program.
+For some examples, suppose the environment passed to @command{env}
+contains @samp{LOGNAME=rms}, @samp{EDITOR=emacs}, and
+@samp{PATH=.:/gnubin:/hacks}:
+
+@itemize @bullet
+
+@item
+Output the current environment.
+@example
+$ env | LC_ALL=C sort
+EDITOR=emacs
+LOGNAME=rms
+PATH=.:/gnubin:/hacks
+@end example
+
+@item
+Run @command{foo} with a reduced environment, preserving only the
+original @env{PATH} to avoid problems in locating @command{foo}.
+@example
+env - PATH="$PATH" foo
+@end example
+
+@item
+Run @command{foo} with the environment containing @samp{LOGNAME=rms},
+@samp{EDITOR=emacs}, and @samp{PATH=.:/gnubin:/hacks}, and guarantees
+that @command{foo} was found in the file system rather than as a shell
+built-in.
+@example
+env foo
+@end example
+
+@item
+Run @command{nemacs} with the environment containing @samp{LOGNAME=foo},
+@samp{EDITOR=emacs}, @samp{PATH=.:/gnubin:/hacks}, and
+@samp{DISPLAY=gnu:0}.
+@example
+env DISPLAY=gnu:0 LOGNAME=foo nemacs
+@end example
+
+@item
+Attempt to run the program @command{/energy/--} (as that is the only
+possible path search result); if the command exists, the environment
+will contain @samp{LOGNAME=rms} and @samp{PATH=/energy}, and the
+arguments will be @samp{e=mc2}, @samp{bar}, and @samp{baz}.
+@example
+env -u EDITOR PATH=/energy -- e=mc2 bar baz
+@end example
+
+@end itemize
+
+
The program accepts the following options. Also see @ref{Common options}.
Options must precede operands.
@table @samp
+@optNull
+
@item -u @var{name}
@itemx --unset=@var{name}
@opindex -u
@@ -13270,7 +16443,7 @@ Exit status:
@display
0 if no @var{command} is specified and the environment is output
-1 if @command{env} itself fails
+125 if @command{env} itself fails
126 if @var{command} is found but cannot be invoked
127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@@ -13285,8 +16458,9 @@ the exit status of @var{command} otherwise
@cindex scheduling, affecting
@cindex appropriate privileges
-@command{nice} prints or modifies a process's @dfn{niceness},
-a parameter that affects whether the process is scheduled favorably.
+@command{nice} prints a process's @dfn{niceness}, or runs
+a command with modified niceness. @dfn{niceness} affects how
+favorably the process is scheduled in the system.
Synopsis:
@example
@@ -13297,9 +16471,11 @@ If no arguments are given, @command{nice} prints the current niceness.
Otherwise, @command{nice} runs the given @var{command} with its
niceness adjusted. By default, its niceness is incremented by 10.
-Nicenesses range at least from @minus{}20 (resulting in the most
-favorable scheduling) through 19 (the least favorable). Some systems
-may have a wider range of nicenesses; conversely, other systems may
+Niceness values range at least from @minus{}20 (process has high priority
+and gets more resources, thus slowing down other processes) through 19
+(process has lower priority and runs slowly itself, but has less impact
+on the speed of other running processes). Some systems
+may have a wider range of niceness values; conversely, other systems may
enforce more restrictive limits. An attempt to set the niceness
outside the supported range is treated as an attempt to use the
minimum or maximum supported value.
@@ -13308,20 +16484,19 @@ A niceness should not be confused with a scheduling priority, which
lets applications determine the order in which threads are scheduled
to run. Unlike a priority, a niceness is merely advice to the
scheduler, which the scheduler is free to ignore. Also, as a point of
-terminology, @acronym{POSIX} defines the behavior of @command{nice} in
-terms of a @dfn{nice value}, which is the nonnegative difference
+terminology, POSIX defines the behavior of @command{nice} in
+terms of a @dfn{nice value}, which is the non-negative difference
between a niceness and the minimum niceness. Though @command{nice}
-conforms to @acronym{POSIX}, its documentation and diagnostics use the
+conforms to POSIX, its documentation and diagnostics use the
term ``niceness'' for compatibility with historical practice.
@var{command} must not be a special built-in utility (@pxref{Special
built-in utilities}).
-@cindex conflicts with shell built-ins
-@cindex built-in shell commands, conflicts with
-Because many shells have a built-in @command{nice} command, using an
-unadorned @command{nice} in a script or interactively may get you
-different functionality than that described here.
+@mayConflictWithShellBuiltIn{nice}
+
+Note to change the @dfn{niceness} of an existing process,
+one needs to use the @command{renice} command.
The program accepts the following option. Also see @ref{Common options}.
Options must precede operands.
@@ -13342,12 +16517,16 @@ option syntax @option{-@var{adjustment}}. New scripts should use
@end table
+@command{nice} is installed only on systems that have the POSIX
+@code{setpriority} function, so portable scripts should not rely on
+its existence on non-POSIX platforms.
+
@cindex exit status of @command{nice}
Exit status:
@display
0 if no @var{command} is specified and the niceness is output
-1 if @command{nice} itself fails
+125 if @command{nice} itself fails
126 if @var{command} is found but cannot be invoked
127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@@ -13419,12 +16598,13 @@ out. Synopsis:
nohup @var{command} [@var{arg}]@dots{}
@end example
-If standard input is a terminal, it is redirected from
-@file{/dev/null} so that terminal sessions do not mistakenly consider
-the terminal to be used by the command. This is a @acronym{GNU}
-extension; programs intended to be portable to non-@acronym{GNU} hosts
-should use @samp{nohup @var{command} [@var{arg}]@dots{} </dev/null}
-instead.
+If standard input is a terminal, redirect it so that terminal sessions
+do not mistakenly consider the terminal to be used by the command.
+Make the substitute file descriptor unreadable, so that commands that
+mistakenly attempt to read from standard input can report an error.
+This redirection is a GNU extension; programs intended to be portable
+to non-GNU hosts can use @samp{nohup @var{command} [@var{arg}]@dots{}
+0>/dev/null} instead.
@flindex nohup.out
If standard output is a terminal, the command's standard output is appended
@@ -13441,6 +16621,14 @@ However, if standard output is closed, standard error terminal output
is instead appended to the file @file{nohup.out} or
@file{$HOME/nohup.out} as above.
+To capture the command's output to a file other than @file{nohup.out}
+you can redirect it. For example, to capture the output of
+@command{make}:
+
+@example
+nohup make > make.log
+@end example
+
@command{nohup} does not automatically put the command it runs in the
background; you must do that explicitly, by ending the command line
with an @samp{&}. Also, @command{nohup} does not alter the
@@ -13457,167 +16645,198 @@ options}. Options must precede operands.
Exit status:
@display
+125 if @command{nohup} itself fails, and @env{POSIXLY_CORRECT} is not set
126 if @var{command} is found but cannot be invoked
-127 if @command{nohup} itself fails or if @var{command} cannot be found
+127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@end display
+If @env{POSIXLY_CORRECT} is set, internal failures give status 127
+instead of 125.
+
-@node su invocation
-@section @command{su}: Run a command with substitute user and group ID
+@node stdbuf invocation
+@section @command{stdbuf}: Run a command with modified I/O stream buffering
-@pindex su
-@cindex substitute user and group IDs
-@cindex user ID, switching
-@cindex super-user, becoming
-@cindex root, becoming
+@pindex stdbuf
+@cindex standard streams, buffering
+@cindex line buffered
-@command{su} 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 @var{user}. Synopsis:
+@command{stdbuf} allows one to modify the buffering operations of the
+three standard I/O streams associated with a program. Synopsis:
@example
-su [@var{option}]@dots{} [@var{user} [@var{arg}]@dots{}]
+stdbuf @var{option}@dots{} @var{command}
@end example
-@cindex passwd entry, and @command{su} shell
-@flindex /bin/sh
-@flindex /etc/passwd
-If no @var{user} is given, the default is @code{root}, the super-user.
-The shell to use is taken from @var{user}'s @code{passwd} entry, or
-@file{/bin/sh} if none is specified there. If @var{user} has a
-password, @command{su} prompts for the password unless run by a user with
-effective user ID of zero (the super-user).
+@var{command} must start with the name of a program that
+@enumerate
+@item
+uses the ISO C @code{FILE} streams for input/output (note the
+programs @command{dd} and @command{cat} don't do that),
-@vindex HOME
-@vindex SHELL
-@vindex USER
-@vindex LOGNAME
-@cindex login shell
-By default, @command{su} does not change the current directory.
-It sets the environment variables @env{HOME} and @env{SHELL}
-from the password entry for @var{user}, and if @var{user} is not
-the super-user, sets @env{USER} and @env{LOGNAME} to @var{user}.
-By default, the shell is not a login shell.
+@item
+does not adjust the buffering of its standard streams (note the
+program @command{tee} is not in this category).
+@end enumerate
Any additional @var{arg}s are passed as additional arguments to the
-shell.
-
-@cindex @option{-su}
-GNU @command{su} does not treat @file{/bin/sh} or any other shells specially
-(e.g., by setting @code{argv[0]} to @option{-su}, passing @option{-c} only
-to certain shells, etc.).
-
-@findex syslog
-@command{su} can optionally be compiled to use @code{syslog} to report
-failed, and optionally successful, @command{su} attempts. (If the system
-supports @code{syslog}.) However, GNU @command{su} does not check if the
-user is a member of the @code{wheel} group; see below.
+@var{command}.
The program accepts the following options. Also see @ref{Common options}.
@table @samp
-@item -c @var{command}
-@itemx --command=@var{command}
-@opindex -c
-@opindex --command
-Pass @var{command}, a single command line to run, to the shell with
-a @option{-c} option instead of starting an interactive shell.
-@item -f
-@itemx --fast
-@opindex -f
-@opindex --fast
-@flindex .cshrc
-@cindex file name pattern expansion, disabled
-@cindex globbing, disabled
-Pass the @option{-f} option to the shell. This probably only makes sense
-if the shell run is @command{csh} or @command{tcsh}, for which the @option{-f}
-option prevents reading the startup file (@file{.cshrc}). With
-Bourne-like shells, the @option{-f} option disables file name pattern
-expansion (globbing), which is not likely to be useful.
+@item -i @var{mode}
+@itemx --input=@var{mode}
+@opindex -i
+@opindex --input
+Adjust the standard input stream buffering.
-@item -
-@itemx -l
-@itemx --login
-@opindex -
-@opindex -l
-@opindex --login
-@c other variables already indexed above
-@vindex TERM
-@vindex PATH
-@cindex login shell, creating
-Make the shell a login shell. This means the following. Unset all
-environment variables except @env{TERM}, @env{HOME}, and @env{SHELL}
-(which are set as described above), and @env{USER} and @env{LOGNAME}
-(which are set, even for the super-user, as described above), and set
-@env{PATH} to a compiled-in default value. Change to @var{user}'s home
-directory. Prepend @samp{-} to the shell's name, intended to make it
-read its login startup file(s).
+@item -o @var{mode}
+@itemx --output=@var{mode}
+@opindex -o
+@opindex --output
+Adjust the standard output stream buffering.
-@item -m
-@itemx -p
-@itemx --preserve-environment
-@opindex -m
-@opindex -p
-@opindex --preserve-environment
-@cindex environment, preserving
-@flindex /etc/shells
-@cindex restricted shell
-Do not change the environment variables @env{HOME}, @env{USER},
-@env{LOGNAME}, or @env{SHELL}. Run the shell given in the environment
-variable @env{SHELL} instead of the shell from @var{user}'s passwd
-entry, unless the user running @command{su} is not the super-user and
-@var{user}'s shell is restricted. A @dfn{restricted shell} is one that
-is not listed in the file @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 @option{--login} and @option{--shell}.
-
-@item -s @var{shell}
-@itemx --shell=@var{shell}
-@opindex -s
-@opindex --shell
-Run @var{shell} instead of the shell from @var{user}'s passwd entry,
-unless the user running @command{su} is not the super-user and @var{user}'s
-shell is restricted (see @option{-m} just above).
+@item -e @var{mode}
+@itemx --error=@var{mode}
+@opindex -e
+@opindex --error
+Adjust the standard error stream buffering.
+
+@end table
+
+The @var{mode} can be specified as follows:
+
+@table @samp
+
+@item L
+Set the stream to line buffered mode.
+In this mode data is coalesced until a newline is output or
+input is read from any stream attached to a terminal device.
+This option is invalid with standard input.
+
+@item 0
+Disable buffering of the selected stream.
+In this mode, data is output immediately and only the
+amount of data requested is read from input.
+Note the difference in function for input and output.
+Disabling buffering for input will not influence the responsiveness
+or blocking behavior of the stream input functions.
+For example @code{fread} will still block until @code{EOF} or error,
+even if the underlying @code{read} returns less data than requested.
+
+@item @var{size}
+Specify the size of the buffer to use in fully buffered mode.
+@multiplierSuffixesNoBlocks{size}
@end table
-@cindex exit status of @command{su}
+@command{stdbuf} is installed only on platforms that use the
+Executable and Linkable Format (ELF) and support the
+@code{constructor} attribute, so portable scripts should not rely on
+its existence.
+
+@cindex exit status of @command{stdbuf}
Exit status:
@display
-1 if @command{su} itself fails
-126 if subshell is found but cannot be invoked
-127 if subshell cannot be found
-the exit status of the subshell otherwise
+125 if @command{stdbuf} itself fails
+126 if @var{command} is found but cannot be invoked
+127 if @var{command} cannot be found
+the exit status of @var{command} otherwise
@end display
-@cindex wheel group, not supported
-@cindex group wheel, not supported
-@cindex fascism
-@subsection Why GNU @command{su} does not support the @samp{wheel} group
-(This section is by Richard Stallman.)
+@node timeout invocation
+@section @command{timeout}: Run a command with a time limit
-@cindex Twenex
-@cindex MIT AI lab
-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.)
+@pindex timeout
+@cindex time limit
+@cindex run commands with bounded time
-However, occasionally the rulers do tell someone. Under the usual
-@command{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.
+@command{timeout} runs the given @var{command} and kills it if it is
+still running after the specified time interval. Synopsis:
-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.
+@example
+timeout [@var{option}] @var{duration} @var{command} [@var{arg}]@dots{}
+@end example
+
+@var{command} must not be a special built-in utility (@pxref{Special
+built-in utilities}).
+
+The program accepts the following options. Also see @ref{Common options}.
+Options must precede operands.
+
+@table @samp
+@item --preserve-status
+@opindex --preserve-status
+Return the exit status of the managed @var{command} on timeout, rather than
+a specific exit status indicating a timeout. This is useful if the
+managed @var{command} supports running for an indeterminate amount of time.
+
+@item --foreground
+@opindex --foreground
+Don't create a separate background program group, so that
+the managed @var{command} can use the foreground TTY normally.
+This is needed to support timing out commands not started
+directly from an interactive shell, in two situations.
+@enumerate
+@item
+@var{command} is interactive and needs to read from the terminal for example
+@item
+the user wants to support sending signals directly to @var{command}
+from the terminal (like Ctrl-C for example)
+@end enumerate
+
+Note in this mode of operation, any children of @var{command}
+will not be timed out. Also SIGCONT will not be sent to @var{command},
+as it's generally not needed with foreground processes, and can
+cause intermittent signal delivery issues with programs that are monitors
+themselves (like GDB for example).
+
+@item -k @var{duration}
+@itemx --kill-after=@var{duration}
+@opindex -k
+@opindex --kill-after
+Ensure the monitored @var{command} is killed by also sending a @samp{KILL}
+signal, after the specified @var{duration}. Without this option, if the
+selected signal proves not to be fatal, @command{timeout} does not kill
+the @var{command}.
+
+@item -s @var{signal}
+@itemx --signal=@var{signal}
+@opindex -s
+@opindex --signal
+Send this @var{signal} to @var{command} on timeout, rather than the
+default @samp{TERM} signal. @var{signal} may be a name like @samp{HUP}
+or a number. @xref{Signal specifications}.
+@end table
+
+@cindex time units
+@var{duration} is a floating point number followed by an optional unit:
+@display
+@samp{s} for seconds (the default)
+@samp{m} for minutes
+@samp{h} for hours
+@samp{d} for days
+@end display
+A duration of 0 disables the associated timeout.
+Note that the actual timeout duration is dependent on system conditions,
+which should be especially considered when specifying sub-second timeouts.
+
+@cindex exit status of @command{timeout}
+Exit status:
+
+@display
+124 if @var{command} times out
+125 if @command{timeout} itself fails
+126 if @var{command} is found but cannot be invoked
+127 if @var{command} cannot be found
+137 if @var{command} is sent the KILL(9) signal (128+9)
+the exit status of @var{command} otherwise
+@end display
@node Process control
@@ -13646,9 +16865,11 @@ kill [-s @var{signal} | --signal @var{signal} | -@var{signal}] @var{pid}@dots{}
kill [-l | --list | -t | --table] [@var{signal}]@dots{}
@end example
+@mayConflictWithShellBuiltIn{kill}
+
The first form of the @command{kill} command sends a signal to all
@var{pid} arguments. The default signal to send if none is specified
-is @samp{TERM}. The special signal number @samp{0} does not denote a
+is @samp{TERM}@. The special signal number @samp{0} does not denote a
valid signal, but can be used to test whether the @var{pid} arguments
specify processes to which a signal could be sent.
@@ -13664,9 +16885,9 @@ If @var{pid} is not positive, a system-dependent set of system
processes is excluded from the list of processes to which the signal
is sent.
-If a negative @var{PID} argument is desired as the first one, it
+If a negative @var{pid} argument is desired as the first one, it
should be preceded by @option{--}. However, as a common extension to
-@acronym{POSIX}, @option{--} is not required with @samp{kill
+POSIX, @option{--} is not required with @samp{kill
-@var{signal} -@var{pid}}. The following commands are equivalent:
@example
@@ -13696,90 +16917,11 @@ The @command{kill} command also supports the @option{--help} and
A @var{signal} may be a signal name like @samp{HUP}, or a signal
number like @samp{1}, or an exit status of a process terminated by the
signal. A signal name can be given in canonical form or prefixed by
-@samp{SIG}. The case of the letters is ignored, except for the
+@samp{SIG}@. The case of the letters is ignored, except for the
@option{-@var{signal}} option which must use upper case to avoid
-ambiguity with lower case option letters. The following signal names
-and numbers are supported on all @acronym{POSIX} compliant systems:
-
-@table @samp
-@item HUP
-1. Hangup.
-@item INT
-2. Terminal interrupt.
-@item QUIT
-3. Terminal quit.
-@item ABRT
-6. Process abort.
-@item KILL
-9. Kill (cannot be caught or ignored).
-@item ALRM
-14. Alarm Clock.
-@item TERM
-15. Termination.
-@end table
-
-@noindent
-Other supported signal names have system-dependent corresponding
-numbers. All systems conforming to @acronym{POSIX} 1003.1-2001 also
-support the following signals:
-
-@table @samp
-@item BUS
-Access to an undefined portion of a memory object.
-@item CHLD
-Child process terminated, stopped, or continued.
-@item CONT
-Continue executing, if stopped.
-@item FPE
-Erroneous arithmetic operation.
-@item ILL
-Illegal Instruction.
-@item PIPE
-Write on a pipe with no one to read it.
-@item SEGV
-Invalid memory reference.
-@item STOP
-Stop executing (cannot be caught or ignored).
-@item TSTP
-Terminal stop.
-@item TTIN
-Background process attempting read.
-@item TTOU
-Background process attempting write.
-@item URG
-High bandwidth data is available at a socket.
-@item USR1
-User-defined signal 1.
-@item USR2
-User-defined signal 2.
-@end table
-
-@noindent
-@acronym{POSIX} 1003.1-2001 systems that support the @acronym{XSI} extension
-also support the following signals:
-
-@table @samp
-@item POLL
-Pollable event.
-@item PROF
-Profiling timer expired.
-@item SYS
-Bad system call.
-@item TRAP
-Trace/breakpoint trap.
-@item VTALRM
-Virtual timer expired.
-@item XCPU
-CPU time limit exceeded.
-@item XFSZ
-File size limit exceeded.
-@end table
-
-@noindent
-@acronym{POSIX} 1003.1-2001 systems that support the @acronym{XRT} extension
-also support at least eight real-time signals called @samp{RTMIN},
-@samp{RTMIN+1}, @dots{}, @samp{RTMAX-1}, @samp{RTMAX}.
-
+ambiguity with lower case option letters.
+@xref{Signal specifications}, for a list of supported
+signal names and numbers.
@node Delaying
@chapter Delaying
@@ -13826,12 +16968,14 @@ days
Historical implementations of @command{sleep} have required that
@var{number} be an integer, and only accepted a single argument
without a suffix. However, GNU @command{sleep} accepts
-arbitrary floating point numbers (using a period before any fractional
-digits).
+arbitrary floating point numbers. @xref{Floating point}.
The only options are @option{--help} and @option{--version}. @xref{Common
options}.
+@c sleep is a shell built-in at least with Solaris 11's /bin/sh
+@mayConflictWithShellBuiltIn{sleep}
+
@exitstatus
@@ -13843,6 +16987,7 @@ These programs do numerically-related operations.
@menu
* factor invocation:: Show factors of numbers.
+* numfmt invocation:: Reformat numbers.
* seq invocation:: Print sequences of numbers.
@end menu
@@ -13863,37 +17008,386 @@ factor @var{option}
If no @var{number} is specified on the command line, @command{factor} reads
numbers from standard input, delimited by newlines, tabs, or spaces.
-The only options are @option{--help} and @option{--version}. @xref{Common
-options}.
+The @command{factor} command supports only a small number of options:
-The algorithm it uses is not very sophisticated, so for some inputs
-@command{factor} runs for a long time. The hardest numbers to factor are
-the products of large primes. Factoring the product of the two largest 32-bit
-prime numbers takes about 80 seconds of CPU time on a 1.6 GHz Athlon.
+@table @samp
+@item --help
+Print a short help on standard output, then exit without further
+processing.
+
+@item --version
+Print the program version on standard output, then exit without further
+processing.
+@end table
+
+Factoring the product of the eighth and ninth Mersenne primes
+takes about 30 milliseconds of CPU time on a 2.2 GHz Athlon.
@example
-$ p=`echo '4294967279 * 4294967291'|bc`
-$ factor $p
-18446743979220271189: 4294967279 4294967291
+M8=$(echo 2^31-1|bc)
+M9=$(echo 2^61-1|bc)
+n=$(echo "$M8 * $M9" | bc)
+/usr/bin/time -f %U factor $n
+4951760154835678088235319297: 2147483647 2305843009213693951
+0.03
@end example
-Similarly, it takes about 80 seconds for GNU factor (from coreutils-5.1.2)
-to ``factor'' the largest 64-bit prime:
+Similarly, factoring the eighth Fermat number @math{2^{256}+1} takes
+about 20 seconds on the same machine.
+
+Factoring large numbers is, in general, hard. The Pollard-Brent rho
+algorithm used by @command{factor} is particularly effective for
+numbers with relatively small factors. If you wish to factor large
+numbers which do not have small factors (for example, numbers which
+are the product of two large primes), other methods are far better.
+
+If @command{factor} is built without using GNU MP, only
+single-precision arithmetic is available, and so large numbers
+(typically @math{2^{128}} and above) will not be supported.
+The single-precision code uses an algorithm which is designed
+for factoring smaller numbers.
+
+@exitstatus
+
+
+@node numfmt invocation
+@section @command{numfmt}: Reformat numbers
+
+@pindex numfmt
+
+@command{numfmt} reads numbers in various representations and reformats them
+as requested. The most common usage is converting numbers to/from @emph{human}
+representation (e.g. @samp{4G} @expansion{} @samp{4,000,000,000}).
@example
-$ factor 18446744073709551557
- 18446744073709551557: 18446744073709551557
+numfmt [@var{option}]@dots{} [@var{number}]
@end example
-In contrast, @command{factor} factors the largest 64-bit number in just
-over a tenth of a second:
+@command{numfmt} converts each @var{number} on the command-line according to the
+specified options (see below). If no @var{number}s are given, it reads numbers
+from standard input. @command{numfmt} can optionally extract numbers from
+specific columns, maintaining proper line padding and alignment.
+
+@exitstatus
+
+See @option{--invalid} for additional information regarding exit status.
+
+@subsection General options
+
+The program accepts the following options. Also see @ref{Common options}.
+
+@table @samp
+
+@item --debug
+@opindex --debug
+Print (to standard error) warning messages about possible erroneous usage.
+
+@item -d @var{d}
+@itemx --delimiter=@var{d}
+@opindex -d
+@opindex --delimiter
+Use the character @var{d} as input field separator (default: whitespace).
+@emph{Note}: Using non-default delimiter turns off automatic padding.
+
+@item --field=@var{fields}
+@opindex --field
+Convert the number in input field @var{fields} (default: 1).
+@var{fields} supports @command{cut} style field ranges:
@example
-$ factor `echo '2^64-1'|bc`
-18446744073709551615: 3 5 17 257 641 65537 6700417
+N N'th field, counted from 1
+N- from N'th field, to end of line
+N-M from N'th to M'th field (inclusive)
+-M from first to M'th field (inclusive)
+- all fields
@end example
-@exitstatus
+
+@item --format=@var{format}
+@opindex --format
+Use printf-style floating FORMAT string. The @var{format} string must contain
+one @samp{%f} directive, optionally with @samp{'}, @samp{-}, @samp{0}, width
+or precision modifiers. The @samp{'} modifier will enable @option{--grouping},
+the @samp{-} modifier will enable left-aligned @option{--padding} and the width
+modifier will enable right-aligned @option{--padding}. The @samp{0} width
+modifier (without the @samp{-} modifier) will generate leading zeros on the
+number, up to the specified width. A precision specification like @samp{%.1f}
+will override the precision determined from the input data or set due to
+@option{--to} option auto scaling.
+
+@item --from=@var{unit}
+@opindex --from
+Auto-scales input numbers according to @var{unit}. See UNITS below.
+The default is no scaling, meaning suffixes (e.g. @samp{M}, @samp{G}) will
+trigger an error.
+
+@item --from-unit=@var{n}
+@opindex --from-unit
+Specify the input unit size (instead of the default 1). Use this option when
+the input numbers represent other units (e.g. if the input number @samp{10}
+represents 10 units of 512 bytes, use @samp{--from-unit=512}).
+Suffixes are handled as with @samp{--from=auto}.
+
+@item --grouping
+@opindex --grouping
+Group digits in output numbers according to the current locale's grouping rules
+(e.g @emph{Thousands Separator} character, commonly @samp{.} (dot) or @samp{,}
+comma). This option has no effect in @samp{POSIX/C} locale.
+
+@item --header[=@var{n}]
+@opindex --header
+@opindex --header=N
+Print the first @var{n} (default: 1) lines without any conversion.
+
+@item --invalid=@var{mode}
+@opindex --invalid
+The default action on input errors is to exit immediately with status code 2.
+@option{--invalid=@samp{abort}} explicitly specifies this default mode.
+With a @var{mode} of @samp{fail}, print a warning for @emph{each} conversion
+error, and exit with status 2. With a @var{mode} of @samp{warn}, exit with
+status 0, even in the presence of conversion errors, and with a @var{mode} of
+@samp{ignore} do not even print diagnostics.
+
+@item --padding=@var{n}
+@opindex --padding
+Pad the output numbers to @var{n} characters, by adding spaces. If @var{n} is
+a positive number, numbers will be right-aligned. If @var{n} is a negative
+number, numbers will be left-aligned. By default, numbers are automatically
+aligned based on the input line's width (only with the default delimiter).
+
+@item --round=@var{method}
+@opindex --round
+@opindex --round=up
+@opindex --round=down
+@opindex --round=from-zero
+@opindex --round=towards-zero
+@opindex --round=nearest
+When converting number representations, round the number according to
+@var{method}, which can be @samp{up}, @samp{down},
+@samp{from-zero} (the default), @samp{towards-zero}, @samp{nearest}.
+
+@item --suffix=@var{suffix}
+@opindex --suffix
+Add @samp{SUFFIX} to the output numbers, and accept optional @samp{SUFFIX} in
+input numbers.
+
+@item --to=@var{unit}
+@opindex --to
+Auto-scales output numbers according to @var{unit}. See @emph{Units} below.
+The default is no scaling, meaning all the digits of the number are printed.
+
+@item --to-unit=@var{n}
+@opindex --to-unit
+Specify the output unit size (instead of the default 1). Use this option when
+the output numbers represent other units (e.g. to represent @samp{4,000,000}
+bytes in blocks of 1KB, use @samp{--to=si --to-unit=1000}).
+Suffixes are handled as with @samp{--from=auto}.
+
+@optZeroTerminated
+@newlineFieldSeparator
+
+@end table
+
+@subsection Possible @var{unit}s:
+
+The following are the possible @var{unit} options with @option{--from=UNITS} and
+@option{--to=UNITS}:
+
+@table @var
+
+@item none
+No scaling is performed. For input numbers, no suffixes are accepted, and any
+trailing characters following the number will trigger an error. For output
+numbers, all digits of the numbers will be printed.
+
+@item si
+Auto-scale numbers according to the @emph{International System of Units (SI)}
+standard.
+For input numbers, accept one of the following suffixes.
+For output numbers, values larger than 1000 will be rounded, and printed with
+one of the following suffixes:
+
+@example
+@samp{K} => @math{1000^1 = 10^3} (Kilo)
+@samp{M} => @math{1000^2 = 10^6} (Mega)
+@samp{G} => @math{1000^3 = 10^9} (Giga)
+@samp{T} => @math{1000^4 = 10^{12}} (Tera)
+@samp{P} => @math{1000^5 = 10^{15}} (Peta)
+@samp{E} => @math{1000^6 = 10^{18}} (Exa)
+@samp{Z} => @math{1000^7 = 10^{21}} (Zetta)
+@samp{Y} => @math{1000^8 = 10^{24}} (Yotta)
+@end example
+
+@item iec
+Auto-scale numbers according to the @emph{International Electrotechnical
+Commission (IEC)} standard.
+For input numbers, accept one of the following suffixes.
+For output numbers, values larger than 1024 will be rounded, and printed with
+one of the following suffixes:
+
+@example
+@samp{K} => @math{1024^1 = 2^{10}} (Kibi)
+@samp{M} => @math{1024^2 = 2^{20}} (Mebi)
+@samp{G} => @math{1024^3 = 2^{30}} (Gibi)
+@samp{T} => @math{1024^4 = 2^{40}} (Tebi)
+@samp{P} => @math{1024^5 = 2^{50}} (Pebi)
+@samp{E} => @math{1024^6 = 2^{60}} (Exbi)
+@samp{Z} => @math{1024^7 = 2^{70}} (Zebi)
+@samp{Y} => @math{1024^8 = 2^{80}} (Yobi)
+@end example
+
+The @option{iec} option uses a single letter suffix (e.g. @samp{G}), which is
+not fully standard, as the @emph{iec} standard recommends a two-letter symbol
+(e.g @samp{Gi}) - but in practice, this method common. Compare with
+the @option{iec-i} option.
+
+@item iec-i
+Auto-scale numbers according to the @emph{International Electrotechnical
+Commission (IEC)} standard.
+For input numbers, accept one of the following suffixes.
+For output numbers, values larger than 1024 will be rounded, and printed with
+one of the following suffixes:
+
+@example
+@samp{Ki} => @math{1024^1 = 2^{10}} (Kibi)
+@samp{Mi} => @math{1024^2 = 2^{20}} (Mebi)
+@samp{Gi} => @math{1024^3 = 2^{30}} (Gibi)
+@samp{Ti} => @math{1024^4 = 2^{40}} (Tebi)
+@samp{Pi} => @math{1024^5 = 2^{50}} (Pebi)
+@samp{Ei} => @math{1024^6 = 2^{60}} (Exbi)
+@samp{Zi} => @math{1024^7 = 2^{70}} (Zebi)
+@samp{Yi} => @math{1024^8 = 2^{80}} (Yobi)
+@end example
+
+The @option{iec-i} option uses a two-letter suffix symbol (e.g. @samp{Gi}),
+as the @emph{iec} standard recommends, but this is not always common in
+practice. Compare with the @option{iec} option.
+
+@item auto
+@samp{auto} can only be used with @option{--from}. With this method, numbers
+with @samp{K},@samp{M},@samp{G},@samp{T},@samp{P},@samp{E},@samp{Z},@samp{Y}
+suffixes are interpreted as @emph{SI} values, and numbers with @samp{Ki},
+@samp{Mi},@samp{Gi},@samp{Ti},@samp{Pi},@samp{Ei},@samp{Zi},@samp{Yi} suffixes
+are interpreted as @emph{IEC} values.
+
+@end table
+
+@subsection Examples of using @command{numfmt}
+
+Converting a single number from/to @emph{human} representation:
+@example
+$ numfmt --to=si 500000
+500K
+
+$ numfmt --to=iec 500000
+489K
+
+$ numfmt --to=iec-i 500000
+489Ki
+
+$ numfmt --from=si 1M
+1000000
+
+$ numfmt --from=iec 1M
+1048576
+
+# with '--from=auto', M=Mega, Mi=Mebi
+$ numfmt --from=auto 1M
+1000000
+$ numfmt --from=auto 1Mi
+1048576
+@end example
+
+Converting from @samp{SI} to @samp{IEC} scales (e.g. when a harddisk capacity is
+advertised as @samp{1TB}, while checking the drive's capacity gives lower
+values):
+
+@example
+$ numfmt --from=si --to=iec 1T
+932G
+@end example
+
+
+Converting a single field from an input file / piped input (these contrived
+examples are for demonstration purposes only, as both @command{ls} and
+@command{df} support the @option{--human-readable} option to
+output sizes in human-readable format):
+
+@example
+# Third field (file size) will be shown in SI representation
+$ ls -log | numfmt --field 3 --header --to=si | head -n4
+-rw-r--r-- 1 94K Aug 23 2011 ABOUT-NLS
+-rw-r--r-- 1 3.7K Jan 7 16:15 AUTHORS
+-rw-r--r-- 1 36K Jun 1 2011 COPYING
+-rw-r--r-- 1 0 Jan 7 15:15 ChangeLog
+
+# Second field (size) will be shown in IEC representation
+$ df --block-size=1 | numfmt --field 2 --header --to=iec | head -n4
+File system 1B-blocks Used Available Use% Mounted on
+rootfs 132G 104741408 26554036 80% /
+tmpfs 794M 7580 804960 1% /run/shm
+/dev/sdb1 694G 651424756 46074696 94% /home
+@end example
+
+
+Output can be tweaked using @option{--padding} or @option{--format}:
+
+@example
+# Pad to 10 characters, right-aligned
+$ du -s * | numfmt --to=si --padding=10
+ 2.5K config.log
+ 108 config.status
+ 1.7K configure
+ 20 configure.ac
+
+# Pad to 10 characters, left-aligned
+$ du -s * | numfmt --to=si --padding=-10
+2.5K config.log
+108 config.status
+1.7K configure
+20 configure.ac
+
+# Pad to 10 characters, left-aligned, using 'format'
+$ du -s * | numfmt --to=si --format="%10f"
+ 2.5K config.log
+ 108 config.status
+ 1.7K configure
+ 20 configure.ac
+
+# Pad to 10 characters, left-aligned, using 'format'
+$ du -s * | numfmt --to=si --padding="%-10f"
+2.5K config.log
+108 config.status
+1.7K configure
+20 configure.ac
+@end example
+
+With locales that support grouping digits, using @option{--grouping} or
+@option{--format} enables grouping. In @samp{POSIX} locale, grouping is
+silently ignored:
+
+@example
+$ LC_ALL=C numfmt --from=iec --grouping 2G
+2147483648
+
+$ LC_ALL=en_US.utf8 numfmt --from=iec --grouping 2G
+2,147,483,648
+
+$ LC_ALL=ta_IN numfmt --from=iec --grouping 2G
+2,14,74,83,648
+
+$ LC_ALL=C ./src/numfmt --from=iec --format="==%'15f==" 2G
+== 2147483648==
+
+$ LC_ALL=en_US.utf8 ./src/numfmt --from=iec --format="==%'15f==" 2G
+== 2,147,483,648==
+
+$ LC_ALL=en_US.utf8 ./src/numfmt --from=iec --format="==%'-15f==" 2G
+==2,147,483,648 ==
+
+$ LC_ALL=ta_IN ./src/numfmt --from=iec --format="==%'15f==" 2G
+== 2,14,74,83,648==
+@end example
@node seq invocation
@@ -13917,8 +17411,10 @@ When @var{increment} is not specified, it defaults to @samp{1},
even when @var{first} is larger than @var{last}.
@var{first} also defaults to @samp{1}. So @code{seq 1} prints
@samp{1}, but @code{seq 0} and @code{seq 10 5} produce no output.
-Floating-point numbers
-may be specified (using a period before any fractional digits).
+The sequence of numbers ends when the sum of the current number and
+@var{increment} would become greater than @var{last},
+so @code{seq 1 10 10} only produces @samp{1}.
+Floating-point numbers may be specified. @xref{Floating point}.
The program accepts the following options. Also see @ref{Common options}.
Options must precede operands.
@@ -13926,13 +17422,13 @@ Options must precede operands.
@table @samp
@item -f @var{format}
@itemx --format=@var{format}
-@opindex -f @var{format}
-@opindex --format=@var{format}
+@opindex -f
+@opindex --format
@cindex formatting of numbers in @command{seq}
Print all numbers using @var{format}.
@var{format} must contain exactly one of the @samp{printf}-style
floating point conversion specifications @samp{%a}, @samp{%e},
-@samp{%f}, @samp{%g}, @samp{%A}, @samp{%E}, @samp{%F}, @samp{%G}.
+@samp{%f}, @samp{%g}, @samp{%A}, @samp{%E}, @samp{%F}, @samp{%G}@.
The @samp{%} may be followed by zero or more flags taken from the set
@samp{-+#0 '}, then an optional width containing one or more digits,
then an optional precision consisting of a @samp{.} followed by zero
@@ -13948,12 +17444,16 @@ the default format is @samp{%g}.
@item -s @var{string}
@itemx --separator=@var{string}
+@opindex -s
+@opindex --separator
@cindex separator for numbers in @command{seq}
Separate numbers with @var{string}; default is a newline.
The output always terminates with a newline.
@item -w
@itemx --equal-width
+@opindex -w
+@opindex --equal-width
Print all numbers with the same width, by padding with leading zeros.
@var{first}, @var{step}, and @var{last} should all use a fixed point
decimal representation.
@@ -13974,7 +17474,7 @@ If you want hexadecimal integer output, you can use @command{printf}
to perform the conversion:
@example
-$ printf '%x\n' `seq 1048575 1024 1050623`
+$ printf '%x\n' $(seq 1048575 1024 1050623)
fffff
1003ff
1007ff
@@ -13994,46 +17494,33 @@ To generate octal output, use the printf @code{%o} format instead
of @code{%x}.
On most systems, seq can produce whole-number output for values up to
-at least @code{2^53}. Larger integers are approximated. The details
-differ depending on your floating-point implementation, but a common
-case is that @command{seq} works with integers through @code{2^64},
+at least @math{2^{53}}. Larger integers are approximated. The details
+differ depending on your floating-point implementation.
+@xref{Floating point}. A common
+case is that @command{seq} works with integers through @math{2^{64}},
and larger integers may not be numerically correct:
@example
-$ seq 18446744073709551616 1 18446744073709551618
-18446744073709551616
-18446744073709551616
-18446744073709551618
-@end example
-
-Be careful when using @command{seq} with a fractional @var{increment};
-otherwise you may see surprising results. Most people would expect to
-see @code{0.000003} printed as the last number in this example:
-
-@example
-$ seq -s ' ' 0 0.000001 0.000003
-0.000000 0.000001 0.000002
+$ seq 50000000000000000000 2 50000000000000000004
+50000000000000000000
+50000000000000000000
+50000000000000000004
@end example
-But that doesn't happen on many systems because @command{seq} is
-implemented using binary floating point arithmetic (via the C
-@code{long double} type)---which means decimal fractions like @code{0.000001}
-cannot be represented exactly. That in turn means some nonintuitive
-conditions like @w{@code{0.000001 * 3 > 0.000003}} will end up being true.
+However, note that when limited to non-negative whole numbers,
+an increment of 1 and no format-specifying option, seq can print
+arbitrarily large numbers.
-To work around that in the above example, use a slightly larger number as
-the @var{last} value:
+Be careful when using @command{seq} with outlandish values: otherwise
+you may see surprising results, as @command{seq} uses floating point
+internally. For example, on the x86 platform, where the internal
+representation uses a 64-bit fraction, the command:
@example
-$ seq -s ' ' 0 0.000001 0.0000031
-0.000000 0.000001 0.000002 0.000003
+seq 1 0.0000000000000000001 1.0000000000000000009
@end example
-In general, when using an @var{increment} with a fractional part, where
-(@var{last} - @var{first}) / @var{increment} is (mathematically) a whole
-number, specify a slightly larger (or smaller, if @var{increment} is negative)
-value for @var{last} to ensure that @var{last} is the final value printed
-by seq.
+outputs 1.0000000000000000007 twice and skips 1.0000000000000000008.
@exitstatus
@@ -14042,7 +17529,7 @@ by seq.
@chapter File permissions
@include perm.texi
-@include getdate.texi
+@include parse-datetime.texi
@c What's GNU?
@c Arnold Robbins
@@ -14051,7 +17538,7 @@ by seq.
An earlier version of this chapter appeared in
@uref{http://www.linuxjournal.com/article.php?sid=2762, the
-@cite{What's GNU?} column of @cite{Linux Journal}, 2 (June, 1994)}.
+@cite{What's GNU@?} column of the June 1994 @cite{Linux Journal}}.
It was written by Arnold Robbins.
@menu
@@ -14069,7 +17556,8 @@ It was written by Arnold Robbins.
@unnumberedsec Toolbox Introduction
This month's column is only peripherally related to the GNU Project, in
-that it describes a number of the GNU tools on your GNU/Linux system and how they
+that it describes a number of the GNU tools on your GNU/Linux system
+and how they
might be used. What it's really about is the ``Software Tools'' philosophy
of program development and usage.
@@ -14160,7 +17648,7 @@ redirected standard output of your program away from your screen.
For filter programs to work together, the format of the data has to be
agreed upon. The most straightforward and easiest format to use is simply
lines of text. Unix data files are generally just streams of bytes, with
-lines delimited by the @acronym{ASCII} @sc{lf} (Line Feed) character,
+lines delimited by the ASCII LF (Line Feed) character,
conventionally called a ``newline'' in the Unix literature. (This is
@code{'\n'} if you're a C programmer.) This is the format used by all
the traditional filtering programs. (Many earlier operating systems
@@ -14269,7 +17757,8 @@ by a count of the number of times that line occurred in the input.
@unnumberedsec Putting the Tools Together
Now, let's suppose this is a large ISP server system with dozens of users
-logged in. The management wants the system administrator to write a program that will
+logged in. The management wants the system administrator to write a
+program that will
generate a sorted list of logged in users. Furthermore, even if a user
is logged in multiple times, his or her name should only show up in the
output once.
@@ -14311,7 +17800,8 @@ The @command{sort} command actually has a @option{-u} option that does what
@command{uniq} does. However, @command{uniq} has other uses for which one
cannot substitute @samp{sort -u}.
-The administrator puts this pipeline into a shell script, and makes it available for
+The administrator puts this pipeline into a shell script, and makes it
+available for
all the users on the system (@samp{#} is the system administrator,
or @code{root}, prompt):
@@ -14426,7 +17916,7 @@ $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' | ...
The second @command{tr} command operates on the complement of the listed
characters, which are all the letters, the digits, the underscore, and
the blank. The @samp{\n} represents the newline character; it has to
-be left alone. (The @acronym{ASCII} tab character should also be included for
+be left alone. (The ASCII tab character should also be included for
good measure in a production script.)
At this point, we have data consisting of words separated by blank space.
@@ -14440,8 +17930,8 @@ $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' |
@end smallexample
This command turns blanks into newlines. The @option{-s} option squeezes
-multiple newline characters in the output into just one. This helps us
-avoid blank lines. (The @samp{>} is the shell's ``secondary prompt.''
+multiple newline characters in the output into just one, removing
+blank lines. (The @samp{>} is the shell's ``secondary prompt.''
This is what the shell prints when it notices you haven't finished
typing in all of a command.)
@@ -14503,7 +17993,7 @@ that your spelling is incorrect. So, we need a dictionary.
The conventional location for a dictionary is @file{/usr/dict/words}.
On my GNU/Linux system,@footnote{Redhat Linux 6.1, for the November 2000
revision of this article.}
-this is a is a sorted, 45,402 word dictionary.
+this is a sorted, 45,402 word dictionary.
Now, how to compare our file with the dictionary? As before, we generate
a sorted list of words, one per line:
@@ -14576,10 +18066,10 @@ Know your toolbox! Use each program appropriately. If you don't have an
appropriate tool, build one.
@end enumerate
-As of this writing, all the programs we've discussed are available via
-anonymous @command{ftp} from: @*
-@uref{ftp://gnudist.gnu.org/textutils/textutils-1.22.tar.gz}. (There may
-be more recent versions available now.)
+As of this writing, all the programs discussed are available from
+@uref{http://ftp.gnu.org/old-gnu/textutils/textutils-1.22.tar.gz},
+with more recent versions available from
+@uref{http://ftp.gnu.org/gnu/coreutils}.
None of what I have presented in this column is new. The Software Tools
philosophy was first introduced in the book @cite{Software Tools}, by
@@ -14615,22 +18105,16 @@ philosophy, these books are unparalleled, and I recommend them highly.
Acknowledgment: I would like to express my gratitude to Brian Kernighan
of Bell Labs, the original Software Toolsmith, for reviewing this column.
-@node Copying This Manual
-@appendix Copying This Manual
-
-@menu
-* GNU Free Documentation License:: License for copying this manual.
-@end menu
+@node GNU Free Documentation License
+@appendix GNU Free Documentation License
@include fdl.texi
-@node Index
+@node Concept index
@unnumbered Index
@printindex cp
-@shortcontents
-@contents
@bye
@c Local variables: