cp/mv: add xattr support
[coreutils.git] / doc / coreutils.texi
blob7ba872ebb5bd0994fd8fd311097506e6fce4028a
1 \input texinfo
2 @c %**start of header
3 @setfilename coreutils.info
4 @settitle @sc{gnu} Coreutils
6 @c %**end of header
8 @include version.texi
9 @include constants.texi
11 @c Define new indices.
12 @defcodeindex op
13 @defcodeindex fl
15 @c Put everything in one index (arbitrarily chosen to be the concept index).
16 @syncodeindex fl cp
17 @syncodeindex fn cp
18 @syncodeindex ky cp
19 @syncodeindex op cp
20 @syncodeindex pg cp
21 @syncodeindex vr cp
23 @dircategory Basics
24 @direntry
25 * Coreutils: (coreutils).       Core GNU (file, text, shell) utilities.
26 * Common options: (coreutils)Common options.      Common options.
27 * File permissions: (coreutils)File permissions.  Access modes.
28 * Date input formats: (coreutils)Date input formats.
29 @end direntry
31 @c FIXME: the following need documentation
32 @c * [: (coreutils)[ invocation.                   File/string tests.
33 @c * pinky: (coreutils)pinky invocation.           FIXME.
34 @c * mktemp: (coreutils)mktemp invocation.         FIXME.
36 @dircategory Individual utilities
37 @direntry
38 * arch: (coreutils)arch invocation.             Print machine hardware name.
39 * base64: (coreutils)base64 invocation.         Base64 encode/decode data.
40 * basename: (coreutils)basename invocation.     Strip directory and suffix.
41 * cat: (coreutils)cat invocation.               Concatenate and write files.
42 * chcon: (coreutils)chcon invocation.           Change SELinux CTX of files.
43 * chgrp: (coreutils)chgrp invocation.           Change file groups.
44 * chmod: (coreutils)chmod invocation.           Change file permissions.
45 * chown: (coreutils)chown invocation.           Change file owners/groups.
46 * chroot: (coreutils)chroot invocation.         Specify the root directory.
47 * cksum: (coreutils)cksum invocation.           Print POSIX CRC checksum.
48 * comm: (coreutils)comm invocation.             Compare sorted files by line.
49 * cp: (coreutils)cp invocation.                 Copy files.
50 * csplit: (coreutils)csplit invocation.         Split by context.
51 * cut: (coreutils)cut invocation.               Print selected parts of lines.
52 * date: (coreutils)date invocation.             Print/set system date and time.
53 * dd: (coreutils)dd invocation.                 Copy and convert a file.
54 * df: (coreutils)df invocation.                 Report file system disk usage.
55 * dir: (coreutils)dir invocation.               List directories briefly.
56 * dircolors: (coreutils)dircolors invocation.   Color setup for ls.
57 * dirname: (coreutils)dirname invocation.       Strip non-directory suffix.
58 * du: (coreutils)du invocation.                 Report on disk usage.
59 * echo: (coreutils)echo invocation.             Print a line of text.
60 * env: (coreutils)env invocation.               Modify the environment.
61 * expand: (coreutils)expand invocation.         Convert tabs to spaces.
62 * expr: (coreutils)expr invocation.             Evaluate expressions.
63 * factor: (coreutils)factor invocation.         Print prime factors
64 * false: (coreutils)false invocation.           Do nothing, unsuccessfully.
65 * fmt: (coreutils)fmt invocation.               Reformat paragraph text.
66 * fold: (coreutils)fold invocation.             Wrap long input lines.
67 * groups: (coreutils)groups invocation.         Print group names a user is in.
68 * head: (coreutils)head invocation.             Output the first part of files.
69 * hostid: (coreutils)hostid invocation.         Print numeric host identifier.
70 * hostname: (coreutils)hostname invocation.     Print or set system name.
71 * id: (coreutils)id invocation.                 Print user identity.
72 * install: (coreutils)install invocation.       Copy and change attributes.
73 * join: (coreutils)join invocation.             Join lines on a common field.
74 * kill: (coreutils)kill invocation.             Send a signal to processes.
75 * link: (coreutils)link invocation.             Make hard links between files.
76 * ln: (coreutils)ln invocation.                 Make links between files.
77 * logname: (coreutils)logname invocation.       Print current login name.
78 * ls: (coreutils)ls invocation.                 List directory contents.
79 * md5sum: (coreutils)md5sum invocation.         Print or check MD5 digests.
80 * mkdir: (coreutils)mkdir invocation.           Create directories.
81 * mkfifo: (coreutils)mkfifo invocation.         Create FIFOs (named pipes).
82 * mknod: (coreutils)mknod invocation.           Create special files.
83 * mv: (coreutils)mv invocation.                 Rename files.
84 * nice: (coreutils)nice invocation.             Modify niceness.
85 * nl: (coreutils)nl invocation.                 Number lines and write files.
86 * nohup: (coreutils)nohup invocation.           Immunize to hangups.
87 * od: (coreutils)od invocation.                 Dump files in octal, etc.
88 * paste: (coreutils)paste invocation.           Merge lines of files.
89 * pathchk: (coreutils)pathchk invocation.       Check file name portability.
90 * pr: (coreutils)pr invocation.                 Paginate or columnate files.
91 * printenv: (coreutils)printenv invocation.     Print environment variables.
92 * printf: (coreutils)printf invocation.         Format and print data.
93 * ptx: (coreutils)ptx invocation.               Produce permuted indexes.
94 * pwd: (coreutils)pwd invocation.               Print working directory.
95 * readlink: (coreutils)readlink invocation.     Print referent of a symlink.
96 * rm: (coreutils)rm invocation.                 Remove files.
97 * rmdir: (coreutils)rmdir invocation.           Remove empty directories.
98 * runcon: (coreutils)runcon invocation.         Run in specified SELinux CTX.
99 * seq: (coreutils)seq invocation.               Print numeric sequences
100 * sha1sum: (coreutils)sha1sum invocation.       Print or check SHA-1 digests.
101 * sha2: (coreutils)sha2 utilities.              Print or check SHA-2 digests.
102 * shred: (coreutils)shred invocation.           Remove files more securely.
103 * shuf: (coreutils)shuf invocation.             Shuffling text files.
104 * sleep: (coreutils)sleep invocation.           Delay for a specified time.
105 * sort: (coreutils)sort invocation.             Sort text files.
106 * split: (coreutils)split invocation.           Split into fixed-size pieces.
107 * stat: (coreutils)stat invocation.             Report file(system) status.
108 * stty: (coreutils)stty invocation.             Print/change terminal settings.
109 * su: (coreutils)su invocation.                 Modify user and group ID.
110 * sum: (coreutils)sum invocation.               Print traditional checksum.
111 * sync: (coreutils)sync invocation.             Synchronize memory and disk.
112 * tac: (coreutils)tac invocation.               Reverse files.
113 * tail: (coreutils)tail invocation.             Output the last part of files.
114 * tee: (coreutils)tee invocation.               Redirect to multiple files.
115 * test: (coreutils)test invocation.             File/string tests.
116 * timeout: (coreutils)timeout invocation.       Run with time limit.
117 * touch: (coreutils)touch invocation.           Change file timestamps.
118 * tr: (coreutils)tr invocation.                 Translate characters.
119 * true: (coreutils)true invocation.             Do nothing, successfully.
120 * truncate: (coreutils)truncate invocation.     Shrink/extend size of a file.
121 * tsort: (coreutils)tsort invocation.           Topological sort.
122 * tty: (coreutils)tty invocation.               Print terminal name.
123 * uname: (coreutils)uname invocation.           Print system information.
124 * unexpand: (coreutils)unexpand invocation.     Convert spaces to tabs.
125 * uniq: (coreutils)uniq invocation.             Uniquify files.
126 * unlink: (coreutils)unlink invocation.         Removal via unlink(2).
127 * uptime: (coreutils)uptime invocation.         Print uptime and load.
128 * users: (coreutils)users invocation.           Print current user names.
129 * vdir: (coreutils)vdir invocation.             List directories verbosely.
130 * wc: (coreutils)wc invocation.                 Line, word, and byte counts.
131 * who: (coreutils)who invocation.               Print who is logged in.
132 * whoami: (coreutils)whoami invocation.         Print effective user ID.
133 * yes: (coreutils)yes invocation.               Print a string indefinitely.
134 @end direntry
136 @copying
137 This manual documents version @value{VERSION} of the @sc{gnu} core
138 utilities, including the standard programs for text and file manipulation.
140 Copyright @copyright{} 1994-1996, 2000-2009 Free Software Foundation, Inc.
142 @quotation
143 Permission is granted to copy, distribute and/or modify this document
144 under the terms of the GNU Free Documentation License, Version 1.3 or
145 any later version published by the Free Software Foundation; with no
146 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
147 Texts.  A copy of the license is included in the section entitled ``GNU
148 Free Documentation License''.
149 @end quotation
150 @end copying
152 @titlepage
153 @title @sc{gnu} @code{Coreutils}
154 @subtitle Core GNU utilities
155 @subtitle for version @value{VERSION}, @value{UPDATED}
156 @author David MacKenzie et al.
158 @page
159 @vskip 0pt plus 1filll
160 @insertcopying
161 @end titlepage
162 @shortcontents
163 @contents
165 @ifnottex
166 @node Top
167 @top GNU Coreutils
169 @insertcopying
170 @end ifnottex
172 @cindex core utilities
173 @cindex text utilities
174 @cindex shell utilities
175 @cindex file utilities
177 @menu
178 * Introduction::                       Caveats, overview, and authors.
179 * Common options::                     Common options.
180 * Output of entire files::             cat tac nl od
181 * Formatting file contents::           fmt pr fold
182 * Output of parts of files::           head tail split csplit
183 * Summarizing files::                  wc sum cksum md5sum sha1sum sha2
184 * Operating on sorted files::          sort shuf uniq comm ptx tsort
185 * Operating on fields within a line::  cut paste join
186 * Operating on characters::            tr expand unexpand
187 * Directory listing::                  ls dir vdir dircolors
188 * Basic operations::                   cp dd install mv rm shred
189 * Special file types::                 ln mkdir rmdir mkfifo mknod
190 * Changing file attributes::           chgrp chmod chown touch
191 * Disk usage::                         df du stat sync truncate
192 * Printing text::                      echo printf yes
193 * Conditions::                         false true test expr
194 * Redirection::                        tee
195 * File name manipulation::             dirname basename pathchk
196 * Working context::                    pwd stty printenv tty
197 * User information::                   id logname whoami groups users who
198 * System context::                     date uname hostname hostid uptime
199 * SELinux context::                    chcon runcon
200 * Modified command invocation::        chroot env nice nohup su timeout
201 * Process control::                    kill
202 * Delaying::                           sleep
203 * Numeric operations::                 factor seq
204 * File permissions::                   Access modes.
205 * Date input formats::                 Specifying date strings.
206 * Opening the software toolbox::       The software tools philosophy.
207 * GNU Free Documentation License::     Copying and sharing this manual.
208 * Concept index::                      General index.
210 @detailmenu
211  --- The Detailed Node Listing ---
213 Common Options
215 * Exit status::                 Indicating program success or failure.
216 * Backup options::              Backup options
217 * Block size::                  Block size
218 * Signal specifications::       Specifying signals
219 * Disambiguating names and IDs:: chgrp and chown owner and group syntax
220 * Random sources::              Sources of random data
221 * Target directory::            Target directory
222 * Trailing slashes::            Trailing slashes
223 * Traversing symlinks::         Traversing symlinks to directories
224 * Treating / specially::        Treating / specially
225 * Standards conformance::       Standards conformance
227 Output of entire files
229 * cat invocation::              Concatenate and write files.
230 * tac invocation::              Concatenate and write files in reverse.
231 * nl invocation::               Number lines and write files.
232 * od invocation::               Write files in octal or other formats.
233 * base64 invocation::           Transform data into printable data.
235 Formatting file contents
237 * fmt invocation::              Reformat paragraph text.
238 * pr invocation::               Paginate or columnate files for printing.
239 * fold invocation::             Wrap input lines to fit in specified width.
241 Output of parts of files
243 * head invocation::             Output the first part of files.
244 * tail invocation::             Output the last part of files.
245 * split invocation::            Split a file into fixed-size pieces.
246 * csplit invocation::           Split a file into context-determined pieces.
248 Summarizing files
250 * wc invocation::               Print newline, word, and byte counts.
251 * sum invocation::              Print checksum and block counts.
252 * cksum invocation::            Print CRC checksum and byte counts.
253 * md5sum invocation::           Print or check MD5 digests.
254 * sha1sum invocation::          Print or check SHA-1 digests.
255 * sha2 utilities::              Print or check SHA-2 digests.
257 Operating on sorted files
259 * sort invocation::             Sort text files.
260 * shuf invocation::             Shuffle text files.
261 * uniq invocation::             Uniquify files.
262 * comm invocation::             Compare two sorted files line by line.
263 * ptx invocation::              Produce a permuted index of file contents.
264 * tsort invocation::            Topological sort.
266 @command{ptx}: Produce permuted indexes
268 * General options in ptx::      Options which affect general program behavior.
269 * Charset selection in ptx::    Underlying character set considerations.
270 * Input processing in ptx::     Input fields, contexts, and keyword selection.
271 * Output formatting in ptx::    Types of output format, and sizing the fields.
272 * Compatibility in ptx::        The @acronym{GNU} extensions to @command{ptx}
274 Operating on fields within a line
276 * cut invocation::              Print selected parts of lines.
277 * paste invocation::            Merge lines of files.
278 * join invocation::             Join lines on a common field.
280 Operating on characters
282 * tr invocation::               Translate, squeeze, and/or delete characters.
283 * expand invocation::           Convert tabs to spaces.
284 * unexpand invocation::         Convert spaces to tabs.
286 @command{tr}: Translate, squeeze, and/or delete characters
288 * Character sets::              Specifying sets of characters.
289 * Translating::                 Changing one set of characters to another.
290 * Squeezing::                   Squeezing repeats and deleting.
292 Directory listing
294 * ls invocation::               List directory contents
295 * dir invocation::              Briefly list directory contents
296 * vdir invocation::             Verbosely list directory contents
297 * dircolors invocation::        Color setup for @command{ls}
299 @command{ls}:  List directory contents
301 * Which files are listed::      Which files are listed
302 * What information is listed::  What information is listed
303 * Sorting the output::          Sorting the output
304 * More details about version sort::  More details about version sort
305 * General output formatting::   General output formatting
306 * Formatting the file names::   Formatting the file names
308 Basic operations
310 * cp invocation::               Copy files and directories
311 * dd invocation::               Convert and copy a file
312 * install invocation::          Copy files and set attributes
313 * mv invocation::               Move (rename) files
314 * rm invocation::               Remove files or directories
315 * shred invocation::            Remove files more securely
317 Special file types
319 * link invocation::             Make a hard link via the link syscall
320 * ln invocation::               Make links between files
321 * mkdir invocation::            Make directories
322 * mkfifo invocation::           Make FIFOs (named pipes)
323 * mknod invocation::            Make block or character special files
324 * readlink invocation::         Print the referent of a symbolic link
325 * rmdir invocation::            Remove empty directories
326 * unlink invocation::           Remove files via unlink syscall
328 Changing file attributes
330 * chown invocation::            Change file owner and group
331 * chgrp invocation::            Change group ownership
332 * chmod invocation::            Change access permissions
333 * touch invocation::            Change file timestamps
335 Disk usage
337 * df invocation::               Report file system disk space usage
338 * du invocation::               Estimate file space usage
339 * stat invocation::             Report file or file system status
340 * sync invocation::             Synchronize data on disk with memory
341 * truncate invocation::         Shrink or extend the size of a file
343 Printing text
345 * echo invocation::             Print a line of text
346 * printf invocation::           Format and print data
347 * yes invocation::              Print a string until interrupted
349 Conditions
351 * false invocation::              Do nothing, unsuccessfully
352 * true invocation::               Do nothing, successfully
353 * test invocation::               Check file types and compare values
354 * expr invocation::               Evaluate expressions
356 @command{test}: Check file types and compare values
358 * File type tests::               File type tests
359 * Access permission tests::       Access permission tests
360 * File characteristic tests::     File characteristic tests
361 * String tests::                  String tests
362 * Numeric tests::                 Numeric tests
364 @command{expr}: Evaluate expression
366 * String expressions::         + : match substr index length
367 * Numeric expressions::        + - * / %
368 * Relations for expr::         | & < <= = == != >= >
369 * Examples of expr::           Examples of using @command{expr}
371 Redirection
373 * tee invocation::               Redirect output to multiple files or processes
375 File name manipulation
377 * basename invocation::          Strip directory and suffix from a file name
378 * dirname invocation::           Strip non-directory suffix from a file name
379 * pathchk invocation::           Check file name validity and portability
381 Working context
383 * pwd invocation::               Print working directory
384 * stty invocation::              Print or change terminal characteristics
385 * printenv invocation::          Print all or some environment variables
386 * tty invocation::               Print file name of terminal on standard input
388 @command{stty}: Print or change terminal characteristics
390 * Control::                     Control settings
391 * Input::                       Input settings
392 * Output::                      Output settings
393 * Local::                       Local settings
394 * Combination::                 Combination settings
395 * Characters::                  Special characters
396 * Special::                     Special settings
398 User information
400 * id invocation::                Print user identity
401 * logname invocation::           Print current login name
402 * whoami invocation::            Print effective user ID
403 * groups invocation::            Print group names a user is in
404 * users invocation::             Print login names of users currently logged in
405 * who invocation::               Print who is currently logged in
407 System context
409 * arch invocation::              Print machine hardware name
410 * date invocation::              Print or set system date and time
411 * uname invocation::             Print system information
412 * hostname invocation::          Print or set system name
413 * hostid invocation::            Print numeric host identifier
414 * uptime invocation::            Print system uptime and load
416 @command{date}: Print or set system date and time
418 * Time conversion specifiers::   %[HIklMNpPrRsSTXzZ]
419 * Date conversion specifiers::   %[aAbBcCdDeFgGhjmuUVwWxyY]
420 * Literal conversion specifiers:: %[%nt]
421 * Padding and other flags::      Pad with zeros, spaces, etc.
422 * Setting the time::             Changing the system clock.
423 * Options for date::             Instead of the current time.
424 * Date input formats::           Specifying date strings.
425 * Examples of date::             Examples.
427 SELinux context
428 * chcon invocation::             Change SELinux context of file
429 * runcon invocation::            Run a command in specified SELinux context
431 Modified command invocation
433 * chroot invocation::            Run a command with a different root directory
434 * env invocation::               Run a command in a modified environment
435 * nice invocation::              Run a command with modified niceness
436 * nohup invocation::             Run a command immune to hangups
437 * su invocation::                Run a command with substitute user and group ID
438 * timeout invocation::           Run a command with a time limit
440 Process control
442 * kill invocation::              Sending a signal to processes.
444 Delaying
446 * sleep invocation::             Delay for a specified time
448 Numeric operations
450 * factor invocation::            Print prime factors
451 * seq invocation::               Print numeric sequences
453 File permissions
455 * Mode Structure::               Structure of file mode bits.
456 * Symbolic Modes::               Mnemonic representation of file mode bits.
457 * Numeric Modes::                File mode bits as octal numbers.
458 * Directory Setuid and Setgid::  Set-user-ID and set-group-ID on directories.
460 Date input formats
462 * General date syntax::          Common rules.
463 * Calendar date items::          19 Dec 1994.
464 * Time of day items::            9:20pm.
465 * Time zone items::              @sc{est}, @sc{pdt}, @sc{gmt}.
466 * Day of week items::            Monday and others.
467 * Relative items in date strings:: next tuesday, 2 years ago.
468 * Pure numbers in date strings:: 19931219, 1440.
469 * Seconds since the Epoch::      @@1078100502.
470 * Specifying time zone rules::   TZ="America/New_York", TZ="UTC0".
471 * Authors of get_date::          Bellovin, Eggert, Salz, Berets, et al.
473 Opening the software toolbox
475 * Toolbox introduction::         Toolbox introduction
476 * I/O redirection::              I/O redirection
477 * The who command::              The @command{who} command
478 * The cut command::              The @command{cut} command
479 * The sort command::             The @command{sort} command
480 * The uniq command::             The @command{uniq} command
481 * Putting the tools together::   Putting the tools together
483 Copying This Manual
485 * GNU Free Documentation License::     Copying and sharing this manual.
487 @end detailmenu
488 @end menu
491 @node Introduction
492 @chapter Introduction
494 This manual is a work in progress: many sections make no attempt to explain
495 basic concepts in a way suitable for novices.  Thus, if you are interested,
496 please get involved in improving this manual.  The entire @sc{gnu} community
497 will benefit.
499 @cindex @acronym{POSIX}
500 The @sc{gnu} utilities documented here are mostly compatible with the
501 @acronym{POSIX} standard.
502 @cindex bugs, reporting
503 Please report bugs to @email{bug-coreutils@@gnu.org}.  Remember
504 to include the version number, machine architecture, input files, and
505 any other information needed to reproduce the bug: your input, what you
506 expected, what you got, and why it is wrong.  Diffs are welcome, but
507 please include a description of the problem as well, since this is
508 sometimes difficult to infer.  @xref{Bugs, , , gcc, Using and Porting GNU CC}.
510 @cindex Berry, K.
511 @cindex Paterson, R.
512 @cindex Stallman, R.
513 @cindex Pinard, F.
514 @cindex MacKenzie, D.
515 @cindex Meyering, J.
516 @cindex Youmans, B.
517 This manual was originally derived from the Unix man pages in the
518 distributions, which were written by David MacKenzie and updated by Jim
519 Meyering.  What you are reading now is the authoritative documentation
520 for these utilities; the man pages are no longer being maintained.  The
521 original @command{fmt} man page was written by Ross Paterson.  Fran@,{c}ois
522 Pinard did the initial conversion to Texinfo format.  Karl Berry did the
523 indexing, some reorganization, and editing of the results.  Brian
524 Youmans of the Free Software Foundation office staff combined the
525 manuals for textutils, fileutils, and sh-utils to produce the present
526 omnibus manual.  Richard Stallman contributed his usual invaluable
527 insights to the overall process.
529 @node Common options
530 @chapter Common options
532 @macro optBackup
533 @item -b
534 @itemx @w{@kbd{--backup}[=@var{method}]}
535 @opindex -b
536 @opindex --backup
537 @vindex VERSION_CONTROL
538 @cindex backups, making
539 @xref{Backup options}.
540 Make a backup of each file that would otherwise be overwritten or removed.
541 @end macro
543 @macro optBackupSuffix
544 @item -S @var{suffix}
545 @itemx --suffix=@var{suffix}
546 @opindex -S
547 @opindex --suffix
548 Append @var{suffix} to each backup file made with @option{-b}.
549 @xref{Backup options}.
550 @end macro
552 @macro optTargetDirectory
553 @item -t @var{directory}
554 @itemx @w{@kbd{--target-directory}=@var{directory}}
555 @opindex -t
556 @opindex --target-directory
557 @cindex target directory
558 @cindex destination directory
559 Specify the destination @var{directory}.
560 @xref{Target directory}.
561 @end macro
563 @macro optNoTargetDirectory
564 @item -T
565 @itemx --no-target-directory
566 @opindex -T
567 @opindex --no-target-directory
568 @cindex target directory
569 @cindex destination directory
570 Do not treat the last operand specially when it is a directory or a
571 symbolic link to a directory.  @xref{Target directory}.
572 @end macro
574 @macro optSi
575 @itemx --si
576 @opindex --si
577 @cindex SI output
578 Append an SI-style abbreviation to each size, such as @samp{M} for
579 megabytes.  Powers of 1000 are used, not 1024; @samp{M} stands for
580 1,000,000 bytes.  This option is equivalent to
581 @option{--block-size=si}.  Use the @option{-h} or
582 @option{--human-readable} option if
583 you prefer powers of 1024.
584 @end macro
586 @macro optHumanReadable
587 @item -h
588 @itemx --human-readable
589 @opindex -h
590 @opindex --human-readable
591 @cindex human-readable output
592 Append a size letter to each size, such as @samp{M} for mebibytes.
593 Powers of 1024 are used, not 1000; @samp{M} stands for 1,048,576 bytes.
594 This option is equivalent to @option{--block-size=human-readable}.
595 Use the @option{--si} option if you prefer powers of 1000.
596 @end macro
598 @macro optStripTrailingSlashes
599 @itemx @w{@kbd{--strip-trailing-slashes}}
600 @opindex --strip-trailing-slashes
601 @cindex stripping trailing slashes
602 Remove any trailing slashes from each @var{source} argument.
603 @xref{Trailing slashes}.
604 @end macro
606 @macro mayConflictWithShellBuiltIn{cmd}
607 @cindex conflicts with shell built-ins
608 @cindex built-in shell commands, conflicts with
609 Due to shell aliases and built-in @command{\cmd\} command, using an
610 unadorned @command{\cmd\} interactively or in a script may get you
611 different functionality than that described here.  Invoke it via
612 @command{env} (i.e., @code{env \cmd\ @dots{}}) to avoid interference
613 from the shell.
615 @end macro
617 @macro multiplierSuffixes{varName}
618 @ignore
619 Appending @samp{b} multiplies @var{\varName\} by 512,
620 @samp{kB} by 1000, @samp{K} by 1024,
621 @samp{MB} by 1000*1000, @samp{M} by 1024*1024,
622 @samp{GB} by 1000*1000*1000, @samp{G} by 1024*1024*1024,
623 and so on for @samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}.
624 @end ignore
625 @var{\varName\} is a number which may have one of the following
626 multiplicative suffixes:
627 @example
628 @samp{b}  =>            512 ("blocks")
629 @samp{KB} =>           1000 (KiloBytes)
630 @samp{K}  =>           1024 (KibiBytes)
631 @samp{MB} =>      1000*1000 (MegaBytes)
632 @samp{M}  =>      1024*1024 (MebiBytes)
633 @samp{GB} => 1000*1000*1000 (GigaBytes)
634 @samp{G}  => 1024*1024*1024 (GibiBytes)
635 @end example
636 and so on for @samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}.
637 @end macro
639 @c FIXME: same as above, but no ``blocks'' line.
640 @macro multiplierSuffixesNoBlocks{varName}
641 @var{\varName\} is a number which may have one of the following
642 multiplicative suffixes:
643 @example
644 @samp{KB} =>           1000 (KiloBytes)
645 @samp{K}  =>           1024 (KibiBytes)
646 @samp{MB} =>      1000*1000 (MegaBytes)
647 @samp{M}  =>      1024*1024 (MebiBytes)
648 @samp{GB} => 1000*1000*1000 (GigaBytes)
649 @samp{G}  => 1024*1024*1024 (GibiBytes)
650 @end example
651 and so on for @samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}.
652 @end macro
654 @cindex common options
656 Certain options are available in all of these programs.  Rather than
657 writing identical descriptions for each of the programs, they are
658 described here.  (In fact, every @sc{gnu} program accepts (or should accept)
659 these options.)
661 @vindex POSIXLY_CORRECT
662 Normally options and operands can appear in any order, and programs act
663 as if all the options appear before any operands.  For example,
664 @samp{sort -r passwd -t :} acts like @samp{sort -r -t : passwd}, since
665 @samp{:} is an option-argument of @option{-t}.  However, if the
666 @env{POSIXLY_CORRECT} environment variable is set, options must appear
667 before operands, unless otherwise specified for a particular command.
669 A few programs can usefully have trailing operands with leading
670 @samp{-}.  With such a program, options must precede operands even if
671 @env{POSIXLY_CORRECT} is not set, and this fact is noted in the
672 program description.  For example, the @command{env} command's options
673 must appear before its operands, since in some cases the operands
674 specify a command that itself contains options.
676 Most programs that accept long options recognize unambiguous
677 abbreviations of those options.  For example, @samp{rmdir
678 --ignore-fail-on-non-empty} can be invoked as @samp{rmdir
679 --ignore-fail} or even @samp{rmdir --i}.  Ambiguous options, such as
680 @samp{ls --h}, are identified as such.
682 Some of these programs recognize the @option{--help} and @option{--version}
683 options only when one of them is the sole command line argument.  For
684 these programs, abbreviations of the long options are not always recognized.
686 @table @samp
688 @item --help
689 @opindex --help
690 @cindex help, online
691 Print a usage message listing all available options, then exit successfully.
693 @item --version
694 @opindex --version
695 @cindex version number, finding
696 Print the version number, then exit successfully.
698 @item --
699 @opindex --
700 @cindex option delimiter
701 Delimit the option list.  Later arguments, if any, are treated as
702 operands even if they begin with @samp{-}.  For example, @samp{sort --
703 -r} reads from the file named @file{-r}.
705 @end table
707 @cindex standard input
708 @cindex standard output
709 A single @samp{-} operand is not really an option, though it looks like one.  It
710 stands for standard input, or for standard output if that is clear from
711 the context.  For example, @samp{sort -} reads from standard input,
712 and is equivalent to plain @samp{sort}, and @samp{tee -} writes an
713 extra copy of its input to standard output.  Unless otherwise
714 specified, @samp{-} can appear as any operand that requires a file
715 name.
717 @menu
718 * Exit status::                 Indicating program success or failure.
719 * Backup options::              -b -S, in some programs.
720 * Block size::                  BLOCK_SIZE and --block-size, in some programs.
721 * Signal specifications::       Specifying signals using the --signal option.
722 * Disambiguating names and IDs:: chgrp and chown owner and group syntax
723 * Random sources::              --random-source, in some programs.
724 * Target directory::            Specifying a target directory, in some programs.
725 * Trailing slashes::            --strip-trailing-slashes, in some programs.
726 * Traversing symlinks::         -H, -L, or -P, in some programs.
727 * Treating / specially::        --preserve-root and --no-preserve-root.
728 * Special built-in utilities::  @command{break}, @command{:}, @command{eval}, @dots{}
729 * Standards conformance::       Conformance to the @acronym{POSIX} standard.
730 @end menu
733 @node Exit status
734 @section Exit status
736 @macro exitstatus
737 An exit status of zero indicates success,
738 and a nonzero value indicates failure.
739 @end macro
741 Nearly every command invocation yields an integral @dfn{exit status}
742 that can be used to change how other commands work.
743 For the vast majority of commands, an exit status of zero indicates
744 success.  Failure is indicated by a nonzero value---typically
745 @samp{1}, though it may differ on unusual platforms as @acronym{POSIX}
746 requires only that it be nonzero.
748 However, some of the programs documented here do produce
749 other exit status values and a few associate different
750 meanings with the values @samp{0} and @samp{1}.
751 Here are some of the exceptions:
752 @command{chroot}, @command{env}, @command{expr},
753 @command{nice}, @command{nohup}, @command{printenv}, @command{sort},
754 @command{su}, @command{test}, @command{timeout}, @command{tty}.
757 @node Backup options
758 @section Backup options
760 @cindex backup options
762 Some @sc{gnu} programs (at least @command{cp}, @command{install},
763 @command{ln}, and @command{mv}) optionally make backups of files
764 before writing new versions.
765 These options control the details of these backups.  The options are also
766 briefly mentioned in the descriptions of the particular programs.
768 @table @samp
770 @item -b
771 @itemx @w{@kbd{--backup}[=@var{method}]}
772 @opindex -b
773 @opindex --backup
774 @vindex VERSION_CONTROL
775 @cindex backups, making
776 Make a backup of each file that would otherwise be overwritten or removed.
777 Without this option, the original versions are destroyed.
778 Use @var{method} to determine the type of backups to make.
779 When this option is used but @var{method} is not specified,
780 then the value of the @env{VERSION_CONTROL}
781 environment variable is used.  And if @env{VERSION_CONTROL} is not set,
782 the default backup type is @samp{existing}.
784 Note that the short form of this option, @option{-b} does not accept any
785 argument.  Using @option{-b} is equivalent to using @option{--backup=existing}.
787 @vindex version-control @r{Emacs variable}
788 This option corresponds to the Emacs variable @samp{version-control};
789 the values for @var{method} are the same as those used in Emacs.
790 This option also accepts more descriptive names.
791 The valid @var{method}s are (unique abbreviations are accepted):
793 @table @samp
794 @item none
795 @itemx off
796 @opindex none @r{backup method}
797 Never make backups.
799 @item numbered
800 @itemx t
801 @opindex numbered @r{backup method}
802 Always make numbered backups.
804 @item existing
805 @itemx nil
806 @opindex existing @r{backup method}
807 Make numbered backups of files that already have them, simple backups
808 of the others.
810 @item simple
811 @itemx never
812 @opindex simple @r{backup method}
813 Always make simple backups.  Please note @samp{never} is not to be
814 confused with @samp{none}.
816 @end table
818 @item -S @var{suffix}
819 @itemx --suffix=@var{suffix}
820 @opindex -S
821 @opindex --suffix
822 @cindex backup suffix
823 @vindex SIMPLE_BACKUP_SUFFIX
824 Append @var{suffix} to each backup file made with @option{-b}.  If this
825 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
826 environment variable is used.  And if @env{SIMPLE_BACKUP_SUFFIX} is not
827 set, the default is @samp{~}, just as in Emacs.
829 @end table
831 @node Block size
832 @section Block size
834 @cindex block size
836 Some @sc{gnu} programs (at least @command{df}, @command{du}, and
837 @command{ls}) display sizes in ``blocks''.  You can adjust the block size
838 and method of display to make sizes easier to read.  The block size
839 used for display is independent of any file system block size.
840 Fractional block counts are rounded up to the nearest integer.
842 @opindex --block-size=@var{size}
843 @vindex BLOCKSIZE
844 @vindex BLOCK_SIZE
845 @vindex DF_BLOCK_SIZE
846 @vindex DU_BLOCK_SIZE
847 @vindex LS_BLOCK_SIZE
848 @vindex POSIXLY_CORRECT@r{, and block size}
850 The default block size is chosen by examining the following environment
851 variables in turn; the first one that is set determines the block size.
853 @table @code
855 @item DF_BLOCK_SIZE
856 This specifies the default block size for the @command{df} command.
857 Similarly, @env{DU_BLOCK_SIZE} specifies the default for @command{du} and
858 @env{LS_BLOCK_SIZE} for @command{ls}.
860 @item BLOCK_SIZE
861 This specifies the default block size for all three commands, if the
862 above command-specific environment variables are not set.
864 @item BLOCKSIZE
865 This specifies the default block size for all values that are normally
866 printed as blocks, if neither @env{BLOCK_SIZE} nor the above
867 command-specific environment variables are set.  Unlike the other
868 environment variables, @env{BLOCKSIZE} does not affect values that are
869 normally printed as byte counts, e.g., the file sizes contained in
870 @code{ls -l} output.
872 @item POSIXLY_CORRECT
873 If neither @env{@var{command}_BLOCK_SIZE}, nor @env{BLOCK_SIZE}, nor
874 @env{BLOCKSIZE} is set, but this variable is set, the block size
875 defaults to 512.
877 @end table
879 If none of the above environment variables are set, the block size
880 currently defaults to 1024 bytes in most contexts, but this number may
881 change in the future.  For @command{ls} file sizes, the block size
882 defaults to 1 byte.
884 @cindex human-readable output
885 @cindex SI output
887 A block size specification can be a positive integer specifying the number
888 of bytes per block, or it can be @code{human-readable} or @code{si} to
889 select a human-readable format.  Integers may be followed by suffixes
890 that are upward compatible with the
891 @uref{http://www.bipm.fr/enus/3_SI/si-prefixes.html, SI prefixes}
892 for decimal multiples and with the
893 @uref{http://physics.nist.gov/cuu/Units/binary.html, IEC 60027-2
894 prefixes for binary multiples}.
896 With human-readable formats, output sizes are followed by a size letter
897 such as @samp{M} for megabytes.  @code{BLOCK_SIZE=human-readable} uses
898 powers of 1024; @samp{M} stands for 1,048,576 bytes.
899 @code{BLOCK_SIZE=si} is similar, but uses powers of 1000 and appends
900 @samp{B}; @samp{MB} stands for 1,000,000 bytes.
902 @vindex LC_NUMERIC
903 A block size specification preceded by @samp{'} causes output sizes to
904 be displayed with thousands separators.  The @env{LC_NUMERIC} locale
905 specifies the thousands separator and grouping.  For example, in an
906 American English locale, @samp{--block-size="'1kB"} would cause a size
907 of 1234000 bytes to be displayed as @samp{1,234}.  In the default C
908 locale, there is no thousands separator so a leading @samp{'} has no
909 effect.
911 An integer block size can be followed by a suffix to specify a
912 multiple of that size.  A bare size letter,
913 or one followed by @samp{iB}, specifies
914 a multiple using powers of 1024.  A size letter followed by @samp{B}
915 specifies powers of 1000 instead.  For example, @samp{1M} and
916 @samp{1MiB} are equivalent to @samp{1048576}, whereas @samp{1MB} is
917 equivalent to @samp{1000000}.
919 A plain suffix without a preceding integer acts as if @samp{1} were
920 prepended, except that it causes a size indication to be appended to
921 the output.  For example, @samp{--block-size="kB"} displays 3000 as
922 @samp{3kB}.
924 The following suffixes are defined.  Large sizes like @code{1Y}
925 may be rejected by your computer due to limitations of its arithmetic.
927 @table @samp
928 @item kB
929 @cindex kilobyte, definition of
930 kilobyte: @math{10^3 = 1000}.
931 @item k
932 @itemx K
933 @itemx KiB
934 @cindex kibibyte, definition of
935 kibibyte: @math{2^{10} = 1024}.  @samp{K} is special: the SI prefix is
936 @samp{k} and the IEC 60027-2 prefix is @samp{Ki}, but tradition and
937 @acronym{POSIX} use @samp{k} to mean @samp{KiB}.
938 @item MB
939 @cindex megabyte, definition of
940 megabyte: @math{10^6 = 1,000,000}.
941 @item M
942 @itemx MiB
943 @cindex mebibyte, definition of
944 mebibyte: @math{2^{20} = 1,048,576}.
945 @item GB
946 @cindex gigabyte, definition of
947 gigabyte: @math{10^9 = 1,000,000,000}.
948 @item G
949 @itemx GiB
950 @cindex gibibyte, definition of
951 gibibyte: @math{2^{30} = 1,073,741,824}.
952 @item TB
953 @cindex terabyte, definition of
954 terabyte:  @math{10^{12} = 1,000,000,000,000}.
955 @item T
956 @itemx TiB
957 @cindex tebibyte, definition of
958 tebibyte: @math{2^{40} = 1,099,511,627,776}.
959 @item PB
960 @cindex petabyte, definition of
961 petabyte: @math{10^{15} = 1,000,000,000,000,000}.
962 @item P
963 @itemx PiB
964 @cindex pebibyte, definition of
965 pebibyte: @math{2^{50} = 1,125,899,906,842,624}.
966 @item EB
967 @cindex exabyte, definition of
968 exabyte: @math{10^{18} = 1,000,000,000,000,000,000}.
969 @item E
970 @itemx EiB
971 @cindex exbibyte, definition of
972 exbibyte: @math{2^{60} = 1,152,921,504,606,846,976}.
973 @item ZB
974 @cindex zettabyte, definition of
975 zettabyte: @math{10^{21} = 1,000,000,000,000,000,000,000}
976 @item Z
977 @itemx ZiB
978 @math{2^{70} = 1,180,591,620,717,411,303,424}.
979 (@samp{Zi} is a @acronym{GNU} extension to IEC 60027-2.)
980 @item YB
981 @cindex yottabyte, definition of
982 yottabyte: @math{10^{24} = 1,000,000,000,000,000,000,000,000}.
983 @item Y
984 @itemx YiB
985 @math{2^{80} = 1,208,925,819,614,629,174,706,176}.
986 (@samp{Yi} is a @acronym{GNU} extension to IEC 60027-2.)
987 @end table
989 @opindex -k
990 @opindex -h
991 @opindex --block-size
992 @opindex --human-readable
993 @opindex --si
995 Block size defaults can be overridden by an explicit
996 @option{--block-size=@var{size}} option.  The @option{-k}
997 option is equivalent to @option{--block-size=1K}, which
998 is the default unless the @env{POSIXLY_CORRECT} environment variable is
999 set.  The @option{-h} or @option{--human-readable} option is equivalent to
1000 @option{--block-size=human-readable}.  The @option{--si} option is
1001 equivalent to @option{--block-size=si}.
1003 @node Signal specifications
1004 @section Signal specifications
1005 @cindex signals, specifying
1007 A @var{signal} may be a signal name like @samp{HUP}, or a signal
1008 number like @samp{1}, or an exit status of a process terminated by the
1009 signal.  A signal name can be given in canonical form or prefixed by
1010 @samp{SIG}.  The case of the letters is ignored. The following signal names
1011 and numbers are supported on all @acronym{POSIX} compliant systems:
1013 @table @samp
1014 @item HUP
1015 1.  Hangup.
1016 @item INT
1017 2.  Terminal interrupt.
1018 @item QUIT
1019 3.  Terminal quit.
1020 @item ABRT
1021 6.  Process abort.
1022 @item KILL
1023 9.  Kill (cannot be caught or ignored).
1024 @item ALRM
1025 14.  Alarm Clock.
1026 @item TERM
1027 15.  Termination.
1028 @end table
1030 @noindent
1031 Other supported signal names have system-dependent corresponding
1032 numbers.  All systems conforming to @acronym{POSIX} 1003.1-2001 also
1033 support the following signals:
1035 @table @samp
1036 @item BUS
1037 Access to an undefined portion of a memory object.
1038 @item CHLD
1039 Child process terminated, stopped, or continued.
1040 @item CONT
1041 Continue executing, if stopped.
1042 @item FPE
1043 Erroneous arithmetic operation.
1044 @item ILL
1045 Illegal Instruction.
1046 @item PIPE
1047 Write on a pipe with no one to read it.
1048 @item SEGV
1049 Invalid memory reference.
1050 @item STOP
1051 Stop executing (cannot be caught or ignored).
1052 @item TSTP
1053 Terminal stop.
1054 @item TTIN
1055 Background process attempting read.
1056 @item TTOU
1057 Background process attempting write.
1058 @item URG
1059 High bandwidth data is available at a socket.
1060 @item USR1
1061 User-defined signal 1.
1062 @item USR2
1063 User-defined signal 2.
1064 @end table
1066 @noindent
1067 @acronym{POSIX} 1003.1-2001 systems that support the @acronym{XSI} extension
1068 also support the following signals:
1070 @table @samp
1071 @item POLL
1072 Pollable event.
1073 @item PROF
1074 Profiling timer expired.
1075 @item SYS
1076 Bad system call.
1077 @item TRAP
1078 Trace/breakpoint trap.
1079 @item VTALRM
1080 Virtual timer expired.
1081 @item XCPU
1082 CPU time limit exceeded.
1083 @item XFSZ
1084 File size limit exceeded.
1085 @end table
1087 @noindent
1088 @acronym{POSIX} 1003.1-2001 systems that support the @acronym{XRT} extension
1089 also support at least eight real-time signals called @samp{RTMIN},
1090 @samp{RTMIN+1}, @dots{}, @samp{RTMAX-1}, @samp{RTMAX}.
1092 @node Disambiguating names and IDs
1093 @section chown and chgrp: Disambiguating user names and IDs
1094 @cindex user names, disambiguating
1095 @cindex user IDs, disambiguating
1096 @cindex group names, disambiguating
1097 @cindex group IDs, disambiguating
1098 @cindex disambiguating group names and IDs
1100 Since the @var{owner} and @var{group} arguments to @command{chown} and
1101 @command{chgrp} may be specified as names or numeric IDs, there is an
1102 apparent ambiguity.
1103 What if a user or group @emph{name} is a string of digits?
1104 @footnote{Using a number as a user name is common in some environments.}
1105 Should the command interpret it as a user name or as an ID?
1106 @acronym{POSIX} requires that @command{chown} and @command{chgrp}
1107 first attempt to resolve the specified string as a name, and
1108 only once that fails, then try to interpret it as an ID.
1109 This is troublesome when you want to specify a numeric ID, say 42,
1110 and it must work even in a pathological situation where
1111 @samp{42} is a user name that maps to some other user ID, say 1000.
1112 Simply invoking @code{chown 42 F}, will set @file{F}s owner ID to
1113 1000---not what you intended.
1115 GNU @command{chown} and @command{chgrp} provide a way to work around this,
1116 that at the same time may result in a significant performance improvement
1117 by eliminating a database look-up.
1118 Simply precede each numeric user ID and/or group ID with a @samp{+},
1119 in order to force its interpretation as an integer:
1121 @example
1122 chown +42 F
1123 chgrp +$numeric_group_id another-file
1124 chown +0:+0 /
1125 @end example
1127 GNU @command{chown} and @command{chgrp}
1128 skip the name look-up process for each @samp{+}-prefixed string,
1129 because a string containing @samp{+} is never a valid user or group name.
1130 This syntax is accepted on most common Unix systems, but not on Solaris 10.
1132 @node Random sources
1133 @section Sources of random data
1135 @cindex random sources
1137 The @command{shuf}, @command{shred}, and @command{sort} commands
1138 sometimes need random data to do their work.  For example, @samp{sort
1139 -R} must choose a hash function at random, and it needs random data to
1140 make this selection.
1142 Normally these commands use the device file @file{/dev/urandom} as the
1143 source of random data.  Typically, this device gathers environmental
1144 noise from device drivers and other sources into an entropy pool, and
1145 uses the pool to generate random bits.  If the pool is short of data,
1146 the device reuses the internal pool to produce more bits, using a
1147 cryptographically secure pseudorandom number generator.
1149 @file{/dev/urandom} suffices for most practical uses, but applications
1150 requiring high-value or long-term protection of private data may
1151 require an alternate data source like @file{/dev/random} or
1152 @file{/dev/arandom}.  The set of available sources depends on your
1153 operating system.
1155 To use such a source, specify the @option{--random-source=@var{file}}
1156 option, e.g., @samp{shuf --random-source=/dev/random}.  The contents
1157 of @var{file} should be as random as possible.  An error is reported
1158 if @var{file} does not contain enough bytes to randomize the input
1159 adequately.
1161 To reproduce the results of an earlier invocation of a command, you
1162 can save some random data into a file and then use that file as the
1163 random source in earlier and later invocations of the command.
1165 Some old-fashioned or stripped-down operating systems lack support for
1166 @command{/dev/urandom}.  On these systems commands like @command{shuf}
1167 by default fall back on an internal pseudorandom generator initialized
1168 by a small amount of entropy.
1170 @node Target directory
1171 @section Target directory
1173 @cindex target directory
1175 The @command{cp}, @command{install}, @command{ln}, and @command{mv}
1176 commands normally treat the last operand specially when it is a
1177 directory or a symbolic link to a directory.  For example, @samp{cp
1178 source dest} is equivalent to @samp{cp source dest/source} if
1179 @file{dest} is a directory.  Sometimes this behavior is not exactly
1180 what is wanted, so these commands support the following options to
1181 allow more fine-grained control:
1183 @table @samp
1185 @item -T
1186 @itemx --no-target-directory
1187 @opindex --no-target-directory
1188 @cindex target directory
1189 @cindex destination directory
1190 Do not treat the last operand specially when it is a directory or a
1191 symbolic link to a directory.  This can help avoid race conditions in
1192 programs that operate in a shared area.  For example, when the command
1193 @samp{mv /tmp/source /tmp/dest} succeeds, there is no guarantee that
1194 @file{/tmp/source} was renamed to @file{/tmp/dest}: it could have been
1195 renamed to @file{/tmp/dest/source} instead, if some other process
1196 created @file{/tmp/dest} as a directory.  However, if @file{mv
1197 -T /tmp/source /tmp/dest} succeeds, there is no
1198 question that @file{/tmp/source} was renamed to @file{/tmp/dest}.
1200 In the opposite situation, where you want the last operand to be
1201 treated as a directory and want a diagnostic otherwise, you can use
1202 the @option{--target-directory} (@option{-t}) option.
1204 @item -t @var{directory}
1205 @itemx @w{@kbd{--target-directory}=@var{directory}}
1206 @opindex --target-directory
1207 @cindex target directory
1208 @cindex destination directory
1209 Use @var{directory} as the directory component of each destination
1210 file name.
1212 The interface for most programs is that after processing options and a
1213 finite (possibly zero) number of fixed-position arguments, the remaining
1214 argument list is either expected to be empty, or is a list of items
1215 (usually files) that will all be handled identically.  The @command{xargs}
1216 program is designed to work well with this convention.
1218 The commands in the @command{mv}-family are unusual in that they take
1219 a variable number of arguments with a special case at the @emph{end}
1220 (namely, the target directory).  This makes it nontrivial to perform some
1221 operations, e.g., ``move all files from here to ../d/'', because
1222 @code{mv * ../d/} might exhaust the argument space, and @code{ls | xargs ...}
1223 doesn't have a clean way to specify an extra final argument for each
1224 invocation of the subject command.  (It can be done by going through a
1225 shell command, but that requires more human labor and brain power than
1226 it should.)
1228 The @w{@kbd{--target-directory}} (@option{-t}) option allows the @command{cp},
1229 @command{install}, @command{ln}, and @command{mv} programs to be used
1230 conveniently with @command{xargs}.  For example, you can move the files
1231 from the current directory to a sibling directory, @code{d} like this:
1233 @smallexample
1234 ls | xargs mv -t ../d --
1235 @end smallexample
1237 However, this doesn't move files whose names begin with @samp{.}.
1238 If you use the @sc{gnu} @command{find} program, you can move those
1239 files too, with this command:
1241 @example
1242 find . -mindepth 1 -maxdepth 1 \
1243   | xargs mv -t ../d
1244 @end example
1246 But both of the above approaches fail if there are no files in the
1247 current directory, or if any file has a name containing a blank or
1248 some other special characters.
1249 The following example removes those limitations and requires both
1250 @sc{gnu} @command{find} and @sc{gnu} @command{xargs}:
1252 @example
1253 find . -mindepth 1 -maxdepth 1 -print0 \
1254   | xargs --null --no-run-if-empty \
1255       mv -t ../d
1256 @end example
1258 @end table
1260 @noindent
1261 The @option{--target-directory} (@option{-t}) and
1262 @option{--no-target-directory} (@option{-T})
1263 options cannot be combined.
1265 @node Trailing slashes
1266 @section Trailing slashes
1268 @cindex trailing slashes
1270 Some @sc{gnu} programs (at least @command{cp} and @command{mv}) allow you to
1271 remove any trailing slashes from each @var{source} argument before
1272 operating on it.  The @w{@kbd{--strip-trailing-slashes}} option enables
1273 this behavior.
1275 This is useful when a @var{source} argument may have a trailing slash and
1276 @c FIXME: mv's behavior in this case is system-dependent
1277 specify a symbolic link to a directory.  This scenario is in fact rather
1278 common because some shells can automatically append a trailing slash when
1279 performing file name completion on such symbolic links.  Without this
1280 option, @command{mv}, for example, (via the system's rename function) must
1281 interpret a trailing slash as a request to dereference the symbolic link
1282 and so must rename the indirectly referenced @emph{directory} and not
1283 the symbolic link.  Although it may seem surprising that such behavior
1284 be the default, it is required by @acronym{POSIX} and is consistent with
1285 other parts of that standard.
1287 @node Traversing symlinks
1288 @section Traversing symlinks
1290 @cindex symbolic link to directory, controlling traversal of
1292 The following options modify how @command{chown} and @command{chgrp}
1293 @c FIXME: note that `du' has these options, too, but they have slightly
1294 @c different meaning.
1295 traverse a hierarchy when the @option{--recursive} (@option{-R})
1296 option is also specified.
1297 If more than one of the following options is specified, only the final
1298 one takes effect.
1299 These options specify whether processing a symbolic link to a directory
1300 entails operating on just the symbolic link or on all files in the
1301 hierarchy rooted at that directory.
1303 These options are independent of @option{--dereference} and
1304 @option{--no-dereference} (@option{-h}), which control whether to modify
1305 a symlink or its referent.
1307 @table @samp
1309 @macro choptH
1310 @item -H
1311 @opindex -H
1312 @cindex symbolic link to directory, traverse each that is specified on the command line
1313 If @option{--recursive} (@option{-R}) is specified and
1314 a command line argument is a symbolic link to a directory, traverse it.
1315 @end macro
1316 @choptH
1318 @macro choptL
1319 @item -L
1320 @opindex -L
1321 @cindex symbolic link to directory, traverse each that is encountered
1322 In a recursive traversal, traverse every symbolic link to a directory
1323 that is encountered.
1324 @end macro
1325 @choptL
1327 @macro choptP
1328 @item -P
1329 @opindex -P
1330 @cindex symbolic link to directory, never traverse
1331 Do not traverse any symbolic links.
1332 This is the default if none of @option{-H}, @option{-L},
1333 or @option{-P} is specified.
1334 @end macro
1335 @choptP
1337 @end table
1340 @node Treating / specially
1341 @section Treating @file{/} specially
1343 Certain commands can operate destructively on entire hierarchies.
1344 For example, if a user with appropriate privileges mistakenly runs
1345 @samp{rm -rf / tmp/junk}, that may remove
1346 all files on the entire system.  Since there are so few
1347 legitimate uses for such a command,
1348 @sc{gnu} @command{rm} normally declines to operate on any directory
1349 that resolves to @file{/}.  If you really want to try to remove all
1350 the files on your system, you can use the @option{--no-preserve-root}
1351 option, but the default behavior, specified by the
1352 @option{--preserve-option}, is safer for most purposes.
1354 The commands @command{chgrp}, @command{chmod} and @command{chown}
1355 can also operate destructively on entire hierarchies, so they too
1356 support these options.  Although, unlike @command{rm}, they don't
1357 actually unlink files, these commands are arguably more dangerous
1358 when operating recursively on @file{/}, since they often work much
1359 more quickly, and hence damage more files before an alert user can
1360 interrupt them.  Tradition and @acronym{POSIX} require these commands
1361 to operate recursively on @file{/}, so they default to
1362 @option{--no-preserve-root}, but using the @option{--preserve-root}
1363 option makes them safer for most purposes.  For convenience you can
1364 specify @option{--preserve-root} in an alias or in a shell function.
1366 Note that the @option{--preserve-root} option also ensures
1367 that @command{chgrp} and @command{chown} do not modify @file{/}
1368 even when dereferencing a symlink pointing to @file{/}.
1370 @node Special built-in utilities
1371 @section Special built-in utilities
1373 Some programs like @command{nice} can invoke other programs; for
1374 example, the command @samp{nice cat file} invokes the program
1375 @command{cat} by executing the command @samp{cat file}.  However,
1376 @dfn{special built-in utilities} like @command{exit} cannot be invoked
1377 this way.  For example, the command @samp{nice exit} does not have a
1378 well-defined behavior: it may generate an error message instead of
1379 exiting.
1381 Here is a list of the special built-in utilities that are standardized
1382 by @acronym{POSIX} 1003.1-2004.
1384 @quotation
1385 @t{.@: : break continue eval exec exit export readonly
1386 return set shift times trap unset}
1387 @end quotation
1389 For example, because @samp{.}, @samp{:}, and @samp{exec} are special,
1390 the commands @samp{nice . foo.sh}, @samp{nice :}, and @samp{nice exec
1391 pwd} do not work as you might expect.
1393 Many shells extend this list.  For example, Bash has several extra
1394 special built-in utilities like @command{history}, and
1395 @command{suspend}, and with Bash the command @samp{nice suspend}
1396 generates an error message instead of suspending.
1398 @node Standards conformance
1399 @section Standards conformance
1401 @vindex POSIXLY_CORRECT
1402 In a few cases, the @sc{gnu} utilities' default behavior is
1403 incompatible with the @acronym{POSIX} standard.  To suppress these
1404 incompatibilities, define the @env{POSIXLY_CORRECT} environment
1405 variable.  Unless you are checking for @acronym{POSIX} conformance, you
1406 probably do not need to define @env{POSIXLY_CORRECT}.
1408 Newer versions of @acronym{POSIX} are occasionally incompatible with older
1409 versions.  For example, older versions of @acronym{POSIX} required the
1410 command @samp{sort +1} to sort based on the second and succeeding
1411 fields in each input line, but starting with @acronym{POSIX} 1003.1-2001
1412 the same command is required to sort the file named @file{+1}, and you
1413 must instead use the command @samp{sort -k 2} to get the field-based
1414 sort.
1416 @vindex _POSIX2_VERSION
1417 The @sc{gnu} utilities normally conform to the version of @acronym{POSIX}
1418 that is standard for your system.  To cause them to conform to a
1419 different version of @acronym{POSIX}, define the @env{_POSIX2_VERSION}
1420 environment variable to a value of the form @var{yyyymm} specifying
1421 the year and month the standard was adopted.  Two values are currently
1422 supported for @env{_POSIX2_VERSION}: @samp{199209} stands for
1423 @acronym{POSIX} 1003.2-1992, and @samp{200112} stands for @acronym{POSIX}
1424 1003.1-2001.  For example, if you have a newer system but are running software
1425 that assumes an older version of @acronym{POSIX} and uses @samp{sort +1}
1426 or @samp{tail +10}, you can work around any compatibility problems by setting
1427 @samp{_POSIX2_VERSION=199209} in your environment.
1429 @node Output of entire files
1430 @chapter Output of entire files
1432 @cindex output of entire files
1433 @cindex entire files, output of
1435 These commands read and write entire files, possibly transforming them
1436 in some way.
1438 @menu
1439 * cat invocation::              Concatenate and write files.
1440 * tac invocation::              Concatenate and write files in reverse.
1441 * nl invocation::               Number lines and write files.
1442 * od invocation::               Write files in octal or other formats.
1443 * base64 invocation::           Transform data into printable data.
1444 @end menu
1446 @node cat invocation
1447 @section @command{cat}: Concatenate and write files
1449 @pindex cat
1450 @cindex concatenate and write files
1451 @cindex copying files
1453 @command{cat} copies each @var{file} (@samp{-} means standard input), or
1454 standard input if none are given, to standard output.  Synopsis:
1456 @example
1457 cat [@var{option}] [@var{file}]@dots{}
1458 @end example
1460 The program accepts the following options.  Also see @ref{Common options}.
1462 @table @samp
1464 @item -A
1465 @itemx --show-all
1466 @opindex -A
1467 @opindex --show-all
1468 Equivalent to @option{-vET}.
1470 @item -b
1471 @itemx --number-nonblank
1472 @opindex -b
1473 @opindex --number-nonblank
1474 Number all nonempty output lines, starting with 1.
1476 @item -e
1477 @opindex -e
1478 Equivalent to @option{-vE}.
1480 @item -E
1481 @itemx --show-ends
1482 @opindex -E
1483 @opindex --show-ends
1484 Display a @samp{$} after the end of each line.
1486 @item -n
1487 @itemx --number
1488 @opindex -n
1489 @opindex --number
1490 Number all output lines, starting with 1.
1492 @item -s
1493 @itemx --squeeze-blank
1494 @opindex -s
1495 @opindex --squeeze-blank
1496 @cindex squeezing empty lines
1497 Suppress repeated adjacent empty lines; output just one empty line
1498 instead of several.
1500 @item -t
1501 @opindex -t
1502 Equivalent to @option{-vT}.
1504 @item -T
1505 @itemx --show-tabs
1506 @opindex -T
1507 @opindex --show-tabs
1508 Display TAB characters as @samp{^I}.
1510 @item -u
1511 @opindex -u
1512 Ignored; for @acronym{POSIX} compatibility.
1514 @item -v
1515 @itemx --show-nonprinting
1516 @opindex -v
1517 @opindex --show-nonprinting
1518 Display control characters except for LFD and TAB using
1519 @samp{^} notation and precede characters that have the high bit set with
1520 @samp{M-}.
1522 @end table
1524 On systems like MS-DOS that distinguish between text and binary files,
1525 @command{cat} normally reads and writes in binary mode.  However,
1526 @command{cat} reads in text mode if one of the options
1527 @option{-bensAE} is used or if @command{cat} is reading from standard
1528 input and standard input is a terminal.  Similarly, @command{cat}
1529 writes in text mode if one of the options @option{-bensAE} is used or
1530 if standard output is a terminal.
1532 @exitstatus
1534 Examples:
1536 @smallexample
1537 # Output f's contents, then standard input, then g's contents.
1538 cat f - g
1540 # Copy standard input to standard output.
1542 @end smallexample
1545 @node tac invocation
1546 @section @command{tac}: Concatenate and write files in reverse
1548 @pindex tac
1549 @cindex reversing files
1551 @command{tac} copies each @var{file} (@samp{-} means standard input), or
1552 standard input if none are given, to standard output, reversing the
1553 records (lines by default) in each separately.  Synopsis:
1555 @example
1556 tac [@var{option}]@dots{} [@var{file}]@dots{}
1557 @end example
1559 @dfn{Records} are separated by instances of a string (newline by
1560 default).  By default, this separator string is attached to the end of
1561 the record that it follows in the file.
1563 The program accepts the following options.  Also see @ref{Common options}.
1565 @table @samp
1567 @item -b
1568 @itemx --before
1569 @opindex -b
1570 @opindex --before
1571 The separator is attached to the beginning of the record that it
1572 precedes in the file.
1574 @item -r
1575 @itemx --regex
1576 @opindex -r
1577 @opindex --regex
1578 Treat the separator string as a regular expression.  Users of @command{tac}
1579 on MS-DOS/MS-Windows should note that, since @command{tac} reads files in
1580 binary mode, each line of a text file might end with a CR/LF pair
1581 instead of the Unix-style LF.
1583 @item -s @var{separator}
1584 @itemx --separator=@var{separator}
1585 @opindex -s
1586 @opindex --separator
1587 Use @var{separator} as the record separator, instead of newline.
1589 @end table
1591 @exitstatus
1594 @node nl invocation
1595 @section @command{nl}: Number lines and write files
1597 @pindex nl
1598 @cindex numbering lines
1599 @cindex line numbering
1601 @command{nl} writes each @var{file} (@samp{-} means standard input), or
1602 standard input if none are given, to standard output, with line numbers
1603 added to some or all of the lines.  Synopsis:
1605 @example
1606 nl [@var{option}]@dots{} [@var{file}]@dots{}
1607 @end example
1609 @cindex logical pages, numbering on
1610 @command{nl} decomposes its input into (logical) pages; by default, the
1611 line number is reset to 1 at the top of each logical page.  @command{nl}
1612 treats all of the input files as a single document; it does not reset
1613 line numbers or logical pages between files.
1615 @cindex headers, numbering
1616 @cindex body, numbering
1617 @cindex footers, numbering
1618 A logical page consists of three sections: header, body, and footer.
1619 Any of the sections can be empty.  Each can be numbered in a different
1620 style from the others.
1622 The beginnings of the sections of logical pages are indicated in the
1623 input file by a line containing exactly one of these delimiter strings:
1625 @table @samp
1626 @item \:\:\:
1627 start of header;
1628 @item \:\:
1629 start of body;
1630 @item \:
1631 start of footer.
1632 @end table
1634 The two characters from which these strings are made can be changed from
1635 @samp{\} and @samp{:} via options (see below), but the pattern and
1636 length of each string cannot be changed.
1638 A section delimiter is replaced by an empty line on output.  Any text
1639 that comes before the first section delimiter string in the input file
1640 is considered to be part of a body section, so @command{nl} treats a
1641 file that contains no section delimiters as a single body section.
1643 The program accepts the following options.  Also see @ref{Common options}.
1645 @table @samp
1647 @item -b @var{style}
1648 @itemx --body-numbering=@var{style}
1649 @opindex -b
1650 @opindex --body-numbering
1651 Select the numbering style for lines in the body section of each
1652 logical page.  When a line is not numbered, the current line number
1653 is not incremented, but the line number separator character is still
1654 prepended to the line.  The styles are:
1656 @table @samp
1657 @item a
1658 number all lines,
1659 @item t
1660 number only nonempty lines (default for body),
1661 @item n
1662 do not number lines (default for header and footer),
1663 @item p@var{bre}
1664 number only lines that contain a match for the basic regular
1665 expression @var{bre}.
1666 @xref{Regular Expressions, , Regular Expressions, grep, The GNU Grep Manual}.
1667 @end table
1669 @item -d @var{cd}
1670 @itemx --section-delimiter=@var{cd}
1671 @opindex -d
1672 @opindex --section-delimiter
1673 @cindex section delimiters of pages
1674 Set the section delimiter characters to @var{cd}; default is
1675 @samp{\:}.  If only @var{c} is given, the second remains @samp{:}.
1676 (Remember to protect @samp{\} or other metacharacters from shell
1677 expansion with quotes or extra backslashes.)
1679 @item -f @var{style}
1680 @itemx --footer-numbering=@var{style}
1681 @opindex -f
1682 @opindex --footer-numbering
1683 Analogous to @option{--body-numbering}.
1685 @item -h @var{style}
1686 @itemx --header-numbering=@var{style}
1687 @opindex -h
1688 @opindex --header-numbering
1689 Analogous to @option{--body-numbering}.
1691 @item -i @var{number}
1692 @itemx --page-increment=@var{number}
1693 @opindex -i
1694 @opindex --page-increment
1695 Increment line numbers by @var{number} (default 1).
1697 @item -l @var{number}
1698 @itemx --join-blank-lines=@var{number}
1699 @opindex -l
1700 @opindex --join-blank-lines
1701 @cindex empty lines, numbering
1702 @cindex blank lines, numbering
1703 Consider @var{number} (default 1) consecutive empty lines to be one
1704 logical line for numbering, and only number the last one.  Where fewer
1705 than @var{number} consecutive empty lines occur, do not number them.
1706 An empty line is one that contains no characters, not even spaces
1707 or tabs.
1709 @item -n @var{format}
1710 @itemx --number-format=@var{format}
1711 @opindex -n
1712 @opindex --number-format
1713 Select the line numbering format (default is @code{rn}):
1715 @table @samp
1716 @item ln
1717 @opindex ln @r{format for @command{nl}}
1718 left justified, no leading zeros;
1719 @item rn
1720 @opindex rn @r{format for @command{nl}}
1721 right justified, no leading zeros;
1722 @item rz
1723 @opindex rz @r{format for @command{nl}}
1724 right justified, leading zeros.
1725 @end table
1727 @item -p
1728 @itemx --no-renumber
1729 @opindex -p
1730 @opindex --no-renumber
1731 Do not reset the line number at the start of a logical page.
1733 @item -s @var{string}
1734 @itemx --number-separator=@var{string}
1735 @opindex -s
1736 @opindex --number-separator
1737 Separate the line number from the text line in the output with
1738 @var{string} (default is the TAB character).
1740 @item -v @var{number}
1741 @itemx --starting-line-number=@var{number}
1742 @opindex -v
1743 @opindex --starting-line-number
1744 Set the initial line number on each logical page to @var{number} (default 1).
1746 @item -w @var{number}
1747 @itemx --number-width=@var{number}
1748 @opindex -w
1749 @opindex --number-width
1750 Use @var{number} characters for line numbers (default 6).
1752 @end table
1754 @exitstatus
1757 @node od invocation
1758 @section @command{od}: Write files in octal or other formats
1760 @pindex od
1761 @cindex octal dump of files
1762 @cindex hex dump of files
1763 @cindex ASCII dump of files
1764 @cindex file contents, dumping unambiguously
1766 @command{od} writes an unambiguous representation of each @var{file}
1767 (@samp{-} means standard input), or standard input if none are given.
1768 Synopses:
1770 @smallexample
1771 od [@var{option}]@dots{} [@var{file}]@dots{}
1772 od [-abcdfilosx]@dots{} [@var{file}] [[+]@var{offset}[.][b]]
1773 od [@var{option}]@dots{} --traditional [@var{file}] [[+]@var{offset}[.][b] [[+]@var{label}[.][b]]]
1774 @end smallexample
1776 Each line of output consists of the offset in the input, followed by
1777 groups of data from the file.  By default, @command{od} prints the offset in
1778 octal, and each group of file data is a C @code{short int}'s worth of input
1779 printed as a single octal number.
1781 If @var{offset} is given, it specifies how many input bytes to skip
1782 before formatting and writing.  By default, it is interpreted as an
1783 octal number, but the optional trailing decimal point causes it to be
1784 interpreted as decimal.  If no decimal is specified and the offset
1785 begins with @samp{0x} or @samp{0X} it is interpreted as a hexadecimal
1786 number.  If there is a trailing @samp{b}, the number of bytes skipped
1787 will be @var{offset} multiplied by 512.
1789 If a command is of both the first and second forms, the second form is
1790 assumed if the last operand begins with @samp{+} or (if there are two
1791 operands) a digit.  For example, in @samp{od foo 10} and @samp{od +10}
1792 the @samp{10} is an offset, whereas in @samp{od 10} the @samp{10} is a
1793 file name.
1795 The program accepts the following options.  Also see @ref{Common options}.
1797 @table @samp
1799 @item -A @var{radix}
1800 @itemx --address-radix=@var{radix}
1801 @opindex -A
1802 @opindex --address-radix
1803 @cindex radix for file offsets
1804 @cindex file offset radix
1805 Select the base in which file offsets are printed.  @var{radix} can
1806 be one of the following:
1808 @table @samp
1809 @item d
1810 decimal;
1811 @item o
1812 octal;
1813 @item x
1814 hexadecimal;
1815 @item n
1816 none (do not print offsets).
1817 @end table
1819 The default is octal.
1821 @item -j @var{bytes}
1822 @itemx --skip-bytes=@var{bytes}
1823 @opindex -j
1824 @opindex --skip-bytes
1825 Skip @var{bytes} input bytes before formatting and writing.  If
1826 @var{bytes} begins with @samp{0x} or @samp{0X}, it is interpreted in
1827 hexadecimal; otherwise, if it begins with @samp{0}, in octal; otherwise,
1828 in decimal.
1829 @multiplierSuffixes{bytes}
1831 @item -N @var{bytes}
1832 @itemx --read-bytes=@var{bytes}
1833 @opindex -N
1834 @opindex --read-bytes
1835 Output at most @var{bytes} bytes of the input.  Prefixes and suffixes on
1836 @code{bytes} are interpreted as for the @option{-j} option.
1838 @item -S @var{bytes}
1839 @itemx --strings[=@var{bytes}]
1840 @opindex -S
1841 @opindex --strings
1842 @cindex string constants, outputting
1843 Instead of the normal output, output only @dfn{string constants}: at
1844 least @var{bytes} consecutive @acronym{ASCII} graphic characters,
1845 followed by a zero byte (@acronym{ASCII} @sc{nul}).
1846 Prefixes and suffixes on @code{bytes} are interpreted as for the
1847 @option{-j} option.
1849 If @var{n} is omitted with @option{--strings}, the default is 3.
1851 @item -t @var{type}
1852 @itemx --format=@var{type}
1853 @opindex -t
1854 @opindex --format
1855 Select the format in which to output the file data.  @var{type} is a
1856 string of one or more of the below type indicator characters.  If you
1857 include more than one type indicator character in a single @var{type}
1858 string, or use this option more than once, @command{od} writes one copy
1859 of each output line using each of the data types that you specified,
1860 in the order that you specified.
1862 Adding a trailing ``z'' to any type specification appends a display
1863 of the @acronym{ASCII} character representation of the printable characters
1864 to the output line generated by the type specification.
1866 @table @samp
1867 @item a
1868 named character, ignoring high-order bit
1869 @item c
1870 @acronym{ASCII} character or backslash escape,
1871 @item d
1872 signed decimal
1873 @item f
1874 floating point
1875 @item o
1876 octal
1877 @item u
1878 unsigned decimal
1879 @item x
1880 hexadecimal
1881 @end table
1883 The type @code{a} outputs things like @samp{sp} for space, @samp{nl} for
1884 newline, and @samp{nul} for a zero byte.  Only the least significant
1885 seven bits of each byte is used; the high-order bit is ignored.
1886 Type @code{c} outputs
1887 @samp{ }, @samp{\n}, and @code{\0}, respectively.
1889 @cindex type size
1890 Except for types @samp{a} and @samp{c}, you can specify the number
1891 of bytes to use in interpreting each number in the given data type
1892 by following the type indicator character with a decimal integer.
1893 Alternately, you can specify the size of one of the C compiler's
1894 built-in data types by following the type indicator character with
1895 one of the following characters.  For integers (@samp{d}, @samp{o},
1896 @samp{u}, @samp{x}):
1898 @table @samp
1899 @item C
1900 char
1901 @item S
1902 short
1903 @item I
1905 @item L
1906 long
1907 @end table
1909 For floating point (@code{f}):
1911 @table @asis
1912 @item F
1913 float
1914 @item D
1915 double
1916 @item L
1917 long double
1918 @end table
1920 @item -v
1921 @itemx --output-duplicates
1922 @opindex -v
1923 @opindex --output-duplicates
1924 Output consecutive lines that are identical.  By default, when two or
1925 more consecutive output lines would be identical, @command{od} outputs only
1926 the first line, and puts just an asterisk on the following line to
1927 indicate the elision.
1929 @item -w[@var{n}]
1930 @itemx --width[=@var{n}]
1931 @opindex -w
1932 @opindex --width
1933 Dump @code{n} input bytes per output line.  This must be a multiple of
1934 the least common multiple of the sizes associated with the specified
1935 output types.
1937 If this option is not given at all, the default is 16.  If @var{n} is
1938 omitted, the default is 32.
1940 @end table
1942 The next several options are shorthands for format specifications.
1943 @sc{gnu} @command{od} accepts any combination of shorthands and format
1944 specification options.  These options accumulate.
1946 @table @samp
1948 @item -a
1949 @opindex -a
1950 Output as named characters.  Equivalent to @samp{-t a}.
1952 @item -b
1953 @opindex -b
1954 Output as octal bytes.  Equivalent to @samp{-t o1}.
1956 @item -c
1957 @opindex -c
1958 Output as @acronym{ASCII} characters or backslash escapes.  Equivalent to
1959 @samp{-t c}.
1961 @item -d
1962 @opindex -d
1963 Output as unsigned decimal two-byte units.  Equivalent to @samp{-t u2}.
1965 @item -f
1966 @opindex -f
1967 Output as floats.  Equivalent to @samp{-t fF}.
1969 @item -i
1970 @opindex -i
1971 Output as decimal ints.  Equivalent to @samp{-t dI}.
1973 @item -l
1974 @opindex -l
1975 Output as decimal long ints.  Equivalent to @samp{-t dL}.
1977 @item -o
1978 @opindex -o
1979 Output as octal two-byte units.  Equivalent to @option{-t o2}.
1981 @item -s
1982 @opindex -s
1983 Output as decimal two-byte units.  Equivalent to @option{-t d2}.
1985 @item -x
1986 @opindex -x
1987 Output as hexadecimal two-byte units.  Equivalent to @samp{-t x2}.
1989 @item --traditional
1990 @opindex --traditional
1991 Recognize the non-option label argument that traditional @command{od}
1992 accepted.  The following syntax:
1994 @smallexample
1995 od --traditional [@var{file}] [[+]@var{offset}[.][b] [[+]@var{label}[.][b]]]
1996 @end smallexample
1998 @noindent
1999 can be used to specify at most one file and optional arguments
2000 specifying an offset and a pseudo-start address, @var{label}.
2001 The @var{label} argument is interpreted
2002 just like @var{offset}, but it specifies an initial pseudo-address.  The
2003 pseudo-addresses are displayed in parentheses following any normal
2004 address.
2006 @end table
2008 @exitstatus
2010 @node base64 invocation
2011 @section @command{base64}: Transform data into printable data.
2013 @pindex base64
2014 @cindex base64 encoding
2016 @command{base64} transforms data read from a file, or standard input,
2017 into (or from) base64 encoded form.  The base64 encoded form uses
2018 printable @acronym{ASCII} characters to represent binary data.
2019 Synopses:
2021 @smallexample
2022 base64 [@var{option}]@dots{} [@var{file}]
2023 base64 --decode [@var{option}]@dots{} [@var{file}]
2024 @end smallexample
2026 The base64 encoding expands data to roughly 133% of the original.
2027 The format conforms to
2028 @uref{ftp://ftp.rfc-editor.org/in-notes/rfc4648.txt, RFC 4648}.
2030 The program accepts the following options.  Also see @ref{Common options}.
2032 @table @samp
2034 @item -w @var{cols}
2035 @itemx --wrap=@var{cols}
2036 @opindex -w
2037 @opindex --wrap
2038 @cindex wrap data
2039 @cindex column to wrap data after
2040 During encoding, wrap lines after @var{cols} characters.  This must be
2041 a positive number.
2043 The default is to wrap after 76 characters.  Use the value 0 to
2044 disable line wrapping altogether.
2046 @item -d
2047 @itemx --decode
2048 @opindex -d
2049 @opindex --decode
2050 @cindex Decode base64 data
2051 @cindex Base64 decoding
2052 Change the mode of operation, from the default of encoding data, to
2053 decoding data.  Input is expected to be base64 encoded data, and the
2054 output will be the original data.
2056 @item -i
2057 @itemx --ignore-garbage
2058 @opindex -i
2059 @opindex --ignore-garbage
2060 @cindex Ignore garbage in base64 stream
2061 When decoding, newlines are always accepted.
2062 During decoding, ignore unrecognized bytes,
2063 to permit distorted data to be decoded.
2065 @end table
2067 @exitstatus
2070 @node Formatting file contents
2071 @chapter Formatting file contents
2073 @cindex formatting file contents
2075 These commands reformat the contents of files.
2077 @menu
2078 * fmt invocation::              Reformat paragraph text.
2079 * pr invocation::               Paginate or columnate files for printing.
2080 * fold invocation::             Wrap input lines to fit in specified width.
2081 @end menu
2084 @node fmt invocation
2085 @section @command{fmt}: Reformat paragraph text
2087 @pindex fmt
2088 @cindex reformatting paragraph text
2089 @cindex paragraphs, reformatting
2090 @cindex text, reformatting
2092 @command{fmt} fills and joins lines to produce output lines of (at most)
2093 a given number of characters (75 by default).  Synopsis:
2095 @example
2096 fmt [@var{option}]@dots{} [@var{file}]@dots{}
2097 @end example
2099 @command{fmt} reads from the specified @var{file} arguments (or standard
2100 input if none are given), and writes to standard output.
2102 By default, blank lines, spaces between words, and indentation are
2103 preserved in the output; successive input lines with different
2104 indentation are not joined; tabs are expanded on input and introduced on
2105 output.
2107 @cindex line-breaking
2108 @cindex sentences and line-breaking
2109 @cindex Knuth, Donald E.
2110 @cindex Plass, Michael F.
2111 @command{fmt} prefers breaking lines at the end of a sentence, and tries to
2112 avoid line breaks after the first word of a sentence or before the last
2113 word of a sentence.  A @dfn{sentence break} is defined as either the end
2114 of a paragraph or a word ending in any of @samp{.?!}, followed by two
2115 spaces or end of line, ignoring any intervening parentheses or quotes.
2116 Like @TeX{}, @command{fmt} reads entire ``paragraphs'' before choosing line
2117 breaks; the algorithm is a variant of that given by Donald E. Knuth
2118 and Michael F. Plass in ``Breaking Paragraphs Into Lines'',
2119 @cite{Software---Practice & Experience} @b{11}, 11 (November 1981),
2120 1119--1184.
2122 The program accepts the following options.  Also see @ref{Common options}.
2124 @table @samp
2126 @item -c
2127 @itemx --crown-margin
2128 @opindex -c
2129 @opindex --crown-margin
2130 @cindex crown margin
2131 @dfn{Crown margin} mode: preserve the indentation of the first two
2132 lines within a paragraph, and align the left margin of each subsequent
2133 line with that of the second line.
2135 @item -t
2136 @itemx --tagged-paragraph
2137 @opindex -t
2138 @opindex --tagged-paragraph
2139 @cindex tagged paragraphs
2140 @dfn{Tagged paragraph} mode: like crown margin mode, except that if
2141 indentation of the first line of a paragraph is the same as the
2142 indentation of the second, the first line is treated as a one-line
2143 paragraph.
2145 @item -s
2146 @itemx --split-only
2147 @opindex -s
2148 @opindex --split-only
2149 Split lines only.  Do not join short lines to form longer ones.  This
2150 prevents sample lines of code, and other such ``formatted'' text from
2151 being unduly combined.
2153 @item -u
2154 @itemx --uniform-spacing
2155 @opindex -u
2156 @opindex --uniform-spacing
2157 Uniform spacing.  Reduce spacing between words to one space, and spacing
2158 between sentences to two spaces.
2160 @item -@var{width}
2161 @itemx -w @var{width}
2162 @itemx --width=@var{width}
2163 @opindex -@var{width}
2164 @opindex -w
2165 @opindex --width
2166 Fill output lines up to @var{width} characters (default 75).  @command{fmt}
2167 initially tries to make lines about 7% shorter than this, to give it
2168 room to balance line lengths.
2170 @item -p @var{prefix}
2171 @itemx --prefix=@var{prefix}
2172 Only lines beginning with @var{prefix} (possibly preceded by whitespace)
2173 are subject to formatting.  The prefix and any preceding whitespace are
2174 stripped for the formatting and then re-attached to each formatted output
2175 line.  One use is to format certain kinds of program comments, while
2176 leaving the code unchanged.
2178 @end table
2180 @exitstatus
2183 @node pr invocation
2184 @section @command{pr}: Paginate or columnate files for printing
2186 @pindex pr
2187 @cindex printing, preparing files for
2188 @cindex multicolumn output, generating
2189 @cindex merging files in parallel
2191 @command{pr} writes each @var{file} (@samp{-} means standard input), or
2192 standard input if none are given, to standard output, paginating and
2193 optionally outputting in multicolumn format; optionally merges all
2194 @var{file}s, printing all in parallel, one per column.  Synopsis:
2196 @example
2197 pr [@var{option}]@dots{} [@var{file}]@dots{}
2198 @end example
2200 @vindex LC_MESSAGES
2201 By default, a 5-line header is printed at each page: two blank lines;
2202 a line with the date, the file name, and the page count; and two more
2203 blank lines.  A footer of five blank lines is also printed.
2204 The default @var{page_length} is 66
2205 lines.  The default number of text lines is therefore 56.
2206 The text line of the header takes the form
2207 @samp{@var{date} @var{string} @var{page}}, with spaces inserted around
2208 @var{string} so that the line takes up the full @var{page_width}.  Here,
2209 @var{date} is the date (see the @option{-D} or @option{--date-format}
2210 option for details), @var{string} is the centered header string, and
2211 @var{page} identifies the page number.  The @env{LC_MESSAGES} locale
2212 category affects the spelling of @var{page}; in the default C locale, it
2213 is @samp{Page @var{number}} where @var{number} is the decimal page
2214 number.
2216 Form feeds in the input cause page breaks in the output.  Multiple form
2217 feeds produce empty pages.
2219 Columns are of equal width, separated by an optional string (default
2220 is @samp{space}).  For multicolumn output, lines will always be truncated to
2221 @var{page_width} (default 72), unless you use the @option{-J} option.
2222 For single
2223 column output no line truncation occurs by default.  Use @option{-W} option to
2224 truncate lines in that case.
2226 The following changes were made in version 1.22i and apply to later
2227 versions of @command{pr}:
2228 @c FIXME: this whole section here sounds very awkward to me. I
2229 @c made a few small changes, but really it all needs to be redone. - Brian
2230 @c OK, I fixed another sentence or two, but some of it I just don't understand.
2231 @ - Brian
2232 @itemize @bullet
2234 @item
2235 Some small @var{letter options} (@option{-s}, @option{-w}) have been
2236 redefined for better @acronym{POSIX} compliance.  The output of some further
2237 cases has been adapted to other Unix systems.  These changes are not
2238 compatible with earlier versions of the program.
2240 @item
2241 Some @var{new capital letter} options (@option{-J}, @option{-S}, @option{-W})
2242 have been introduced to turn off unexpected interferences of small letter
2243 options.  The @option{-N} option and the second argument @var{last_page}
2244 of @samp{+FIRST_PAGE} offer more flexibility.  The detailed handling of
2245 form feeds set in the input files requires the @option{-T} option.
2247 @item
2248 Capital letter options override small letter ones.
2250 @item
2251 Some of the option-arguments (compare @option{-s}, @option{-e},
2252 @option{-i}, @option{-n}) cannot be specified as separate arguments from the
2253 preceding option letter (already stated in the @acronym{POSIX} specification).
2254 @end itemize
2256 The program accepts the following options.  Also see @ref{Common options}.
2258 @table @samp
2260 @item +@var{first_page}[:@var{last_page}]
2261 @itemx --pages=@var{first_page}[:@var{last_page}]
2262 @c The two following @opindex lines evoke warnings because they contain `:'
2263 @c The `info' spec does not permit that.  If we use those lines, we end
2264 @c up with truncated index entries that don't work.
2265 @c @opindex +@var{first_page}[:@var{last_page}]
2266 @c @opindex --pages=@var{first_page}[:@var{last_page}]
2267 @opindex +@var{page_range}
2268 @opindex --pages=@var{page_range}
2269 Begin printing with page @var{first_page} and stop with @var{last_page}.
2270 Missing @samp{:@var{last_page}} implies end of file.  While estimating
2271 the number of skipped pages each form feed in the input file results
2272 in a new page.  Page counting with and without @samp{+@var{first_page}}
2273 is identical.  By default, counting starts with the first page of input
2274 file (not first page printed).  Line numbering may be altered by @option{-N}
2275 option.
2277 @item -@var{column}
2278 @itemx --columns=@var{column}
2279 @opindex -@var{column}
2280 @opindex --columns
2281 @cindex down columns
2282 With each single @var{file}, produce @var{column} columns of output
2283 (default is 1) and print columns down, unless @option{-a} is used.  The
2284 column width is automatically decreased as @var{column} increases; unless
2285 you use the @option{-W/-w} option to increase @var{page_width} as well.
2286 This option might well cause some lines to be truncated.  The number of
2287 lines in the columns on each page are balanced.  The options @option{-e}
2288 and @option{-i} are on for multiple text-column output.  Together with
2289 @option{-J} option column alignment and line truncation is turned off.
2290 Lines of full length are joined in a free field format and @option{-S}
2291 option may set field separators.  @option{-@var{column}} may not be used
2292 with @option{-m} option.
2294 @item -a
2295 @itemx --across
2296 @opindex -a
2297 @opindex --across
2298 @cindex across columns
2299 With each single @var{file}, print columns across rather than down.  The
2300 @option{-@var{column}} option must be given with @var{column} greater than one.
2301 If a line is too long to fit in a column, it is truncated.
2303 @item -c
2304 @itemx --show-control-chars
2305 @opindex -c
2306 @opindex --show-control-chars
2307 Print control characters using hat notation (e.g., @samp{^G}); print
2308 other nonprinting characters in octal backslash notation.  By default,
2309 nonprinting characters are not changed.
2311 @item -d
2312 @itemx --double-space
2313 @opindex -d
2314 @opindex --double-space
2315 @cindex double spacing
2316 Double space the output.
2318 @item -D @var{format}
2319 @itemx --date-format=@var{format}
2320 @cindex time formats
2321 @cindex formatting times
2322 Format header dates using @var{format}, using the same conventions as
2323 for the command @samp{date +@var{format}}; @xref{date invocation}.
2324 Except for directives, which start with
2325 @samp{%}, characters in @var{format} are printed unchanged.  You can use
2326 this option to specify an arbitrary string in place of the header date,
2327 e.g., @option{--date-format="Monday morning"}.
2329 @vindex POSIXLY_CORRECT
2330 @vindex LC_TIME
2331 The default date format is @samp{%Y-%m-%d %H:%M} (for example,
2332 @samp{2001-12-04 23:59});
2333 but if the @env{POSIXLY_CORRECT} environment variable is set
2334 and the @env{LC_TIME} locale category specifies the @acronym{POSIX}
2335 locale, the default is @samp{%b %e %H:%M %Y} (for example,
2336 @samp{Dec@ @ 4 23:59 2001}.
2338 @vindex TZ
2339 Time stamps are listed according to the time zone rules specified by
2340 the @env{TZ} environment variable, or by the system default rules if
2341 @env{TZ} is not set.  @xref{TZ Variable,, Specifying the Time Zone
2342 with @env{TZ}, libc, The GNU C Library Reference Manual}.
2344 @item -e[@var{in-tabchar}[@var{in-tabwidth}]]
2345 @itemx --expand-tabs[=@var{in-tabchar}[@var{in-tabwidth}]]
2346 @opindex -e
2347 @opindex --expand-tabs
2348 @cindex input tabs
2349 Expand @var{tab}s to spaces on input.  Optional argument @var{in-tabchar} is
2350 the input tab character (default is the TAB character).  Second optional
2351 argument @var{in-tabwidth} is the input tab character's width (default
2352 is 8).
2354 @item -f
2355 @itemx -F
2356 @itemx --form-feed
2357 @opindex -F
2358 @opindex -f
2359 @opindex --form-feed
2360 Use a form feed instead of newlines to separate output pages.  This does
2361 not alter the default page length of 66 lines.
2363 @item -h @var{header}
2364 @itemx --header=@var{header}
2365 @opindex -h
2366 @opindex --header
2367 Replace the file name in the header with the centered string @var{header}.
2368 When using the shell, @var{header} should be quoted and should be
2369 separated from @option{-h} by a space.
2371 @item -i[@var{out-tabchar}[@var{out-tabwidth}]]
2372 @itemx --output-tabs[=@var{out-tabchar}[@var{out-tabwidth}]]
2373 @opindex -i
2374 @opindex --output-tabs
2375 @cindex output tabs
2376 Replace spaces with @var{tab}s on output.  Optional argument @var{out-tabchar}
2377 is the output tab character (default is the TAB character).  Second optional
2378 argument @var{out-tabwidth} is the output tab character's width (default
2379 is 8).
2381 @item -J
2382 @itemx --join-lines
2383 @opindex -J
2384 @opindex --join-lines
2385 Merge lines of full length.  Used together with the column options
2386 @option{-@var{column}}, @option{-a -@var{column}} or @option{-m}.  Turns off
2387 @option{-W/-w} line truncation;
2388 no column alignment used; may be used with
2389 @option{--sep-string[=@var{string}]}.  @option{-J} has been introduced
2390 (together with @option{-W} and @option{--sep-string})
2391 to disentangle the old (@acronym{POSIX}-compliant) options @option{-w} and
2392 @option{-s} along with the three column options.
2395 @item -l @var{page_length}
2396 @itemx --length=@var{page_length}
2397 @opindex -l
2398 @opindex --length
2399 Set the page length to @var{page_length} (default 66) lines, including
2400 the lines of the header [and the footer].  If @var{page_length} is less
2401 than or equal to 10, the header and footer are omitted, as if the
2402 @option{-t} option had been given.
2404 @item -m
2405 @itemx --merge
2406 @opindex -m
2407 @opindex --merge
2408 Merge and print all @var{file}s in parallel, one in each column.  If a
2409 line is too long to fit in a column, it is truncated, unless the @option{-J}
2410 option is used.  @option{--sep-string[=@var{string}]} may be used.
2411 Empty pages in
2412 some @var{file}s (form feeds set) produce empty columns, still marked
2413 by @var{string}.  The result is a continuous line numbering and column
2414 marking throughout the whole merged file.  Completely empty merged pages
2415 show no separators or line numbers.  The default header becomes
2416 @samp{@var{date} @var{page}} with spaces inserted in the middle; this
2417 may be used with the @option{-h} or @option{--header} option to fill up
2418 the middle blank part.
2420 @item -n[@var{number-separator}[@var{digits}]]
2421 @itemx --number-lines[=@var{number-separator}[@var{digits}]]
2422 @opindex -n
2423 @opindex --number-lines
2424 Provide @var{digits} digit line numbering (default for @var{digits} is
2425 5).  With multicolumn output the number occupies the first @var{digits}
2426 column positions of each text column or only each line of @option{-m}
2427 output.  With single column output the number precedes each line just as
2428 @option{-m} does.  Default counting of the line numbers starts with the
2429 first line of the input file (not the first line printed, compare the
2430 @option{--page} option and @option{-N} option).
2431 Optional argument @var{number-separator} is the character appended to
2432 the line number to separate it from the text followed.  The default
2433 separator is the TAB character.  In a strict sense a TAB is always
2434 printed with single column output only.  The TAB width varies
2435 with the TAB position, e.g., with the left @var{margin} specified
2436 by @option{-o} option.  With multicolumn output priority is given to
2437 @samp{equal width of output columns} (a @acronym{POSIX} specification).
2438 The TAB width is fixed to the value of the first column and does
2439 not change with different values of left @var{margin}.  That means a
2440 fixed number of spaces is always printed in the place of the
2441 @var{number-separator} TAB.  The tabification depends upon the output
2442 position.
2444 @item -N @var{line_number}
2445 @itemx --first-line-number=@var{line_number}
2446 @opindex -N
2447 @opindex --first-line-number
2448 Start line counting with the number @var{line_number} at first line of
2449 first page printed (in most cases not the first line of the input file).
2451 @item -o @var{margin}
2452 @itemx --indent=@var{margin}
2453 @opindex -o
2454 @opindex --indent
2455 @cindex indenting lines
2456 @cindex left margin
2457 Indent each line with a margin @var{margin} spaces wide (default is zero).
2458 The total page width is the size of the margin plus the @var{page_width}
2459 set with the @option{-W/-w} option.  A limited overflow may occur with
2460 numbered single column output (compare @option{-n} option).
2462 @item -r
2463 @itemx --no-file-warnings
2464 @opindex -r
2465 @opindex --no-file-warnings
2466 Do not print a warning message when an argument @var{file} cannot be
2467 opened.  (The exit status will still be nonzero, however.)
2469 @item -s[@var{char}]
2470 @itemx --separator[=@var{char}]
2471 @opindex -s
2472 @opindex --separator
2473 Separate columns by a single character @var{char}.  The default for
2474 @var{char} is the TAB character without @option{-w} and @samp{no
2475 character} with @option{-w}.  Without @option{-s} the default separator
2476 @samp{space} is set.  @option{-s[char]} turns off line truncation of all
2477 three column options (@option{-COLUMN}|@option{-a -COLUMN}|@option{-m}) unless
2478 @option{-w} is set.  This is a @acronym{POSIX}-compliant formulation.
2481 @item -S@var{string}
2482 @itemx --sep-string[=@var{string}]
2483 @opindex -S
2484 @opindex --sep-string
2485 Use @var{string} to separate output columns.  The @option{-S} option doesn't
2486 affect the @option{-W/-w} option, unlike the @option{-s} option which does.  It
2487 does not affect line truncation or column alignment.
2488 Without @option{-S}, and with @option{-J}, @command{pr} uses the default output
2489 separator, TAB@.
2490 Without @option{-S} or @option{-J}, @command{pr} uses a @samp{space}
2491 (same as @option{-S"@w{ }"}).  @option{--sep-string} with no
2492 @samp{=@var{string}} is equivalent to @option{--sep-string=""}.
2494 @item -t
2495 @itemx --omit-header
2496 @opindex -t
2497 @opindex --omit-header
2498 Do not print the usual header [and footer] on each page, and do not fill
2499 out the bottom of pages (with blank lines or a form feed).  No page
2500 structure is produced, but form feeds set in the input files are retained.
2501 The predefined pagination is not changed.  @option{-t} or @option{-T} may be
2502 useful together with other options; e.g.: @option{-t -e4}, expand TAB characters
2503 in the input file to 4 spaces but don't make any other changes.  Use of
2504 @option{-t} overrides @option{-h}.
2506 @item -T
2507 @itemx --omit-pagination
2508 @opindex -T
2509 @opindex --omit-pagination
2510 Do not print header [and footer].  In addition eliminate all form feeds
2511 set in the input files.
2513 @item -v
2514 @itemx --show-nonprinting
2515 @opindex -v
2516 @opindex --show-nonprinting
2517 Print nonprinting characters in octal backslash notation.
2519 @item -w @var{page_width}
2520 @itemx --width=@var{page_width}
2521 @opindex -w
2522 @opindex --width
2523 Set page width to @var{page_width} characters for multiple text-column
2524 output only (default for @var{page_width} is 72).  @option{-s[CHAR]} turns
2525 off the default page width and any line truncation and column alignment.
2526 Lines of full length are merged, regardless of the column options
2527 set.  No @var{page_width} setting is possible with single column output.
2528 A @acronym{POSIX}-compliant formulation.
2530 @item -W @var{page_width}
2531 @itemx --page_width=@var{page_width}
2532 @opindex -W
2533 @opindex --page_width
2534 Set the page width to @var{page_width} characters.  That's valid with and
2535 without a column option.  Text lines are truncated, unless @option{-J}
2536 is used.  Together with one of the three column options
2537 (@option{-@var{column}}, @option{-a -@var{column}} or @option{-m}) column
2538 alignment is always used.  The separator options @option{-S} or @option{-s}
2539 don't affect the @option{-W} option.  Default is 72 characters.  Without
2540 @option{-W @var{page_width}} and without any of the column options NO line
2541 truncation is used (defined to keep downward compatibility and to meet
2542 most frequent tasks).  That's equivalent to @option{-W 72 -J}.  The header
2543 line is never truncated.
2545 @end table
2547 @exitstatus
2550 @node fold invocation
2551 @section @command{fold}: Wrap input lines to fit in specified width
2553 @pindex fold
2554 @cindex wrapping long input lines
2555 @cindex folding long input lines
2557 @command{fold} writes each @var{file} (@option{-} means standard input), or
2558 standard input if none are given, to standard output, breaking long
2559 lines.  Synopsis:
2561 @example
2562 fold [@var{option}]@dots{} [@var{file}]@dots{}
2563 @end example
2565 By default, @command{fold} breaks lines wider than 80 columns.  The output
2566 is split into as many lines as necessary.
2568 @cindex screen columns
2569 @command{fold} counts screen columns by default; thus, a tab may count more
2570 than one column, backspace decreases the column count, and carriage
2571 return sets the column to zero.
2573 The program accepts the following options.  Also see @ref{Common options}.
2575 @table @samp
2577 @item -b
2578 @itemx --bytes
2579 @opindex -b
2580 @opindex --bytes
2581 Count bytes rather than columns, so that tabs, backspaces, and carriage
2582 returns are each counted as taking up one column, just like other
2583 characters.
2585 @item -s
2586 @itemx --spaces
2587 @opindex -s
2588 @opindex --spaces
2589 Break at word boundaries: the line is broken after the last blank before
2590 the maximum line length.  If the line contains no such blanks, the line
2591 is broken at the maximum line length as usual.
2593 @item -w @var{width}
2594 @itemx --width=@var{width}
2595 @opindex -w
2596 @opindex --width
2597 Use a maximum line length of @var{width} columns instead of 80.
2599 For compatibility @command{fold} supports an obsolete option syntax
2600 @option{-@var{width}}.  New scripts should use @option{-w @var{width}}
2601 instead.
2603 @end table
2605 @exitstatus
2608 @node Output of parts of files
2609 @chapter Output of parts of files
2611 @cindex output of parts of files
2612 @cindex parts of files, output of
2614 These commands output pieces of the input.
2616 @menu
2617 * head invocation::             Output the first part of files.
2618 * tail invocation::             Output the last part of files.
2619 * split invocation::            Split a file into fixed-size pieces.
2620 * csplit invocation::           Split a file into context-determined pieces.
2621 @end menu
2623 @node head invocation
2624 @section @command{head}: Output the first part of files
2626 @pindex head
2627 @cindex initial part of files, outputting
2628 @cindex first part of files, outputting
2630 @command{head} prints the first part (10 lines by default) of each
2631 @var{file}; it reads from standard input if no files are given or
2632 when given a @var{file} of @option{-}.  Synopsis:
2634 @example
2635 head [@var{option}]@dots{} [@var{file}]@dots{}
2636 @end example
2638 If more than one @var{file} is specified, @command{head} prints a
2639 one-line header consisting of:
2641 @example
2642 ==> @var{file name} <==
2643 @end example
2645 @noindent
2646 before the output for each @var{file}.
2648 The program accepts the following options.  Also see @ref{Common options}.
2650 @table @samp
2652 @item -c @var{n}
2653 @itemx --bytes=@var{n}
2654 @opindex -c
2655 @opindex --bytes
2656 Print the first @var{n} bytes, instead of initial lines.
2657 However, if @var{n} starts with a @samp{-},
2658 print all but the last @var{n} bytes of each file.
2659 @multiplierSuffixes{n}
2661 @itemx -n @var{n}
2662 @itemx --lines=@var{n}
2663 @opindex -n
2664 @opindex --lines
2665 Output the first @var{n} lines.
2666 However, if @var{n} starts with a @samp{-},
2667 print all but the last @var{n} lines of each file.
2668 Size multiplier suffixes are the same as with the @option{-c} option.
2670 @item -q
2671 @itemx --quiet
2672 @itemx --silent
2673 @opindex -q
2674 @opindex --quiet
2675 @opindex --silent
2676 Never print file name headers.
2678 @item -v
2679 @itemx --verbose
2680 @opindex -v
2681 @opindex --verbose
2682 Always print file name headers.
2684 @end table
2686 For compatibility @command{head} also supports an obsolete option syntax
2687 @option{-@var{count}@var{options}}, which is recognized only if it is
2688 specified first.  @var{count} is a decimal number optionally followed
2689 by a size letter (@samp{b}, @samp{k}, @samp{m}) as in @option{-c}, or
2690 @samp{l} to mean count by lines, or other option letters (@samp{cqv}).
2691 Scripts intended for standard hosts should use @option{-c @var{count}}
2692 or @option{-n @var{count}} instead.  If your script must also run on
2693 hosts that support only the obsolete syntax, it is usually simpler to
2694 avoid @command{head}, e.g., by using @samp{sed 5q} instead of
2695 @samp{head -5}.
2697 @exitstatus
2700 @node tail invocation
2701 @section @command{tail}: Output the last part of files
2703 @pindex tail
2704 @cindex last part of files, outputting
2706 @command{tail} prints the last part (10 lines by default) of each
2707 @var{file}; it reads from standard input if no files are given or
2708 when given a @var{file} of @samp{-}.  Synopsis:
2710 @example
2711 tail [@var{option}]@dots{} [@var{file}]@dots{}
2712 @end example
2714 If more than one @var{file} is specified, @command{tail} prints a
2715 one-line header consisting of:
2717 @example
2718 ==> @var{file name} <==
2719 @end example
2721 @noindent
2722 before the output for each @var{file}.
2724 @cindex BSD @command{tail}
2725 @sc{gnu} @command{tail} can output any amount of data (some other versions of
2726 @command{tail} cannot).  It also has no @option{-r} option (print in
2727 reverse), since reversing a file is really a different job from printing
2728 the end of a file; BSD @command{tail} (which is the one with @option{-r}) can
2729 only reverse files that are at most as large as its buffer, which is
2730 typically 32 KiB@.  A more reliable and versatile way to reverse files is
2731 the @sc{gnu} @command{tac} command.
2733 The program accepts the following options.  Also see @ref{Common options}.
2735 @table @samp
2737 @item -c @var{n}
2738 @itemx --bytes=@var{n}
2739 @opindex -c
2740 @opindex --bytes
2741 Output the last @var{n} bytes, instead of final lines.
2742 However, if @var{n} starts with a @samp{+}, start printing with the
2743 @var{n}th byte from the start of each file, instead of from the end.
2744 @multiplierSuffixes{n}
2746 @item -f
2747 @itemx --follow[=@var{how}]
2748 @opindex -f
2749 @opindex --follow
2750 @cindex growing files
2751 @vindex name @r{follow option}
2752 @vindex descriptor @r{follow option}
2753 Loop forever trying to read more characters at the end of the file,
2754 presumably because the file is growing.
2755 If more than one file is given, @command{tail} prints a header whenever it
2756 gets output from a different file, to indicate which file that output is
2757 from.
2759 There are two ways to specify how you'd like to track files with this option,
2760 but that difference is noticeable only when a followed file is removed or
2761 renamed.
2762 If you'd like to continue to track the end of a growing file even after
2763 it has been unlinked, use @option{--follow=descriptor}.  This is the default
2764 behavior, but it is not useful if you're tracking a log file that may be
2765 rotated (removed or renamed, then reopened).  In that case, use
2766 @option{--follow=name} to track the named file by reopening it periodically
2767 to see if it has been removed and recreated by some other program.
2769 No matter which method you use, if the tracked file is determined to have
2770 shrunk, @command{tail} prints a message saying the file has been truncated
2771 and resumes tracking the end of the file from the newly-determined endpoint.
2773 When a file is removed, @command{tail}'s behavior depends on whether it is
2774 following the name or the descriptor.  When following by name, tail can
2775 detect that a file has been removed and gives a message to that effect,
2776 and if @option{--retry} has been specified it will continue checking
2777 periodically to see if the file reappears.
2778 When following a descriptor, tail does not detect that the file has
2779 been unlinked or renamed and issues no message;  even though the file
2780 may no longer be accessible via its original name, it may still be
2781 growing.
2783 The option values @samp{descriptor} and @samp{name} may be specified only
2784 with the long form of the option, not with @option{-f}.
2786 @vindex POSIXLY_CORRECT
2787 If @env{POSIXLY_CORRECT} is set, the @option{-f} option is ignored if
2788 no @var{file} operand is specified and standard input is a FIFO or a pipe.
2790 @item -F
2791 @opindex -F
2792 This option is the same as @option{--follow=name --retry}.  That is, tail
2793 will attempt to reopen a file when it is removed.  Should this fail, tail
2794 will keep trying until it becomes accessible again.
2796 @itemx --retry
2797 @opindex --retry
2798 This option is useful mainly when following by name (i.e., with
2799 @option{--follow=name}).
2800 Without this option, when tail encounters a file that doesn't
2801 exist or is otherwise inaccessible, it reports that fact and
2802 never checks it again.
2804 @itemx --sleep-interval=@var{number}
2805 @opindex --sleep-interval
2806 Change the number of seconds to wait between iterations (the default is 1.0).
2807 During one iteration, every specified file is checked to see if it has
2808 changed size.
2809 Historical implementations of @command{tail} have required that
2810 @var{number} be an integer.  However, GNU @command{tail} accepts
2811 an arbitrary floating point number (using a period before any
2812 fractional digits).
2814 @itemx --pid=@var{pid}
2815 @opindex --pid
2816 When following by name or by descriptor, you may specify the process ID,
2817 @var{pid}, of the sole writer of all @var{file} arguments.  Then, shortly
2818 after that process terminates, tail will also terminate.  This will
2819 work properly only if the writer and the tailing process are running on
2820 the same machine.  For example, to save the output of a build in a file
2821 and to watch the file grow, if you invoke @command{make} and @command{tail}
2822 like this then the tail process will stop when your build completes.
2823 Without this option, you would have had to kill the @code{tail -f}
2824 process yourself.
2826 @example
2827 $ make >& makerr & tail --pid=$! -f makerr
2828 @end example
2830 If you specify a @var{pid} that is not in use or that does not correspond
2831 to the process that is writing to the tailed files, then @command{tail}
2832 may terminate long before any @var{file}s stop growing or it may not
2833 terminate until long after the real writer has terminated.
2834 Note that @option{--pid} cannot be supported on some systems; @command{tail}
2835 will print a warning if this is the case.
2837 @itemx --max-unchanged-stats=@var{n}
2838 @opindex --max-unchanged-stats
2839 When tailing a file by name, if there have been @var{n} (default
2840 n=@value{DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS}) consecutive
2841 iterations for which the file has not changed, then
2842 @code{open}/@code{fstat} the file to determine if that file name is
2843 still associated with the same device/inode-number pair as before.
2844 When following a log file that is rotated, this is approximately the
2845 number of seconds between when tail prints the last pre-rotation lines
2846 and when it prints the lines that have accumulated in the new log file.
2847 This option is meaningful only when following by name.
2849 @itemx -n @var{n}
2850 @itemx --lines=@var{n}
2851 @opindex -n
2852 @opindex --lines
2853 Output the last @var{n} lines.
2854 However, if @var{n} starts with a @samp{+}, start printing with the
2855 @var{n}th line from the start of each file, instead of from the end.
2856 Size multiplier suffixes are the same as with the @option{-c} option.
2858 @item -q
2859 @itemx --quiet
2860 @itemx --silent
2861 @opindex -q
2862 @opindex --quiet
2863 @opindex --silent
2864 Never print file name headers.
2866 @item -v
2867 @itemx --verbose
2868 @opindex -v
2869 @opindex --verbose
2870 Always print file name headers.
2872 @end table
2874 For compatibility @command{tail} also supports an obsolete usage
2875 @samp{tail -[@var{count}][bcl][f] [@var{file}]}, which is recognized
2876 only if it does not conflict with the usage described
2877 above.  This obsolete form uses exactly one option and at most one
2878 file.  In the option, @var{count} is an optional decimal number optionally
2879 followed by a size letter (@samp{b}, @samp{c}, @samp{l}) to mean count
2880 by 512-byte blocks, bytes, or lines, optionally followed by @samp{f}
2881 which has the same meaning as @option{-f}.
2883 @vindex _POSIX2_VERSION
2884 On older systems, the leading @samp{-} can be replaced by @samp{+} in
2885 the obsolete option syntax with the same meaning as in counts, and
2886 obsolete usage overrides normal usage when the two conflict.
2887 This obsolete behavior can be enabled or disabled with the
2888 @env{_POSIX2_VERSION} environment variable (@pxref{Standards
2889 conformance}).
2891 Scripts intended for use on standard hosts should avoid obsolete
2892 syntax and should use @option{-c @var{count}[b]}, @option{-n
2893 @var{count}}, and/or @option{-f} instead.  If your script must also
2894 run on hosts that support only the obsolete syntax, you can often
2895 rewrite it to avoid problematic usages, e.g., by using @samp{sed -n
2896 '$p'} rather than @samp{tail -1}.  If that's not possible, the script
2897 can use a test like @samp{if tail -c +1 </dev/null >/dev/null 2>&1;
2898 then @dots{}} to decide which syntax to use.
2900 Even if your script assumes the standard behavior, you should still
2901 beware usages whose behaviors differ depending on the @acronym{POSIX}
2902 version.  For example, avoid @samp{tail - main.c}, since it might be
2903 interpreted as either @samp{tail main.c} or as @samp{tail -- -
2904 main.c}; avoid @samp{tail -c 4}, since it might mean either @samp{tail
2905 -c4} or @samp{tail -c 10 4}; and avoid @samp{tail +4}, since it might
2906 mean either @samp{tail ./+4} or @samp{tail -n +4}.
2908 @exitstatus
2911 @node split invocation
2912 @section @command{split}: Split a file into fixed-size pieces
2914 @pindex split
2915 @cindex splitting a file into pieces
2916 @cindex pieces, splitting a file into
2918 @command{split} creates output files containing consecutive sections of
2919 @var{input} (standard input if none is given or @var{input} is
2920 @samp{-}).  Synopsis:
2922 @example
2923 split [@var{option}] [@var{input} [@var{prefix}]]
2924 @end example
2926 By default, @command{split} puts 1000 lines of @var{input} (or whatever is
2927 left over for the last section), into each output file.
2929 @cindex output file name prefix
2930 The output files' names consist of @var{prefix} (@samp{x} by default)
2931 followed by a group of characters (@samp{aa}, @samp{ab}, @dots{} by
2932 default), such that concatenating the output files in traditional
2933 sorted order by file name produces
2934 the original input file.  If the output file names are exhausted,
2935 @command{split} reports an error without deleting the output files
2936 that it did create.
2938 The program accepts the following options.  Also see @ref{Common options}.
2940 @table @samp
2942 @item -l @var{lines}
2943 @itemx --lines=@var{lines}
2944 @opindex -l
2945 @opindex --lines
2946 Put @var{lines} lines of @var{input} into each output file.
2948 For compatibility @command{split} also supports an obsolete
2949 option syntax @option{-@var{lines}}.  New scripts should use @option{-l
2950 @var{lines}} instead.
2952 @item -b @var{size}
2953 @itemx --bytes=@var{size}
2954 @opindex -b
2955 @opindex --bytes
2956 Put @var{size} bytes of @var{input} into each output file.
2957 @multiplierSuffixes{size}
2959 @item -C @var{size}
2960 @itemx --line-bytes=@var{size}
2961 @opindex -C
2962 @opindex --line-bytes
2963 Put into each output file as many complete lines of @var{input} as
2964 possible without exceeding @var{size} bytes.  Individual lines longer than
2965 @var{size} bytes are broken into multiple files.
2966 @var{size} has the same format as for the @option{--bytes} option.
2968 @item -a @var{length}
2969 @itemx --suffix-length=@var{length}
2970 @opindex -a
2971 @opindex --suffix-length
2972 Use suffixes of length @var{length}.  The default @var{length} is 2.
2974 @item -d
2975 @itemx --numeric-suffixes
2976 @opindex -d
2977 @opindex --numeric-suffixes
2978 Use digits in suffixes rather than lower-case letters.
2980 @itemx --verbose
2981 @opindex --verbose
2982 Write a diagnostic just before each output file is opened.
2984 @end table
2986 @exitstatus
2989 @node csplit invocation
2990 @section @command{csplit}: Split a file into context-determined pieces
2992 @pindex csplit
2993 @cindex context splitting
2994 @cindex splitting a file into pieces by context
2996 @command{csplit} creates zero or more output files containing sections of
2997 @var{input} (standard input if @var{input} is @samp{-}).  Synopsis:
2999 @example
3000 csplit [@var{option}]@dots{} @var{input} @var{pattern}@dots{}
3001 @end example
3003 The contents of the output files are determined by the @var{pattern}
3004 arguments, as detailed below.  An error occurs if a @var{pattern}
3005 argument refers to a nonexistent line of the input file (e.g., if no
3006 remaining line matches a given regular expression).  After every
3007 @var{pattern} has been matched, any remaining input is copied into one
3008 last output file.
3010 By default, @command{csplit} prints the number of bytes written to each
3011 output file after it has been created.
3013 The types of pattern arguments are:
3015 @table @samp
3017 @item @var{n}
3018 Create an output file containing the input up to but not including line
3019 @var{n} (a positive integer).  If followed by a repeat count, also
3020 create an output file containing the next @var{n} lines of the input
3021 file once for each repeat.
3023 @item /@var{regexp}/[@var{offset}]
3024 Create an output file containing the current line up to (but not
3025 including) the next line of the input file that contains a match for
3026 @var{regexp}.  The optional @var{offset} is an integer.
3027 If it is given, the input up to (but not including) the
3028 matching line plus or minus @var{offset} is put into the output file,
3029 and the line after that begins the next section of input.
3031 @item %@var{regexp}%[@var{offset}]
3032 Like the previous type, except that it does not create an output
3033 file, so that section of the input file is effectively ignored.
3035 @item @{@var{repeat-count}@}
3036 Repeat the previous pattern @var{repeat-count} additional
3037 times.  The @var{repeat-count} can either be a positive integer or an
3038 asterisk, meaning repeat as many times as necessary until the input is
3039 exhausted.
3041 @end table
3043 The output files' names consist of a prefix (@samp{xx} by default)
3044 followed by a suffix.  By default, the suffix is an ascending sequence
3045 of two-digit decimal numbers from @samp{00} to @samp{99}.  In any case,
3046 concatenating the output files in sorted order by file name produces the
3047 original input file.
3049 By default, if @command{csplit} encounters an error or receives a hangup,
3050 interrupt, quit, or terminate signal, it removes any output files
3051 that it has created so far before it exits.
3053 The program accepts the following options.  Also see @ref{Common options}.
3055 @table @samp
3057 @item -f @var{prefix}
3058 @itemx --prefix=@var{prefix}
3059 @opindex -f
3060 @opindex --prefix
3061 @cindex output file name prefix
3062 Use @var{prefix} as the output file name prefix.
3064 @item -b @var{suffix}
3065 @itemx --suffix=@var{suffix}
3066 @opindex -b
3067 @opindex --suffix
3068 @cindex output file name suffix
3069 Use @var{suffix} as the output file name suffix.  When this option is
3070 specified, the suffix string must include exactly one
3071 @code{printf(3)}-style conversion specification, possibly including
3072 format specification flags, a field width, a precision specifications,
3073 or all of these kinds of modifiers.  The format letter must convert a
3074 binary integer argument to readable form; thus, only @samp{d}, @samp{i},
3075 @samp{u}, @samp{o}, @samp{x}, and @samp{X} conversions are allowed.  The
3076 entire @var{suffix} is given (with the current output file number) to
3077 @code{sprintf(3)} to form the file name suffixes for each of the
3078 individual output files in turn.  If this option is used, the
3079 @option{--digits} option is ignored.
3081 @item -n @var{digits}
3082 @itemx --digits=@var{digits}
3083 @opindex -n
3084 @opindex --digits
3085 Use output file names containing numbers that are @var{digits} digits
3086 long instead of the default 2.
3088 @item -k
3089 @itemx --keep-files
3090 @opindex -k
3091 @opindex --keep-files
3092 Do not remove output files when errors are encountered.
3094 @item -z
3095 @itemx --elide-empty-files
3096 @opindex -z
3097 @opindex --elide-empty-files
3098 Suppress the generation of zero-length output files.  (In cases where
3099 the section delimiters of the input file are supposed to mark the first
3100 lines of each of the sections, the first output file will generally be a
3101 zero-length file unless you use this option.)  The output file sequence
3102 numbers always run consecutively starting from 0, even when this option
3103 is specified.
3105 @item -s
3106 @itemx -q
3107 @itemx --silent
3108 @itemx --quiet
3109 @opindex -s
3110 @opindex -q
3111 @opindex --silent
3112 @opindex --quiet
3113 Do not print counts of output file sizes.
3115 @end table
3117 @exitstatus
3119 Here is an example of its usage.
3120 First, create an empty directory for the exercise,
3121 and cd into it:
3123 @example
3124 $ mkdir d && cd d
3125 @end example
3127 Now, split the sequence of 1..14 on lines that end with 0 or 5:
3129 @example
3130 $ seq 14 | csplit - '/[05]$/' '@{*@}'
3134 @end example
3136 Each number printed above is the size of an output
3137 file that csplit has just created.
3138 List the names of those output files:
3140 @example
3141 $ ls
3142 xx00  xx01  xx02
3143 @end example
3145 Use @command{head} to show their contents:
3147 @example
3148 $ head xx*
3149 ==> xx00 <==
3155 ==> xx01 <==
3162 ==> xx02 <==
3168 @end example
3170 @node Summarizing files
3171 @chapter Summarizing files
3173 @cindex summarizing files
3175 These commands generate just a few numbers representing entire
3176 contents of files.
3178 @menu
3179 * wc invocation::               Print newline, word, and byte counts.
3180 * sum invocation::              Print checksum and block counts.
3181 * cksum invocation::            Print CRC checksum and byte counts.
3182 * md5sum invocation::           Print or check MD5 digests.
3183 * sha1sum invocation::          Print or check SHA-1 digests.
3184 * sha2 utilities::              Print or check SHA-2 digests.
3185 @end menu
3188 @node wc invocation
3189 @section @command{wc}: Print newline, word, and byte counts
3191 @pindex wc
3192 @cindex byte count
3193 @cindex character count
3194 @cindex word count
3195 @cindex line count
3197 @command{wc} counts the number of bytes, characters, whitespace-separated
3198 words, and newlines in each given @var{file}, or standard input if none
3199 are given or for a @var{file} of @samp{-}.  Synopsis:
3201 @example
3202 wc [@var{option}]@dots{} [@var{file}]@dots{}
3203 @end example
3205 @cindex total counts
3206 @command{wc} prints one line of counts for each file, and if the file was
3207 given as an argument, it prints the file name following the counts.  If
3208 more than one @var{file} is given, @command{wc} prints a final line
3209 containing the cumulative counts, with the file name @file{total}.  The
3210 counts are printed in this order: newlines, words, characters, bytes,
3211 maximum line length.
3212 Each count is printed right-justified in a field with at least one
3213 space between fields so that the numbers and file names normally line
3214 up nicely in columns.  The width of the count fields varies depending
3215 on the inputs, so you should not depend on a particular field width.
3216 However, as a @acronym{GNU} extension, if only one count is printed,
3217 it is guaranteed to be printed without leading spaces.
3219 By default, @command{wc} prints three counts: the newline, words, and byte
3220 counts.  Options can specify that only certain counts be printed.
3221 Options do not undo others previously given, so
3223 @example
3224 wc --bytes --words
3225 @end example
3227 @noindent
3228 prints both the byte counts and the word counts.
3230 With the @option{--max-line-length} option, @command{wc} prints the length
3231 of the longest line per file, and if there is more than one file it
3232 prints the maximum (not the sum) of those lengths.  The line lengths here
3233 are measured in screen columns, according to the current locale and
3234 assuming tab positions in every 8th column.
3236 The program accepts the following options.  Also see @ref{Common options}.
3238 @table @samp
3240 @item -c
3241 @itemx --bytes
3242 @opindex -c
3243 @opindex --bytes
3244 Print only the byte counts.
3246 @item -m
3247 @itemx --chars
3248 @opindex -m
3249 @opindex --chars
3250 Print only the character counts.
3252 @item -w
3253 @itemx --words
3254 @opindex -w
3255 @opindex --words
3256 Print only the word counts.
3258 @item -l
3259 @itemx --lines
3260 @opindex -l
3261 @opindex --lines
3262 Print only the newline counts.
3264 @item -L
3265 @itemx --max-line-length
3266 @opindex -L
3267 @opindex --max-line-length
3268 Print only the maximum line lengths.
3270 @macro filesZeroFromOption{cmd,withTotalOption,subListOutput}
3271 @itemx --files0-from=@var{file}
3272 @opindex --files0-from=@var{file}
3273 @c This is commented out to avoid a texi2dvi failure.
3274 @c texi2dvi (GNU Texinfo 4.11) 1.104
3275 @c @cindex including files from @command{\cmd\}
3276 Disallow processing files named on the command line, and instead process
3277 those named in file @var{file}; each name being terminated by a zero byte
3278 (@acronym{ASCII} @sc{nul}).
3279 This is useful \withTotalOption\
3280 when the list of file names is so long that it may exceed a command line
3281 length limitation.
3282 In such cases, running @command{\cmd\} via @command{xargs} is undesirable
3283 because it splits the list into pieces and makes @command{\cmd\} print
3284 \subListOutput\ for each sublist rather than for the entire list.
3285 One way to produce a list of @acronym{ASCII} @sc{nul} terminated file names is with @sc{gnu}
3286 @command{find}, using its @option{-print0} predicate.
3287 If @var{file} is @samp{-} then the @acronym{ASCII} @sc{nul} terminated file names
3288 are read from standard input.
3289 @end macro
3290 @filesZeroFromOption{wc,,a total}
3292 For example, to find the length of the longest line in any @file{.c} or
3293 @file{.h} file in the current hierarchy, do this:
3295 @example
3296 find . -name '*.[ch]' -print0 |
3297   wc -L --files0-from=- | tail -n1
3298 @end example
3300 @end table
3302 @exitstatus
3305 @node sum invocation
3306 @section @command{sum}: Print checksum and block counts
3308 @pindex sum
3309 @cindex 16-bit checksum
3310 @cindex checksum, 16-bit
3312 @command{sum} computes a 16-bit checksum for each given @var{file}, or
3313 standard input if none are given or for a @var{file} of @samp{-}.  Synopsis:
3315 @example
3316 sum [@var{option}]@dots{} [@var{file}]@dots{}
3317 @end example
3319 @command{sum} prints the checksum for each @var{file} followed by the
3320 number of blocks in the file (rounded up).  If more than one @var{file}
3321 is given, file names are also printed (by default).  (With the
3322 @option{--sysv} option, corresponding file names are printed when there is
3323 at least one file argument.)
3325 By default, @sc{gnu} @command{sum} computes checksums using an algorithm
3326 compatible with BSD @command{sum} and prints file sizes in units of
3327 1024-byte blocks.
3329 The program accepts the following options.  Also see @ref{Common options}.
3331 @table @samp
3333 @item -r
3334 @opindex -r
3335 @cindex BSD @command{sum}
3336 Use the default (BSD compatible) algorithm.  This option is included for
3337 compatibility with the System V @command{sum}.  Unless @option{-s} was also
3338 given, it has no effect.
3340 @item -s
3341 @itemx --sysv
3342 @opindex -s
3343 @opindex --sysv
3344 @cindex System V @command{sum}
3345 Compute checksums using an algorithm compatible with System V
3346 @command{sum}'s default, and print file sizes in units of 512-byte blocks.
3348 @end table
3350 @command{sum} is provided for compatibility; the @command{cksum} program (see
3351 next section) is preferable in new applications.
3353 @exitstatus
3356 @node cksum invocation
3357 @section @command{cksum}: Print CRC checksum and byte counts
3359 @pindex cksum
3360 @cindex cyclic redundancy check
3361 @cindex CRC checksum
3363 @command{cksum} computes a cyclic redundancy check (CRC) checksum for each
3364 given @var{file}, or standard input if none are given or for a
3365 @var{file} of @samp{-}.  Synopsis:
3367 @example
3368 cksum [@var{option}]@dots{} [@var{file}]@dots{}
3369 @end example
3371 @command{cksum} prints the CRC checksum for each file along with the number
3372 of bytes in the file, and the file name unless no arguments were given.
3374 @command{cksum} is typically used to ensure that files
3375 transferred by unreliable means (e.g., netnews) have not been corrupted,
3376 by comparing the @command{cksum} output for the received files with the
3377 @command{cksum} output for the original files (typically given in the
3378 distribution).
3380 The CRC algorithm is specified by the @acronym{POSIX} standard.  It is not
3381 compatible with the BSD or System V @command{sum} algorithms (see the
3382 previous section); it is more robust.
3384 The only options are @option{--help} and @option{--version}.  @xref{Common
3385 options}.
3387 @exitstatus
3390 @node md5sum invocation
3391 @section @command{md5sum}: Print or check MD5 digests
3393 @pindex md5sum
3394 @cindex MD5
3395 @cindex 128-bit checksum
3396 @cindex checksum, 128-bit
3397 @cindex fingerprint, 128-bit
3398 @cindex message-digest, 128-bit
3400 @command{md5sum} computes a 128-bit checksum (or @dfn{fingerprint} or
3401 @dfn{message-digest}) for each specified @var{file}.
3403 Note: The MD5 digest is more reliable than a simple CRC (provided by
3404 the @command{cksum} command) for detecting accidental file corruption,
3405 as the chances of accidentally having two files with identical MD5
3406 are vanishingly small.  However, it should not be considered truly
3407 secure against malicious tampering: although finding a file with a
3408 given MD5 fingerprint, or modifying a file so as to retain its MD5 are
3409 considered infeasible at the moment, it is known how to produce
3410 different files with identical MD5 (a ``collision''), something which
3411 can be a security issue in certain contexts.  For more secure hashes,
3412 consider using SHA-1 or SHA-2.  @xref{sha1sum invocation}, and
3413 @ref{sha2 utilities}.
3415 If a @var{file} is specified as @samp{-} or if no files are given
3416 @command{md5sum} computes the checksum for the standard input.
3417 @command{md5sum} can also determine whether a file and checksum are
3418 consistent.  Synopsis:
3420 @example
3421 md5sum [@var{option}]@dots{} [@var{file}]@dots{}
3422 @end example
3424 For each @var{file}, @samp{md5sum} outputs the MD5 checksum, a flag
3425 indicating a binary or text input file, and the file name.
3426 If @var{file} contains a backslash or newline, the
3427 line is started with a backslash, and each problematic character in
3428 the file name is escaped with a backslash, making the output
3429 unambiguous even in the presence of arbitrary file names.
3430 If @var{file} is omitted or specified as @samp{-}, standard input is read.
3432 The program accepts the following options.  Also see @ref{Common options}.
3434 @table @samp
3436 @item -b
3437 @itemx --binary
3438 @opindex -b
3439 @opindex --binary
3440 @cindex binary input files
3441 Treat each input file as binary, by reading it in binary mode and
3442 outputting a @samp{*} flag.  This is the inverse of @option{--text}.
3443 On systems like @acronym{GNU} that do not distinguish between binary
3444 and text files, this option merely flags each input file as binary:
3445 the MD5 checksum is unaffected.  This option is the default on systems
3446 like MS-DOS that distinguish between binary and text files, except
3447 for reading standard input when standard input is a terminal.
3449 @item -c
3450 @itemx --check
3451 Read file names and checksum information (not data) from each
3452 @var{file} (or from stdin if no @var{file} was specified) and report
3453 whether the checksums match the contents of the named files.
3454 The input to this mode of @command{md5sum} is usually the output of
3455 a prior, checksum-generating run of @samp{md5sum}.
3456 Each valid line of input consists of an MD5 checksum, a binary/text
3457 flag, and then a file name.
3458 Binary files are marked with @samp{*}, text with @samp{ }.
3459 For each such line, @command{md5sum} reads the named file and computes its
3460 MD5 checksum.  Then, if the computed message digest does not match the
3461 one on the line with the file name, the file is noted as having
3462 failed the test.  Otherwise, the file passes the test.
3463 By default, for each valid line, one line is written to standard
3464 output indicating whether the named file passed the test.
3465 After all checks have been performed, if there were any failures,
3466 a warning is issued to standard error.
3467 Use the @option{--status} option to inhibit that output.
3468 If any listed file cannot be opened or read, if any valid line has
3469 an MD5 checksum inconsistent with the associated file, or if no valid
3470 line is found, @command{md5sum} exits with nonzero status.  Otherwise,
3471 it exits successfully.
3473 @itemx --quiet
3474 @opindex --quiet
3475 @cindex verifying MD5 checksums
3476 This option is useful only when verifying checksums.
3477 When verifying checksums, don't generate an 'OK' message per successfully
3478 checked file.  Files that fail the verification are reported in the
3479 default one-line-per-file format.  If there is any checksum mismatch,
3480 print a warning summarizing the failures to standard error.
3482 @itemx --status
3483 @opindex --status
3484 @cindex verifying MD5 checksums
3485 This option is useful only when verifying checksums.
3486 When verifying checksums, don't generate the default one-line-per-file
3487 diagnostic and don't output the warning summarizing any failures.
3488 Failures to open or read a file still evoke individual diagnostics to
3489 standard error.
3490 If all listed files are readable and are consistent with the associated
3491 MD5 checksums, exit successfully.  Otherwise exit with a status code
3492 indicating there was a failure.
3494 @item -t
3495 @itemx --text
3496 @opindex -t
3497 @opindex --text
3498 @cindex text input files
3499 Treat each input file as text, by reading it in text mode and
3500 outputting a @samp{ } flag.  This is the inverse of @option{--binary}.
3501 This option is the default on systems like @acronym{GNU} that do not
3502 distinguish between binary and text files.  On other systems, it is
3503 the default for reading standard input when standard input is a
3504 terminal.
3506 @item -w
3507 @itemx --warn
3508 @opindex -w
3509 @opindex --warn
3510 @cindex verifying MD5 checksums
3511 When verifying checksums, warn about improperly formatted MD5 checksum lines.
3512 This option is useful only if all but a few lines in the checked input
3513 are valid.
3515 @end table
3517 @exitstatus
3520 @node sha1sum invocation
3521 @section @command{sha1sum}: Print or check SHA-1 digests
3523 @pindex sha1sum
3524 @cindex SHA-1
3525 @cindex 160-bit checksum
3526 @cindex checksum, 160-bit
3527 @cindex fingerprint, 160-bit
3528 @cindex message-digest, 160-bit
3530 @command{sha1sum} computes a 160-bit checksum for each specified
3531 @var{file}.  The usage and options of this command are precisely the
3532 same as for @command{md5sum}.  @xref{md5sum invocation}.
3534 Note: The SHA-1 digest is more secure than MD5, and no collisions of
3535 it are known (different files having the same fingerprint).  However,
3536 it is known that they can be produced with considerable, but not
3537 unreasonable, resources.  For this reason, it is generally considered
3538 that SHA-1 should be gradually phased out in favor of the more secure
3539 SHA-2 hash algorithms.  @xref{sha2 utilities}.
3542 @node sha2 utilities
3543 @section sha2 utilities: Print or check SHA-2 digests
3545 @pindex sha224sum
3546 @pindex sha256sum
3547 @pindex sha384sum
3548 @pindex sha512sum
3549 @cindex SHA-2
3550 @cindex 224-bit checksum
3551 @cindex 256-bit checksum
3552 @cindex 384-bit checksum
3553 @cindex 512-bit checksum
3554 @cindex checksum, 224-bit
3555 @cindex checksum, 256-bit
3556 @cindex checksum, 384-bit
3557 @cindex checksum, 512-bit
3558 @cindex fingerprint, 224-bit
3559 @cindex fingerprint, 256-bit
3560 @cindex fingerprint, 384-bit
3561 @cindex fingerprint, 512-bit
3562 @cindex message-digest, 224-bit
3563 @cindex message-digest, 256-bit
3564 @cindex message-digest, 384-bit
3565 @cindex message-digest, 512-bit
3567 The commands @command{sha224sum}, @command{sha256sum},
3568 @command{sha384sum} and @command{sha512sum} compute checksums of
3569 various lengths (respectively 224, 256, 384 and 512 bits),
3570 collectively known as the SHA-2 hashes.  The usage and options of
3571 these commands are precisely the same as for @command{md5sum}.
3572 @xref{md5sum invocation}.
3574 Note: The SHA384 and SHA512 digests are considerably slower to
3575 compute, especially on 32-bit computers, than SHA224 or SHA256.
3578 @node Operating on sorted files
3579 @chapter Operating on sorted files
3581 @cindex operating on sorted files
3582 @cindex sorted files, operations on
3584 These commands work with (or produce) sorted files.
3586 @menu
3587 * sort invocation::             Sort text files.
3588 * shuf invocation::             Shuffle text files.
3589 * uniq invocation::             Uniquify files.
3590 * comm invocation::             Compare two sorted files line by line.
3591 * ptx invocation::              Produce a permuted index of file contents.
3592 * tsort invocation::            Topological sort.
3593 @end menu
3596 @node sort invocation
3597 @section @command{sort}: Sort text files
3599 @pindex sort
3600 @cindex sorting files
3602 @command{sort} sorts, merges, or compares all the lines from the given
3603 files, or standard input if none are given or for a @var{file} of
3604 @samp{-}.  By default, @command{sort} writes the results to standard
3605 output.  Synopsis:
3607 @example
3608 sort [@var{option}]@dots{} [@var{file}]@dots{}
3609 @end example
3611 @command{sort} has three modes of operation: sort (the default), merge,
3612 and check for sortedness.  The following options change the operation
3613 mode:
3615 @table @samp
3617 @item -c
3618 @itemx --check
3619 @itemx --check=diagnose-first
3620 @opindex -c
3621 @opindex --check
3622 @cindex checking for sortedness
3623 Check whether the given file is already sorted: if it is not all
3624 sorted, print a diagnostic containing the first out-of-order line and
3625 exit with a status of 1.
3626 Otherwise, exit successfully.
3627 At most one input file can be given.
3629 @item -C
3630 @itemx --check=quiet
3631 @itemx --check=silent
3632 @opindex -c
3633 @opindex --check
3634 @cindex checking for sortedness
3635 Exit successfully if the given file is already sorted, and
3636 exit with status 1 otherwise.
3637 At most one input file can be given.
3638 This is like @option{-c}, except it does not print a diagnostic.
3640 @item -m
3641 @itemx --merge
3642 @opindex -m
3643 @opindex --merge
3644 @cindex merging sorted files
3645 Merge the given files by sorting them as a group.  Each input file must
3646 always be individually sorted.  It always works to sort instead of
3647 merge; merging is provided because it is faster, in the case where it
3648 works.
3650 @end table
3652 @cindex sort stability
3653 @cindex sort's last-resort comparison
3654 A pair of lines is compared as follows:
3655 @command{sort} compares each pair of fields, in the
3656 order specified on the command line, according to the associated
3657 ordering options, until a difference is found or no fields are left.
3658 If no key fields are specified, @command{sort} uses a default key of
3659 the entire line.  Finally, as a last resort when all keys compare
3660 equal, @command{sort} compares entire lines as if no ordering options
3661 other than @option{--reverse} (@option{-r}) were specified.  The
3662 @option{--stable} (@option{-s}) option disables this @dfn{last-resort
3663 comparison} so that lines in which all fields compare equal are left
3664 in their original relative order.  The @option{--unique}
3665 (@option{-u}) option also disables the last-resort comparison.
3667 @vindex LC_ALL
3668 @vindex LC_COLLATE
3669 Unless otherwise specified, all comparisons use the character collating
3670 sequence specified by the @env{LC_COLLATE} locale.@footnote{If you
3671 use a non-@acronym{POSIX} locale (e.g., by setting @env{LC_ALL}
3672 to @samp{en_US}), then @command{sort} may produce output that is sorted
3673 differently than you're accustomed to.  In that case, set the @env{LC_ALL}
3674 environment variable to @samp{C}.  Note that setting only @env{LC_COLLATE}
3675 has two problems.  First, it is ineffective if @env{LC_ALL} is also set.
3676 Second, it has undefined behavior if @env{LC_CTYPE} (or @env{LANG}, if
3677 @env{LC_CTYPE} is unset) is set to an incompatible value.  For example,
3678 you get undefined behavior if @env{LC_CTYPE} is @code{ja_JP.PCK} but
3679 @env{LC_COLLATE} is @code{en_US.UTF-8}.}
3681 @sc{gnu} @command{sort} (as specified for all @sc{gnu} utilities) has no
3682 limit on input line length or restrictions on bytes allowed within lines.
3683 In addition, if the final byte of an input file is not a newline, @sc{gnu}
3684 @command{sort} silently supplies one.  A line's trailing newline is not
3685 part of the line for comparison purposes.
3687 @cindex exit status of @command{sort}
3688 Exit status:
3690 @display
3691 0 if no error occurred
3692 1 if invoked with @option{-c} or @option{-C} and the input is not sorted
3693 2 if an error occurred
3694 @end display
3696 @vindex TMPDIR
3697 If the environment variable @env{TMPDIR} is set, @command{sort} uses its
3698 value as the directory for temporary files instead of @file{/tmp}.  The
3699 @option{--temporary-directory} (@option{-T}) option in turn overrides
3700 the environment variable.
3702 The following options affect the ordering of output lines.  They may be
3703 specified globally or as part of a specific key field.  If no key
3704 fields are specified, global options apply to comparison of entire
3705 lines; otherwise the global options are inherited by key fields that do
3706 not specify any special options of their own.  In pre-@acronym{POSIX}
3707 versions of @command{sort}, global options affect only later key fields,
3708 so portable shell scripts should specify global options first.
3710 @table @samp
3712 @item -b
3713 @itemx --ignore-leading-blanks
3714 @opindex -b
3715 @opindex --ignore-leading-blanks
3716 @cindex blanks, ignoring leading
3717 @vindex LC_CTYPE
3718 Ignore leading blanks when finding sort keys in each line.
3719 By default a blank is a space or a tab, but the @env{LC_CTYPE} locale
3720 can change this.
3722 @item -d
3723 @itemx --dictionary-order
3724 @opindex -d
3725 @opindex --dictionary-order
3726 @cindex dictionary order
3727 @cindex phone directory order
3728 @cindex telephone directory order
3729 @vindex LC_CTYPE
3730 Sort in @dfn{phone directory} order: ignore all characters except
3731 letters, digits and blanks when sorting.
3732 By default letters and digits are those of @acronym{ASCII} and a blank
3733 is a space or a tab, but the @env{LC_CTYPE} locale can change this.
3735 @item -f
3736 @itemx --ignore-case
3737 @opindex -f
3738 @opindex --ignore-case
3739 @cindex ignoring case
3740 @cindex case folding
3741 @vindex LC_CTYPE
3742 Fold lowercase characters into the equivalent uppercase characters when
3743 comparing so that, for example, @samp{b} and @samp{B} sort as equal.
3744 The @env{LC_CTYPE} locale determines character types.
3746 @item -g
3747 @itemx --general-numeric-sort
3748 @itemx --sort=general-numeric
3749 @opindex -g
3750 @opindex --general-numeric-sort
3751 @opindex --sort
3752 @cindex general numeric sort
3753 @vindex LC_NUMERIC
3754 Sort numerically, using the standard C function @code{strtod} to convert
3755 a prefix of each line to a double-precision floating point number.
3756 This allows floating point numbers to be specified in scientific notation,
3757 like @code{1.0e-34} and @code{10e100}.
3758 The @env{LC_NUMERIC} locale determines the decimal-point character.
3759 Do not report overflow, underflow, or conversion errors.
3760 Use the following collating sequence:
3762 @itemize @bullet
3763 @item
3764 Lines that do not start with numbers (all considered to be equal).
3765 @item
3766 NaNs (``Not a Number'' values, in IEEE floating point arithmetic)
3767 in a consistent but machine-dependent order.
3768 @item
3769 Minus infinity.
3770 @item
3771 Finite numbers in ascending numeric order (with @math{-0} and @math{+0} equal).
3772 @item
3773 Plus infinity.
3774 @end itemize
3776 Use this option only if there is no alternative; it is much slower than
3777 @option{--numeric-sort} (@option{-n}) and it can lose information when
3778 converting to floating point.
3780 @item -i
3781 @itemx --ignore-nonprinting
3782 @opindex -i
3783 @opindex --ignore-nonprinting
3784 @cindex nonprinting characters, ignoring
3785 @cindex unprintable characters, ignoring
3786 @vindex LC_CTYPE
3787 Ignore nonprinting characters.
3788 The @env{LC_CTYPE} locale determines character types.
3789 This option has no effect if the stronger @option{--dictionary-order}
3790 (@option{-d}) option is also given.
3792 @item -M
3793 @itemx --month-sort
3794 @itemx --sort=month
3795 @opindex -M
3796 @opindex --month-sort
3797 @opindex --sort
3798 @cindex months, sorting by
3799 @vindex LC_TIME
3800 An initial string, consisting of any amount of blanks, followed
3801 by a month name abbreviation, is folded to UPPER case and
3802 compared in the order @samp{JAN} < @samp{FEB} < @dots{} < @samp{DEC}.
3803 Invalid names compare low to valid names.  The @env{LC_TIME} locale
3804 category determines the month spellings.
3805 By default a blank is a space or a tab, but the @env{LC_CTYPE} locale
3806 can change this.
3808 @item -n
3809 @itemx --numeric-sort
3810 @itemx --sort=numeric
3811 @opindex -n
3812 @opindex --numeric-sort
3813 @opindex --sort
3814 @cindex numeric sort
3815 @vindex LC_NUMERIC
3816 Sort numerically.  The number begins each line and consists
3817 of optional blanks, an optional @samp{-} sign, and zero or more
3818 digits possibly separated by thousands separators, optionally followed
3819 by a decimal-point character and zero or more digits.  An empty
3820 number is treated as @samp{0}.  The @env{LC_NUMERIC}
3821 locale specifies the decimal-point character and thousands separator.
3822 By default a blank is a space or a tab, but the @env{LC_CTYPE} locale
3823 can change this.
3825 Comparison is exact; there is no rounding error.
3827 Neither a leading @samp{+} nor exponential notation is recognized.
3828 To compare such strings numerically, use the
3829 @option{--general-numeric-sort} (@option{-g}) option.
3831 @item -V
3832 @itemx --version-sort
3833 @opindex -V
3834 @opindex --version-sort
3835 @cindex version number sort
3836 @vindex LC_NUMERIC
3837 Sort per @code{strverscmp(3)}.  This is a normal string comparison, except
3838 that embedded decimal numbers are sorted by numeric value
3839 (see @option{--numeric-sort} above).
3841 @item -r
3842 @itemx --reverse
3843 @opindex -r
3844 @opindex --reverse
3845 @cindex reverse sorting
3846 Reverse the result of comparison, so that lines with greater key values
3847 appear earlier in the output instead of later.
3849 @item -R
3850 @itemx --random-sort
3851 @itemx --sort=random
3852 @opindex -R
3853 @opindex --random-sort
3854 @opindex --sort
3855 @cindex random sort
3856 Sort by hashing the input keys and then sorting the hash values.
3857 Choose the hash function at random, ensuring that it is free of
3858 collisions so that differing keys have differing hash values.  This is
3859 like a random permutation of the inputs (@pxref{shuf invocation}),
3860 except that keys with the same value sort together.
3862 If multiple random sort fields are specified, the same random hash
3863 function is used for all fields.  To use different random hash
3864 functions for different fields, you can invoke @command{sort} more
3865 than once.
3867 The choice of hash function is affected by the
3868 @option{--random-source} option.
3870 @end table
3872 Other options are:
3874 @table @samp
3876 @item --compress-program=@var{prog}
3877 Compress any temporary files with the program @var{prog}.
3879 With no arguments, @var{prog} must compress standard input to standard
3880 output, and when given the @option{-d} option it must decompress
3881 standard input to standard output.
3883 Terminate with an error if @var{prog} exits with nonzero status.
3885 White space and the backslash character should not appear in
3886 @var{prog}; they are reserved for future use.
3888 @filesZeroFromOption{sort,,sorted output}
3890 @item -k @var{pos1}[,@var{pos2}]
3891 @itemx --key=@var{pos1}[,@var{pos2}]
3892 @opindex -k
3893 @opindex --key
3894 @cindex sort field
3895 Specify a sort field that consists of the part of the line between
3896 @var{pos1} and @var{pos2} (or the end of the line, if @var{pos2} is
3897 omitted), @emph{inclusive}.
3899 Each @var{pos} has the form @samp{@var{f}[.@var{c}][@var{opts}]},
3900 where @var{f} is the number of the field to use, and @var{c} is the number
3901 of the first character from the beginning of the field.  Fields and character
3902 positions are numbered starting with 1; a character position of zero in
3903 @var{pos2} indicates the field's last character.  If @samp{.@var{c}} is
3904 omitted from @var{pos1}, it defaults to 1 (the beginning of the field);
3905 if omitted from @var{pos2}, it defaults to 0 (the end of the field).
3906 @var{opts} are ordering options, allowing individual keys to be sorted
3907 according to different rules; see below for details.  Keys can span
3908 multiple fields.
3910 Example:  To sort on the second field, use @option{--key=2,2}
3911 (@option{-k 2,2}).  See below for more examples.
3913 @item --batch-size=@var{nmerge}
3914 @opindex --batch-size
3915 @cindex number of inputs to merge, nmerge
3916 Merge at most @var{nmerge} inputs at once.
3918 When @command{sort} has to merge more than @var{nmerge} inputs,
3919 it merges them in groups of @var{nmerge}, saving the result in
3920 a temporary file, which is then used as an input in a subsequent merge.
3922 A large value of @var{nmerge} may improve merge performance and decrease
3923 temporary storage utilization at the expense of increased memory usage
3924 and I/0.  Conversely a small value of @var{nmerge} may reduce memory
3925 requirements and I/0 at the expense of temporary storage consumption and
3926 merge performance.
3928 The value of @var{nmerge} must be at least 2.
3930 The value of @var{nmerge} may be bounded by a resource limit for open
3931 file descriptors.  Try @samp{ulimit -n} or @samp{getconf OPEN_MAX} to
3932 to display the limit for a particular system.
3933 If the value of @var{nmerge} exceeds this limit, then @command{sort} will
3934 issue a warning to standard error and exit with a nonzero status.
3936 @item -o @var{output-file}
3937 @itemx --output=@var{output-file}
3938 @opindex -o
3939 @opindex --output
3940 @cindex overwriting of input, allowed
3941 Write output to @var{output-file} instead of standard output.
3942 Normally, @command{sort} reads all input before opening
3943 @var{output-file}, so you can safely sort a file in place by using
3944 commands like @code{sort -o F F} and @code{cat F | sort -o F}.
3945 However, @command{sort} with @option{--merge} (@option{-m}) can open
3946 the output file before reading all input, so a command like @code{cat
3947 F | sort -m -o F - G} is not safe as @command{sort} might start
3948 writing @file{F} before @command{cat} is done reading it.
3950 @vindex POSIXLY_CORRECT
3951 On newer systems, @option{-o} cannot appear after an input file if
3952 @env{POSIXLY_CORRECT} is set, e.g., @samp{sort F -o F}.  Portable
3953 scripts should specify @option{-o @var{output-file}} before any input
3954 files.
3956 @item --random-source=@var{file}
3957 @opindex --random-source
3958 @cindex random source for sorting
3959 Use @var{file} as a source of random data used to determine which
3960 random hash function to use with the @option{-R} option.  @xref{Random
3961 sources}.
3963 @item -s
3964 @itemx --stable
3965 @opindex -s
3966 @opindex --stable
3967 @cindex sort stability
3968 @cindex sort's last-resort comparison
3970 Make @command{sort} stable by disabling its last-resort comparison.
3971 This option has no effect if no fields or global ordering options
3972 other than @option{--reverse} (@option{-r}) are specified.
3974 @item -S @var{size}
3975 @itemx --buffer-size=@var{size}
3976 @opindex -S
3977 @opindex --buffer-size
3978 @cindex size for main memory sorting
3979 Use a main-memory sort buffer of the given @var{size}.  By default,
3980 @var{size} is in units of 1024 bytes.  Appending @samp{%} causes
3981 @var{size} to be interpreted as a percentage of physical memory.
3982 Appending @samp{K} multiplies @var{size} by 1024 (the default),
3983 @samp{M} by 1,048,576, @samp{G} by 1,073,741,824, and so on for
3984 @samp{T}, @samp{P}, @samp{E}, @samp{Z}, and @samp{Y}.  Appending
3985 @samp{b} causes @var{size} to be interpreted as a byte count, with no
3986 multiplication.
3988 This option can improve the performance of @command{sort} by causing it
3989 to start with a larger or smaller sort buffer than the default.
3990 However, this option affects only the initial buffer size.  The buffer
3991 grows beyond @var{size} if @command{sort} encounters input lines larger
3992 than @var{size}.
3994 @item -t @var{separator}
3995 @itemx --field-separator=@var{separator}
3996 @opindex -t
3997 @opindex --field-separator
3998 @cindex field separator character
3999 Use character @var{separator} as the field separator when finding the
4000 sort keys in each line.  By default, fields are separated by the empty
4001 string between a non-blank character and a blank character.
4002 By default a blank is a space or a tab, but the @env{LC_CTYPE} locale
4003 can change this.
4005 That is, given the input line @w{@samp{ foo bar}}, @command{sort} breaks it
4006 into fields @w{@samp{ foo}} and @w{@samp{ bar}}.  The field separator is
4007 not considered to be part of either the field preceding or the field
4008 following, so with @samp{sort @w{-t " "}} the same input line has
4009 three fields: an empty field, @samp{foo}, and @samp{bar}.
4010 However, fields that extend to the end of the line,
4011 as @option{-k 2}, or fields consisting of a range, as @option{-k 2,3},
4012 retain the field separators present between the endpoints of the range.
4014 To specify @acronym{ASCII} @sc{nul} as the field separator,
4015 use the two-character string @samp{\0}, e.g., @samp{sort -t '\0'}.
4017 @item -T @var{tempdir}
4018 @itemx --temporary-directory=@var{tempdir}
4019 @opindex -T
4020 @opindex --temporary-directory
4021 @cindex temporary directory
4022 @vindex TMPDIR
4023 Use directory @var{tempdir} to store temporary files, overriding the
4024 @env{TMPDIR} environment variable.  If this option is given more than
4025 once, temporary files are stored in all the directories given.  If you
4026 have a large sort or merge that is I/O-bound, you can often improve
4027 performance by using this option to specify directories on different
4028 disks and controllers.
4030 @item -u
4031 @itemx --unique
4032 @opindex -u
4033 @opindex --unique
4034 @cindex uniquifying output
4036 Normally, output only the first of a sequence of lines that compare
4037 equal.  For the @option{--check} (@option{-c} or @option{-C}) option,
4038 check that no pair of consecutive lines compares equal.
4040 This option also disables the default last-resort comparison.
4042 The commands @code{sort -u} and @code{sort | uniq} are equivalent, but
4043 this equivalence does not extend to arbitrary @command{sort} options.
4044 For example, @code{sort -n -u} inspects only the value of the initial
4045 numeric string when checking for uniqueness, whereas @code{sort -n |
4046 uniq} inspects the entire line.  @xref{uniq invocation}.
4048 @macro zeroTerminatedOption
4049 @item -z
4050 @itemx --zero-terminated
4051 @opindex -z
4052 @opindex --zero-terminated
4053 @cindex process zero-terminated items
4054 Delimit items with a zero byte rather than a newline (@acronym{ASCII} @sc{lf}).
4055 I.E. treat input as items separated by @acronym{ASCII} @sc{nul}
4056 and terminate output items with @acronym{ASCII} @sc{nul}.
4057 This option can be useful in conjunction with @samp{perl -0} or
4058 @samp{find -print0} and @samp{xargs -0} which do the same in order to
4059 reliably handle arbitrary file names (even those containing blanks
4060 or other special characters).
4061 @end macro
4062 @zeroTerminatedOption
4064 @end table
4066 Historical (BSD and System V) implementations of @command{sort} have
4067 differed in their interpretation of some options, particularly
4068 @option{-b}, @option{-f}, and @option{-n}.  @sc{gnu} sort follows the @acronym{POSIX}
4069 behavior, which is usually (but not always!) like the System V behavior.
4070 According to @acronym{POSIX}, @option{-n} no longer implies @option{-b}.  For
4071 consistency, @option{-M} has been changed in the same way.  This may
4072 affect the meaning of character positions in field specifications in
4073 obscure cases.  The only fix is to add an explicit @option{-b}.
4075 A position in a sort field specified with @option{-k} may have any
4076 of the option letters @samp{Mbdfinr} appended to it, in which case the
4077 global ordering options are not used for that particular field.  The
4078 @option{-b} option may be independently attached to either or both of
4079 the start and end positions of a field specification, and if it is
4080 inherited from the global options it will be attached to both.
4081 If input lines can contain leading or adjacent blanks and @option{-t}
4082 is not used, then @option{-k} is typically combined with @option{-b},
4083 @option{-g}, @option{-M}, or @option{-n}; otherwise the varying
4084 numbers of leading blanks in fields can cause confusing results.
4086 If the start position in a sort field specifier falls after the end of
4087 the line or after the end field, the field is empty.  If the @option{-b}
4088 option was specified, the @samp{.@var{c}} part of a field specification
4089 is counted from the first nonblank character of the field.
4091 @vindex _POSIX2_VERSION
4092 @vindex POSIXLY_CORRECT
4093 On older systems, @command{sort} supports an obsolete origin-zero
4094 syntax @samp{+@var{pos1} [-@var{pos2}]} for specifying sort keys.
4095 This obsolete behavior can be enabled or disabled with the
4096 @env{_POSIX2_VERSION} environment variable (@pxref{Standards
4097 conformance}); it can also be enabled when @env{POSIXLY_CORRECT} is
4098 not set by using the obsolete syntax with @samp{-@var{pos2}} present.
4100 Scripts intended for use on standard hosts should avoid obsolete
4101 syntax and should use @option{-k} instead.  For example, avoid
4102 @samp{sort +2}, since it might be interpreted as either @samp{sort
4103 ./+2} or @samp{sort -k 3}.  If your script must also run on hosts that
4104 support only the obsolete syntax, it can use a test like @samp{if sort
4105 -k 1 </dev/null >/dev/null 2>&1; then @dots{}} to decide which syntax
4106 to use.
4108 Here are some examples to illustrate various combinations of options.
4110 @itemize @bullet
4112 @item
4113 Sort in descending (reverse) numeric order.
4115 @example
4116 sort -n -r
4117 @end example
4119 @item
4120 Sort alphabetically, omitting the first and second fields
4121 and the blanks at the start of the third field.
4122 This uses a single key composed of the characters beginning
4123 at the start of the first nonblank character in field three
4124 and extending to the end of each line.
4126 @example
4127 sort -k 3b
4128 @end example
4130 @item
4131 Sort numerically on the second field and resolve ties by sorting
4132 alphabetically on the third and fourth characters of field five.
4133 Use @samp{:} as the field delimiter.
4135 @example
4136 sort -t : -k 2,2n -k 5.3,5.4
4137 @end example
4139 Note that if you had written @option{-k 2n} instead of @option{-k 2,2n}
4140 @command{sort} would have used all characters beginning in the second field
4141 and extending to the end of the line as the primary @emph{numeric}
4142 key.  For the large majority of applications, treating keys spanning
4143 more than one field as numeric will not do what you expect.
4145 Also note that the @samp{n} modifier was applied to the field-end
4146 specifier for the first key.  It would have been equivalent to
4147 specify @option{-k 2n,2} or @option{-k 2n,2n}.  All modifiers except
4148 @samp{b} apply to the associated @emph{field}, regardless of whether
4149 the modifier character is attached to the field-start and/or the
4150 field-end part of the key specifier.
4152 @item
4153 Sort the password file on the fifth field and ignore any
4154 leading blanks.  Sort lines with equal values in field five
4155 on the numeric user ID in field three.  Fields are separated
4156 by @samp{:}.
4158 @example
4159 sort -t : -k 5b,5 -k 3,3n /etc/passwd
4160 sort -t : -n -k 5b,5 -k 3,3 /etc/passwd
4161 sort -t : -b -k 5,5 -k 3,3n /etc/passwd
4162 @end example
4164 These three commands have equivalent effect.  The first specifies that
4165 the first key's start position ignores leading blanks and the second
4166 key is sorted numerically.  The other two commands rely on global
4167 options being inherited by sort keys that lack modifiers.  The inheritance
4168 works in this case because @option{-k 5b,5b} and @option{-k 5b,5} are
4169 equivalent, as the location of a field-end lacking a @samp{.@var{c}}
4170 character position is not affected by whether initial blanks are
4171 skipped.
4173 @item
4174 Sort a set of log files, primarily by IPv4 address and secondarily by
4175 time stamp.  If two lines' primary and secondary keys are identical,
4176 output the lines in the same order that they were input.  The log
4177 files contain lines that look like this:
4179 @example
4180 4.150.156.3 - - [01/Apr/2004:06:31:51 +0000] message 1
4181 211.24.3.231 - - [24/Apr/2004:20:17:39 +0000] message 2
4182 @end example
4184 Fields are separated by exactly one space.  Sort IPv4 addresses
4185 lexicographically, e.g., 212.61.52.2 sorts before 212.129.233.201
4186 because 61 is less than 129.
4188 @example
4189 sort -s -t ' ' -k 4.9n -k 4.5M -k 4.2n -k 4.14,4.21 file*.log |
4190 sort -s -t '.' -k 1,1n -k 2,2n -k 3,3n -k 4,4n
4191 @end example
4193 This example cannot be done with a single @command{sort} invocation,
4194 since IPv4 address components are separated by @samp{.} while dates
4195 come just after a space.  So it is broken down into two invocations of
4196 @command{sort}: the first sorts by time stamp and the second by IPv4
4197 address.  The time stamp is sorted by year, then month, then day, and
4198 finally by hour-minute-second field, using @option{-k} to isolate each
4199 field.  Except for hour-minute-second there's no need to specify the
4200 end of each key field, since the @samp{n} and @samp{M} modifiers sort
4201 based on leading prefixes that cannot cross field boundaries.  The
4202 IPv4 addresses are sorted lexicographically.  The second sort uses
4203 @samp{-s} so that ties in the primary key are broken by the secondary
4204 key; the first sort uses @samp{-s} so that the combination of the two
4205 sorts is stable.
4207 @item
4208 Generate a tags file in case-insensitive sorted order.
4210 @smallexample
4211 find src -type f -print0 | sort -z -f | xargs -0 etags --append
4212 @end smallexample
4214 The use of @option{-print0}, @option{-z}, and @option{-0} in this case means
4215 that file names that contain blanks or other special characters are
4216 not broken up
4217 by the sort operation.
4219 @c This example is a bit contrived and needs more explanation.
4220 @c @item
4221 @c Sort records separated by an arbitrary string by using a pipe to convert
4222 @c each record delimiter string to @samp{\0}, then using sort's -z option,
4223 @c and converting each @samp{\0} back to the original record delimiter.
4225 @c @example
4226 @c printf 'c\n\nb\n\na\n'|perl -0pe 's/\n\n/\n\0/g'|sort -z|perl -0pe 's/\0/\n/g'
4227 @c @end example
4229 @item
4230 Shuffle a list of directories, but preserve the order of files within
4231 each directory.  For instance, one could use this to generate a music
4232 playlist in which albums are shuffled but the songs of each album are
4233 played in order.
4235 @example
4236 ls */* | sort -t / -k 1,1R -k 2,2
4237 @end example
4239 @end itemize
4242 @node shuf invocation
4243 @section @command{shuf}: Shuffling text
4245 @pindex shuf
4246 @cindex shuffling files
4248 @command{shuf} shuffles its input by outputting a random permutation
4249 of its input lines.  Each output permutation is equally likely.
4250 Synopses:
4252 @example
4253 shuf [@var{option}]@dots{} [@var{file}]
4254 shuf -e [@var{option}]@dots{} [@var{arg}]@dots{}
4255 shuf -i @var{lo}-@var{hi} [@var{option}]@dots{}
4256 @end example
4258 @command{shuf} has three modes of operation that affect where it
4259 obtains its input lines.  By default, it reads lines from standard
4260 input.  The following options change the operation mode:
4262 @table @samp
4264 @item -e
4265 @itemx --echo
4266 @opindex -c
4267 @opindex --echo
4268 @cindex command-line operands to shuffle
4269 Treat each command-line operand as an input line.
4271 @item -i @var{lo}-@var{hi}
4272 @itemx --input-range=@var{lo}-@var{hi}
4273 @opindex -i
4274 @opindex --input-range
4275 @cindex input range to shuffle
4276 Act as if input came from a file containing the range of unsigned
4277 decimal integers @var{lo}@dots{}@var{hi}, one per line.
4279 @end table
4281 @command{shuf}'s other options can affect its behavior in all
4282 operation modes:
4284 @table @samp
4286 @item -n @var{lines}
4287 @itemx --head-count=@var{count}
4288 @opindex -n
4289 @opindex --head-count
4290 @cindex head of output
4291 Output at most @var{count} lines.  By default, all input lines are
4292 output.
4294 @item -o @var{output-file}
4295 @itemx --output=@var{output-file}
4296 @opindex -o
4297 @opindex --output
4298 @cindex overwriting of input, allowed
4299 Write output to @var{output-file} instead of standard output.
4300 @command{shuf} reads all input before opening
4301 @var{output-file}, so you can safely shuffle a file in place by using
4302 commands like @code{shuf -o F <F} and @code{cat F | shuf -o F}.
4304 @item --random-source=@var{file}
4305 @opindex --random-source
4306 @cindex random source for shuffling
4307 Use @var{file} as a source of random data used to determine which
4308 permutation to generate.  @xref{Random sources}.
4310 @zeroTerminatedOption
4312 @end table
4314 For example:
4316 @example
4317 shuf <<EOF
4318 A man,
4319 a plan,
4320 a canal:
4321 Panama!
4323 @end example
4325 @noindent
4326 might produce the output
4328 @example
4329 Panama!
4330 A man,
4331 a canal:
4332 a plan,
4333 @end example
4335 @noindent
4336 Similarly, the command:
4338 @example
4339 shuf -e clubs hearts diamonds spades
4340 @end example
4342 @noindent
4343 might output:
4345 @example
4346 clubs
4347 diamonds
4348 spades
4349 hearts
4350 @end example
4352 @noindent
4353 and the command @samp{shuf -i 1-4} might output:
4355 @example
4360 @end example
4362 @noindent
4363 These examples all have four input lines, so @command{shuf} might
4364 produce any of the twenty-four possible permutations of the input.  In
4365 general, if there are @var{n} input lines, there are @var{n}! (i.e.,
4366 @var{n} factorial, or @var{n} * (@var{n} - 1) * @dots{} * 1) possible
4367 output permutations.
4369 @exitstatus
4372 @node uniq invocation
4373 @section @command{uniq}: Uniquify files
4375 @pindex uniq
4376 @cindex uniquify files
4378 @command{uniq} writes the unique lines in the given @file{input}, or
4379 standard input if nothing is given or for an @var{input} name of
4380 @samp{-}.  Synopsis:
4382 @example
4383 uniq [@var{option}]@dots{} [@var{input} [@var{output}]]
4384 @end example
4386 By default, @command{uniq} prints its input lines, except that
4387 it discards all but the first of adjacent repeated lines, so that
4388 no output lines are repeated.  Optionally, it can instead discard
4389 lines that are not repeated, or all repeated lines.
4391 The input need not be sorted, but repeated input lines are detected
4392 only if they are adjacent.  If you want to discard non-adjacent
4393 duplicate lines, perhaps you want to use @code{sort -u}.
4394 @xref{sort invocation}.
4396 @vindex LC_COLLATE
4397 Comparisons use the character collating sequence specified by the
4398 @env{LC_COLLATE} locale category.
4400 If no @var{output} file is specified, @command{uniq} writes to standard
4401 output.
4403 The program accepts the following options.  Also see @ref{Common options}.
4405 @table @samp
4407 @item -f @var{n}
4408 @itemx --skip-fields=@var{n}
4409 @opindex -f
4410 @opindex --skip-fields
4411 Skip @var{n} fields on each line before checking for uniqueness.  Use
4412 a null string for comparison if a line has fewer than @var{n} fields.  Fields
4413 are sequences of non-space non-tab characters that are separated from
4414 each other by at least one space or tab.
4416 For compatibility @command{uniq} supports an obsolete option syntax
4417 @option{-@var{n}}.  New scripts should use @option{-f @var{n}} instead.
4419 @item -s @var{n}
4420 @itemx --skip-chars=@var{n}
4421 @opindex -s
4422 @opindex --skip-chars
4423 Skip @var{n} characters before checking for uniqueness.  Use a null string
4424 for comparison if a line has fewer than @var{n} characters.  If you use both
4425 the field and character skipping options, fields are skipped over first.
4427 @vindex _POSIX2_VERSION
4428 On older systems, @command{uniq} supports an obsolete option syntax
4429 @option{+@var{n}}.
4430 This obsolete behavior can be enabled or disabled with the
4431 @env{_POSIX2_VERSION} environment variable (@pxref{Standards
4432 conformance}), but portable scripts should avoid commands whose
4433 behavior depends on this variable.
4434 For example, use @samp{uniq ./+10} or @samp{uniq -s 10} rather than
4435 the ambiguous @samp{uniq +10}.
4437 @item -c
4438 @itemx --count
4439 @opindex -c
4440 @opindex --count
4441 Print the number of times each line occurred along with the line.
4443 @item -i
4444 @itemx --ignore-case
4445 @opindex -i
4446 @opindex --ignore-case
4447 Ignore differences in case when comparing lines.
4449 @item -d
4450 @itemx --repeated
4451 @opindex -d
4452 @opindex --repeated
4453 @cindex repeated lines, outputting
4454 Discard lines that are not repeated.  When used by itself, this option
4455 causes @command{uniq} to print the first copy of each repeated line,
4456 and nothing else.
4458 @item -D
4459 @itemx --all-repeated[=@var{delimit-method}]
4460 @opindex -D
4461 @opindex --all-repeated
4462 @cindex all repeated lines, outputting
4463 Do not discard the second and subsequent repeated input lines,
4464 but discard lines that are not repeated.
4465 This option is useful mainly in conjunction with other options e.g.,
4466 to ignore case or to compare only selected fields.
4467 The optional @var{delimit-method} tells how to delimit
4468 groups of repeated lines, and must be one of the following:
4470 @table @samp
4472 @item none
4473 Do not delimit groups of repeated lines.
4474 This is equivalent to @option{--all-repeated} (@option{-D}).
4476 @item prepend
4477 Output a newline before each group of repeated lines.
4478 With @option{--zero-terminated} (@option{-z}), use a zero
4479 byte (@acronym{ASCII} @sc{nul}) instead of a newline.
4481 @item separate
4482 Separate groups of repeated lines with a single newline.
4483 With @option{--zero-terminated} (@option{-z}), use a zero
4484 byte (@acronym{ASCII} @sc{nul}) instead of a newline.
4485 This is the same as using @samp{prepend}, except that
4486 no delimiter is inserted before the first group, and hence
4487 may be better suited for output direct to users.
4488 @end table
4490 Note that when groups are delimited and the input stream contains
4491 two or more consecutive blank lines, then the output is ambiguous.
4492 To avoid that, filter the input through @samp{tr -s '\n'} to replace
4493 each sequence of consecutive newlines with a single newline.
4495 This is a @sc{gnu} extension.
4496 @c FIXME: give an example showing *how* it's useful
4498 @item -u
4499 @itemx --unique
4500 @opindex -u
4501 @opindex --unique
4502 @cindex unique lines, outputting
4503 Discard the first repeated line.  When used by itself, this option
4504 causes @command{uniq} to print unique lines, and nothing else.
4506 @item -w @var{n}
4507 @itemx --check-chars=@var{n}
4508 @opindex -w
4509 @opindex --check-chars
4510 Compare at most @var{n} characters on each line (after skipping any specified
4511 fields and characters).  By default the entire rest of the lines are
4512 compared.
4514 @zeroTerminatedOption
4516 @end table
4518 @exitstatus
4521 @node comm invocation
4522 @section @command{comm}: Compare two sorted files line by line
4524 @pindex comm
4525 @cindex line-by-line comparison
4526 @cindex comparing sorted files
4528 @command{comm} writes to standard output lines that are common, and lines
4529 that are unique, to two input files; a file name of @samp{-} means
4530 standard input.  Synopsis:
4532 @example
4533 comm [@var{option}]@dots{} @var{file1} @var{file2}
4534 @end example
4536 @vindex LC_COLLATE
4537 Before @command{comm} can be used, the input files must be sorted using the
4538 collating sequence specified by the @env{LC_COLLATE} locale.
4539 If an input file ends in a non-newline
4540 character, a newline is silently appended.  The @command{sort} command with
4541 no options always outputs a file that is suitable input to @command{comm}.
4543 @cindex differing lines
4544 @cindex common lines
4545 With no options, @command{comm} produces three-column output.  Column one
4546 contains lines unique to @var{file1}, column two contains lines unique
4547 to @var{file2}, and column three contains lines common to both files.
4548 Columns are separated by a single TAB character.
4549 @c FIXME: when there's an option to supply an alternative separator
4550 @c string, append `by default' to the above sentence.
4552 @opindex -1
4553 @opindex -2
4554 @opindex -3
4555 The options @option{-1}, @option{-2}, and @option{-3} suppress printing of
4556 the corresponding columns.  Also see @ref{Common options}.
4558 Unlike some other comparison utilities, @command{comm} has an exit
4559 status that does not depend on the result of the comparison.
4560 Upon normal completion @command{comm} produces an exit code of zero.
4561 If there is an error it exits with nonzero status.
4563 @macro checkOrderOption{cmd}
4564 If the @option{--check-order} option is given, unsorted inputs will
4565 cause a fatal error message.  If the option @option{--nocheck-order}
4566 is given, unsorted inputs will never cause an error message.  If
4567 neither of these options is given, wrongly sorted inputs are diagnosed
4568 only if an input file is found to contain unpairable lines.  If an
4569 input file is diagnosed as being unsorted, the @command{\cmd\} command
4570 will exit with a nonzero status (and the output should not be used).
4572 Forcing @command{\cmd\} to process wrongly sorted input files
4573 containing unpairable lines by specifying @option{--nocheck-order} is
4574 not guaranteed to produce any particular output.  The output will
4575 probably not correspond with whatever you hoped it would be.
4576 @end macro
4577 @checkOrderOption{comm}
4579 @table @samp
4581 @item --check-order
4582 Fail with an error message if either input file is wrongly ordered.
4584 @item --nocheck-order
4585 Do not check that both input files are in sorted order.
4587 Other options are:
4589 @item --output-delimiter=@var{str}
4590 Print @var{str} between adjacent output columns,
4591 rather than the default of a single TAB character.
4593 The delimiter @var{str} may not be empty.
4595 @end table
4597 @node ptx invocation
4598 @section @command{ptx}: Produce permuted indexes
4600 @pindex ptx
4602 @command{ptx} reads a text file and essentially produces a permuted index, with
4603 each keyword in its context.  The calling sketch is either one of:
4605 @example
4606 ptx [@var{option} @dots{}] [@var{file} @dots{}]
4607 ptx -G [@var{option} @dots{}] [@var{input} [@var{output}]]
4608 @end example
4610 The @option{-G} (or its equivalent: @option{--traditional}) option disables
4611 all @sc{gnu} extensions and reverts to traditional mode, thus introducing some
4612 limitations and changing several of the program's default option values.
4613 When @option{-G} is not specified, @sc{gnu} extensions are always enabled.
4614 @sc{gnu} extensions to @command{ptx} are documented wherever appropriate in this
4615 document.  For the full list, see @xref{Compatibility in ptx}.
4617 Individual options are explained in the following sections.
4619 When @sc{gnu} extensions are enabled, there may be zero, one or several
4620 @var{file}s after the options.  If there is no @var{file}, the program
4621 reads the standard input.  If there is one or several @var{file}s, they
4622 give the name of input files which are all read in turn, as if all the
4623 input files were concatenated.  However, there is a full contextual
4624 break between each file and, when automatic referencing is requested,
4625 file names and line numbers refer to individual text input files.  In
4626 all cases, the program outputs the permuted index to the standard
4627 output.
4629 When @sc{gnu} extensions are @emph{not} enabled, that is, when the program
4630 operates in traditional mode, there may be zero, one or two parameters
4631 besides the options.  If there are no parameters, the program reads the
4632 standard input and outputs the permuted index to the standard output.
4633 If there is only one parameter, it names the text @var{input} to be read
4634 instead of the standard input.  If two parameters are given, they give
4635 respectively the name of the @var{input} file to read and the name of
4636 the @var{output} file to produce.  @emph{Be very careful} to note that,
4637 in this case, the contents of file given by the second parameter is
4638 destroyed.  This behavior is dictated by System V @command{ptx}
4639 compatibility; @sc{gnu} Standards normally discourage output parameters not
4640 introduced by an option.
4642 Note that for @emph{any} file named as the value of an option or as an
4643 input text file, a single dash @kbd{-} may be used, in which case
4644 standard input is assumed.  However, it would not make sense to use this
4645 convention more than once per program invocation.
4647 @menu
4648 * General options in ptx::      Options which affect general program behavior.
4649 * Charset selection in ptx::    Underlying character set considerations.
4650 * Input processing in ptx::     Input fields, contexts, and keyword selection.
4651 * Output formatting in ptx::    Types of output format, and sizing the fields.
4652 * Compatibility in ptx::
4653 @end menu
4656 @node General options in ptx
4657 @subsection General options
4659 @table @samp
4661 @item -G
4662 @itemx --traditional
4663 As already explained, this option disables all @sc{gnu} extensions to
4664 @command{ptx} and switches to traditional mode.
4666 @item --help
4667 Print a short help on standard output, then exit without further
4668 processing.
4670 @item --version
4671 Print the program version on standard output, then exit without further
4672 processing.
4674 @end table
4676 @exitstatus
4679 @node Charset selection in ptx
4680 @subsection Charset selection
4682 @c FIXME:  People don't necessarily know what an IBM-PC was these days.
4683 As it is set up now, the program assumes that the input file is coded
4684 using 8-bit @acronym{ISO} 8859-1 code, also known as Latin-1 character set,
4685 @emph{unless} it is compiled for MS-DOS, in which case it uses the
4686 character set of the IBM-PC@.  (@sc{gnu} @command{ptx} is not known to work on
4687 smaller MS-DOS machines anymore.)  Compared to 7-bit @acronym{ASCII}, the set
4688 of characters which are letters is different; this alters the behavior
4689 of regular expression matching.  Thus, the default regular expression
4690 for a keyword allows foreign or diacriticized letters.  Keyword sorting,
4691 however, is still crude; it obeys the underlying character set ordering
4692 quite blindly.
4694 @table @samp
4696 @item -f
4697 @itemx --ignore-case
4698 Fold lower case letters to upper case for sorting.
4700 @end table
4703 @node Input processing in ptx
4704 @subsection Word selection and input processing
4706 @table @samp
4708 @item -b @var{file}
4709 @itemx --break-file=@var{file}
4711 This option provides an alternative (to @option{-W}) method of describing
4712 which characters make up words.  It introduces the name of a
4713 file which contains a list of characters which can@emph{not} be part of
4714 one word; this file is called the @dfn{Break file}.  Any character which
4715 is not part of the Break file is a word constituent.  If both options
4716 @option{-b} and @option{-W} are specified, then @option{-W} has precedence and
4717 @option{-b} is ignored.
4719 When @sc{gnu} extensions are enabled, the only way to avoid newline as a
4720 break character is to write all the break characters in the file with no
4721 newline at all, not even at the end of the file.  When @sc{gnu} extensions
4722 are disabled, spaces, tabs and newlines are always considered as break
4723 characters even if not included in the Break file.
4725 @item -i @var{file}
4726 @itemx --ignore-file=@var{file}
4728 The file associated with this option contains a list of words which will
4729 never be taken as keywords in concordance output.  It is called the
4730 @dfn{Ignore file}.  The file contains exactly one word in each line; the
4731 end of line separation of words is not subject to the value of the
4732 @option{-S} option.
4734 @item -o @var{file}
4735 @itemx --only-file=@var{file}
4737 The file associated with this option contains a list of words which will
4738 be retained in concordance output; any word not mentioned in this file
4739 is ignored.  The file is called the @dfn{Only file}.  The file contains
4740 exactly one word in each line; the end of line separation of words is
4741 not subject to the value of the @option{-S} option.
4743 There is no default for the Only file.  When both an Only file and an
4744 Ignore file are specified, a word is considered a keyword only
4745 if it is listed in the Only file and not in the Ignore file.
4747 @item -r
4748 @itemx --references
4750 On each input line, the leading sequence of non-white space characters will be
4751 taken to be a reference that has the purpose of identifying this input
4752 line in the resulting permuted index.  For more information about reference
4753 production, see @xref{Output formatting in ptx}.
4754 Using this option changes the default value for option @option{-S}.
4756 Using this option, the program does not try very hard to remove
4757 references from contexts in output, but it succeeds in doing so
4758 @emph{when} the context ends exactly at the newline.  If option
4759 @option{-r} is used with @option{-S} default value, or when @sc{gnu} extensions
4760 are disabled, this condition is always met and references are completely
4761 excluded from the output contexts.
4763 @item -S @var{regexp}
4764 @itemx --sentence-regexp=@var{regexp}
4766 This option selects which regular expression will describe the end of a
4767 line or the end of a sentence.  In fact, this regular expression is not
4768 the only distinction between end of lines or end of sentences, and input
4769 line boundaries have no special significance outside this option.  By
4770 default, when @sc{gnu} extensions are enabled and if @option{-r} option is not
4771 used, end of sentences are used.  In this case, this @var{regex} is
4772 imported from @sc{gnu} Emacs:
4774 @example
4775 [.?!][]\"')@}]*\\($\\|\t\\|  \\)[ \t\n]*
4776 @end example
4778 Whenever @sc{gnu} extensions are disabled or if @option{-r} option is used, end
4779 of lines are used; in this case, the default @var{regexp} is just:
4781 @example
4783 @end example
4785 Using an empty @var{regexp} is equivalent to completely disabling end of
4786 line or end of sentence recognition.  In this case, the whole file is
4787 considered to be a single big line or sentence.  The user might want to
4788 disallow all truncation flag generation as well, through option @option{-F
4789 ""}.  @xref{Regexps, , Syntax of Regular Expressions, emacs, The GNU Emacs
4790 Manual}.
4792 When the keywords happen to be near the beginning of the input line or
4793 sentence, this often creates an unused area at the beginning of the
4794 output context line; when the keywords happen to be near the end of the
4795 input line or sentence, this often creates an unused area at the end of
4796 the output context line.  The program tries to fill those unused areas
4797 by wrapping around context in them; the tail of the input line or
4798 sentence is used to fill the unused area on the left of the output line;
4799 the head of the input line or sentence is used to fill the unused area
4800 on the right of the output line.
4802 As a matter of convenience to the user, many usual backslashed escape
4803 sequences from the C language are recognized and converted to the
4804 corresponding characters by @command{ptx} itself.
4806 @item -W @var{regexp}
4807 @itemx --word-regexp=@var{regexp}
4809 This option selects which regular expression will describe each keyword.
4810 By default, if @sc{gnu} extensions are enabled, a word is a sequence of
4811 letters; the @var{regexp} used is @samp{\w+}.  When @sc{gnu} extensions are
4812 disabled, a word is by default anything which ends with a space, a tab
4813 or a newline; the @var{regexp} used is @samp{[^ \t\n]+}.
4815 An empty @var{regexp} is equivalent to not using this option.
4816 @xref{Regexps, , Syntax of Regular Expressions, emacs, The GNU Emacs
4817 Manual}.
4819 As a matter of convenience to the user, many usual backslashed escape
4820 sequences, as found in the C language, are recognized and converted to
4821 the corresponding characters by @command{ptx} itself.
4823 @end table
4826 @node Output formatting in ptx
4827 @subsection Output formatting
4829 Output format is mainly controlled by the @option{-O} and @option{-T} options
4830 described in the table below.  When neither @option{-O} nor @option{-T} are
4831 selected, and if @sc{gnu} extensions are enabled, the program chooses an
4832 output format suitable for a dumb terminal.  Each keyword occurrence is
4833 output to the center of one line, surrounded by its left and right
4834 contexts.  Each field is properly justified, so the concordance output
4835 can be readily observed.  As a special feature, if automatic
4836 references are selected by option @option{-A} and are output before the
4837 left context, that is, if option @option{-R} is @emph{not} selected, then
4838 a colon is added after the reference; this nicely interfaces with @sc{gnu}
4839 Emacs @code{next-error} processing.  In this default output format, each
4840 white space character, like newline and tab, is merely changed to
4841 exactly one space, with no special attempt to compress consecutive
4842 spaces.  This might change in the future.  Except for those white space
4843 characters, every other character of the underlying set of 256
4844 characters is transmitted verbatim.
4846 Output format is further controlled by the following options.
4848 @table @samp
4850 @item -g @var{number}
4851 @itemx --gap-size=@var{number}
4853 Select the size of the minimum white space gap between the fields on the
4854 output line.
4856 @item -w @var{number}
4857 @itemx --width=@var{number}
4859 Select the maximum output width of each final line.  If references are
4860 used, they are included or excluded from the maximum output width
4861 depending on the value of option @option{-R}.  If this option is not
4862 selected, that is, when references are output before the left context,
4863 the maximum output width takes into account the maximum length of all
4864 references.  If this option is selected, that is, when references are
4865 output after the right context, the maximum output width does not take
4866 into account the space taken by references, nor the gap that precedes
4867 them.
4869 @item -A
4870 @itemx --auto-reference
4872 Select automatic references.  Each input line will have an automatic
4873 reference made up of the file name and the line ordinal, with a single
4874 colon between them.  However, the file name will be empty when standard
4875 input is being read.  If both @option{-A} and @option{-r} are selected, then
4876 the input reference is still read and skipped, but the automatic
4877 reference is used at output time, overriding the input reference.
4879 @item -R
4880 @itemx --right-side-refs
4882 In the default output format, when option @option{-R} is not used, any
4883 references produced by the effect of options @option{-r} or @option{-A} are
4884 placed to the far right of output lines, after the right context.  With
4885 default output format, when the @option{-R} option is specified, references
4886 are rather placed at the beginning of each output line, before the left
4887 context.  For any other output format, option @option{-R} is
4888 ignored, with one exception:  with @option{-R} the width of references
4889 is @emph{not} taken into account in total output width given by @option{-w}.
4891 This option is automatically selected whenever @sc{gnu} extensions are
4892 disabled.
4894 @item -F @var{string}
4895 @itemx --flac-truncation=@var{string}
4897 This option will request that any truncation in the output be reported
4898 using the string @var{string}.  Most output fields theoretically extend
4899 towards the beginning or the end of the current line, or current
4900 sentence, as selected with option @option{-S}.  But there is a maximum
4901 allowed output line width, changeable through option @option{-w}, which is
4902 further divided into space for various output fields.  When a field has
4903 to be truncated because it cannot extend beyond the beginning or the end of
4904 the current line to fit in, then a truncation occurs.  By default,
4905 the string used is a single slash, as in @option{-F /}.
4907 @var{string} may have more than one character, as in @option{-F ...}.
4908 Also, in the particular case when @var{string} is empty (@option{-F ""}),
4909 truncation flagging is disabled, and no truncation marks are appended in
4910 this case.
4912 As a matter of convenience to the user, many usual backslashed escape
4913 sequences, as found in the C language, are recognized and converted to
4914 the corresponding characters by @command{ptx} itself.
4916 @item -M @var{string}
4917 @itemx --macro-name=@var{string}
4919 Select another @var{string} to be used instead of @samp{xx}, while
4920 generating output suitable for @command{nroff}, @command{troff} or @TeX{}.
4922 @item -O
4923 @itemx --format=roff
4925 Choose an output format suitable for @command{nroff} or @command{troff}
4926 processing.  Each output line will look like:
4928 @smallexample
4929 .xx "@var{tail}" "@var{before}" "@var{keyword_and_after}" "@var{head}" "@var{ref}"
4930 @end smallexample
4932 so it will be possible to write a @samp{.xx} roff macro to take care of
4933 the output typesetting.  This is the default output format when @sc{gnu}
4934 extensions are disabled.  Option @option{-M} can be used to change
4935 @samp{xx} to another macro name.
4937 In this output format, each non-graphical character, like newline and
4938 tab, is merely changed to exactly one space, with no special attempt to
4939 compress consecutive spaces.  Each quote character: @kbd{"} is doubled
4940 so it will be correctly processed by @command{nroff} or @command{troff}.
4942 @item -T
4943 @itemx --format=tex
4945 Choose an output format suitable for @TeX{} processing.  Each output
4946 line will look like:
4948 @smallexample
4949 \xx @{@var{tail}@}@{@var{before}@}@{@var{keyword}@}@{@var{after}@}@{@var{head}@}@{@var{ref}@}
4950 @end smallexample
4952 @noindent
4953 so it will be possible to write a @code{\xx} definition to take care of
4954 the output typesetting.  Note that when references are not being
4955 produced, that is, neither option @option{-A} nor option @option{-r} is
4956 selected, the last parameter of each @code{\xx} call is inhibited.
4957 Option @option{-M} can be used to change @samp{xx} to another macro
4958 name.
4960 In this output format, some special characters, like @kbd{$}, @kbd{%},
4961 @kbd{&}, @kbd{#} and @kbd{_} are automatically protected with a
4962 backslash.  Curly brackets @kbd{@{}, @kbd{@}} are protected with a
4963 backslash and a pair of dollar signs (to force mathematical mode).  The
4964 backslash itself produces the sequence @code{\backslash@{@}}.
4965 Circumflex and tilde diacritical marks produce the sequence @code{^\@{ @}} and
4966 @code{~\@{ @}} respectively.  Other diacriticized characters of the
4967 underlying character set produce an appropriate @TeX{} sequence as far
4968 as possible.  The other non-graphical characters, like newline and tab,
4969 and all other characters which are not part of @acronym{ASCII}, are merely
4970 changed to exactly one space, with no special attempt to compress
4971 consecutive spaces.  Let me know how to improve this special character
4972 processing for @TeX{}.
4974 @end table
4977 @node Compatibility in ptx
4978 @subsection The @sc{gnu} extensions to @command{ptx}
4980 This version of @command{ptx} contains a few features which do not exist in
4981 System V @command{ptx}.  These extra features are suppressed by using the
4982 @option{-G} command line option, unless overridden by other command line
4983 options.  Some @sc{gnu} extensions cannot be recovered by overriding, so the
4984 simple rule is to avoid @option{-G} if you care about @sc{gnu} extensions.
4985 Here are the differences between this program and System V @command{ptx}.
4987 @itemize @bullet
4989 @item
4990 This program can read many input files at once, it always writes the
4991 resulting concordance on standard output.  On the other hand, System V
4992 @command{ptx} reads only one file and sends the result to standard output
4993 or, if a second @var{file} parameter is given on the command, to that
4994 @var{file}.
4996 Having output parameters not introduced by options is a dangerous
4997 practice which @sc{gnu} avoids as far as possible.  So, for using @command{ptx}
4998 portably between @sc{gnu} and System V, you should always use it with a
4999 single input file, and always expect the result on standard output.  You
5000 might also want to automatically configure in a @option{-G} option to
5001 @command{ptx} calls in products using @command{ptx}, if the configurator finds
5002 that the installed @command{ptx} accepts @option{-G}.
5004 @item
5005 The only options available in System V @command{ptx} are options @option{-b},
5006 @option{-f}, @option{-g}, @option{-i}, @option{-o}, @option{-r}, @option{-t} and
5007 @option{-w}.  All other options are @sc{gnu} extensions and are not repeated in
5008 this enumeration.  Moreover, some options have a slightly different
5009 meaning when @sc{gnu} extensions are enabled, as explained below.
5011 @item
5012 By default, concordance output is not formatted for @command{troff} or
5013 @command{nroff}.  It is rather formatted for a dumb terminal.  @command{troff}
5014 or @command{nroff} output may still be selected through option @option{-O}.
5016 @item
5017 Unless @option{-R} option is used, the maximum reference width is
5018 subtracted from the total output line width.  With @sc{gnu} extensions
5019 disabled, width of references is not taken into account in the output
5020 line width computations.
5022 @item
5023 All 256 bytes, even @acronym{ASCII} @sc{nul} bytes, are always read and
5024 processed from input file with no adverse effect, even if @sc{gnu} extensions
5025 are disabled. However, System V @command{ptx} does not accept 8-bit characters,
5026 a few control characters are rejected, and the tilde @kbd{~} is also rejected.
5028 @item
5029 Input line length is only limited by available memory, even if @sc{gnu}
5030 extensions are disabled.  However, System V @command{ptx} processes only
5031 the first 200 characters in each line.
5033 @item
5034 The break (non-word) characters default to be every character except all
5035 letters of the underlying character set, diacriticized or not.  When @sc{gnu}
5036 extensions are disabled, the break characters default to space, tab and
5037 newline only.
5039 @item
5040 The program makes better use of output line width.  If @sc{gnu} extensions
5041 are disabled, the program rather tries to imitate System V @command{ptx},
5042 but still, there are some slight disposition glitches this program does
5043 not completely reproduce.
5045 @item
5046 The user can specify both an Ignore file and an Only file.  This is not
5047 allowed with System V @command{ptx}.
5049 @end itemize
5052 @node tsort invocation
5053 @section @command{tsort}: Topological sort
5055 @pindex tsort
5056 @cindex topological sort
5058 @command{tsort} performs a topological sort on the given @var{file}, or
5059 standard input if no input file is given or for a @var{file} of
5060 @samp{-}.  For more details and some history, see @ref{tsort background}.
5061 Synopsis:
5063 @example
5064 tsort [@var{option}] [@var{file}]
5065 @end example
5067 @command{tsort} reads its input as pairs of strings, separated by blanks,
5068 indicating a partial ordering.  The output is a total ordering that
5069 corresponds to the given partial ordering.
5071 For example
5073 @example
5074 tsort <<EOF
5075 a b c
5077 e f
5078 b c d e
5080 @end example
5082 @noindent
5083 will produce the output
5085 @example
5092 @end example
5094 Consider a more realistic example.
5095 You have a large set of functions all in one file, and they may all be
5096 declared static except one.  Currently that one (say @code{main}) is the
5097 first function defined in the file, and the ones it calls directly follow
5098 it, followed by those they call, etc.  Let's say that you are determined
5099 to take advantage of prototypes, so you have to choose between declaring
5100 all of those functions (which means duplicating a lot of information from
5101 the definitions) and rearranging the functions so that as many as possible
5102 are defined before they are used.  One way to automate the latter process
5103 is to get a list for each function of the functions it calls directly.
5104 Many programs can generate such lists.  They describe a call graph.
5105 Consider the following list, in which a given line indicates that the
5106 function on the left calls the one on the right directly.
5108 @example
5109 main parse_options
5110 main tail_file
5111 main tail_forever
5112 tail_file pretty_name
5113 tail_file write_header
5114 tail_file tail
5115 tail_forever recheck
5116 tail_forever pretty_name
5117 tail_forever write_header
5118 tail_forever dump_remainder
5119 tail tail_lines
5120 tail tail_bytes
5121 tail_lines start_lines
5122 tail_lines dump_remainder
5123 tail_lines file_lines
5124 tail_lines pipe_lines
5125 tail_bytes xlseek
5126 tail_bytes start_bytes
5127 tail_bytes dump_remainder
5128 tail_bytes pipe_bytes
5129 file_lines dump_remainder
5130 recheck pretty_name
5131 @end example
5133 then you can use @command{tsort} to produce an ordering of those
5134 functions that satisfies your requirement.
5136 @example
5137 example$ tsort call-graph | tac
5138 dump_remainder
5139 start_lines
5140 file_lines
5141 pipe_lines
5142 xlseek
5143 start_bytes
5144 pipe_bytes
5145 tail_lines
5146 tail_bytes
5147 pretty_name
5148 write_header
5149 tail
5150 recheck
5151 parse_options
5152 tail_file
5153 tail_forever
5154 main
5155 @end example
5157 @command{tsort} detects any cycles in the input and writes the first cycle
5158 encountered to standard error.
5160 Note that for a given partial ordering, generally there is no unique
5161 total ordering.  In the context of the call graph above, the function
5162 @code{parse_options} may be placed anywhere in the list as long as it
5163 precedes @code{main}.
5165 The only options are @option{--help} and @option{--version}.  @xref{Common
5166 options}.
5168 @exitstatus
5170 @menu
5171 * tsort background::            Where tsort came from.
5172 @end menu
5174 @node tsort background
5175 @subsection @command{tsort}: Background
5177 @command{tsort} exists because very early versions of the Unix linker processed
5178 an archive file exactly once, and in order.  As @command{ld} read each object
5179 in the archive, it decided whether it was needed in the program based on
5180 whether it defined any symbols which were undefined at that point in
5181 the link.
5183 This meant that dependencies within the archive had to be handled
5184 specially.  For example, @code{scanf} probably calls @code{read}.  That means
5185 that in a single pass through an archive, it was important for @code{scanf.o}
5186 to appear before read.o, because otherwise a program which calls
5187 @code{scanf} but not @code{read} might end up with an unexpected unresolved
5188 reference to @code{read}.
5190 The way to address this problem was to first generate a set of
5191 dependencies of one object file on another.  This was done by a shell
5192 script called @command{lorder}.  The GNU tools don't provide a version of
5193 lorder, as far as I know, but you can still find it in BSD
5194 distributions.
5196 Then you ran @command{tsort} over the @command{lorder} output, and you used the
5197 resulting sort to define the order in which you added objects to the archive.
5199 This whole procedure has been obsolete since about 1980, because
5200 Unix archives now contain a symbol table (traditionally built by
5201 @command{ranlib}, now generally built by @command{ar} itself), and the Unix
5202 linker uses the symbol table to effectively make multiple passes over
5203 an archive file.
5205 Anyhow, that's where tsort came from.  To solve an old problem with
5206 the way the linker handled archive files, which has since been solved
5207 in different ways.
5210 @node Operating on fields within a line
5211 @chapter Operating on fields within a line
5213 @menu
5214 * cut invocation::              Print selected parts of lines.
5215 * paste invocation::            Merge lines of files.
5216 * join invocation::             Join lines on a common field.
5217 @end menu
5220 @node cut invocation
5221 @section @command{cut}: Print selected parts of lines
5223 @pindex cut
5224 @command{cut} writes to standard output selected parts of each line of each
5225 input file, or standard input if no files are given or for a file name of
5226 @samp{-}.  Synopsis:
5228 @example
5229 cut @var{option}@dots{} [@var{file}]@dots{}
5230 @end example
5232 In the table which follows, the @var{byte-list}, @var{character-list},
5233 and @var{field-list} are one or more numbers or ranges (two numbers
5234 separated by a dash) separated by commas.  Bytes, characters, and
5235 fields are numbered starting at 1.  Incomplete ranges may be
5236 given: @option{-@var{m}} means @samp{1-@var{m}}; @samp{@var{n}-} means
5237 @samp{@var{n}} through end of line or last field.  The list elements
5238 can be repeated, can overlap, and can be specified in any order; but
5239 the selected input is written in the same order that it is read, and
5240 is written exactly once.
5242 The program accepts the following options.  Also see @ref{Common
5243 options}.
5245 @table @samp
5247 @item -b @var{byte-list}
5248 @itemx --bytes=@var{byte-list}
5249 @opindex -b
5250 @opindex --bytes
5251 Select for printing only the bytes in positions listed in
5252 @var{byte-list}.  Tabs and backspaces are treated like any other
5253 character; they take up 1 byte.  If an output delimiter is specified,
5254 (see the description of @option{--output-delimiter}), then output that
5255 string between ranges of selected bytes.
5257 @item -c @var{character-list}
5258 @itemx --characters=@var{character-list}
5259 @opindex -c
5260 @opindex --characters
5261 Select for printing only the characters in positions listed in
5262 @var{character-list}.  The same as @option{-b} for now, but
5263 internationalization will change that.  Tabs and backspaces are
5264 treated like any other character; they take up 1 character.  If an
5265 output delimiter is specified, (see the description of
5266 @option{--output-delimiter}), then output that string between ranges
5267 of selected bytes.
5269 @item -f @var{field-list}
5270 @itemx --fields=@var{field-list}
5271 @opindex -f
5272 @opindex --fields
5273 Select for printing only the fields listed in @var{field-list}.
5274 Fields are separated by a TAB character by default.  Also print any
5275 line that contains no delimiter character, unless the
5276 @option{--only-delimited} (@option{-s}) option is specified
5278 @item -d @var{input_delim_byte}
5279 @itemx --delimiter=@var{input_delim_byte}
5280 @opindex -d
5281 @opindex --delimiter
5282 With @option{-f}, use the first byte of @var{input_delim_byte} as
5283 the input fields separator (default is TAB).
5285 @item -n
5286 @opindex -n
5287 Do not split multi-byte characters (no-op for now).
5289 @item -s
5290 @itemx --only-delimited
5291 @opindex -s
5292 @opindex --only-delimited
5293 For @option{-f}, do not print lines that do not contain the field separator
5294 character.  Normally, any line without a field separator is printed verbatim.
5296 @item --output-delimiter=@var{output_delim_string}
5297 @opindex --output-delimiter
5298 With @option{-f}, output fields are separated by @var{output_delim_string}.
5299 The default with @option{-f} is to use the input delimiter.
5300 When using @option{-b} or @option{-c} to select ranges of byte or
5301 character offsets (as opposed to ranges of fields),
5302 output @var{output_delim_string} between non-overlapping
5303 ranges of selected bytes.
5305 @item --complement
5306 @opindex --complement
5307 This option is a @acronym{GNU} extension.
5308 Select for printing the complement of the bytes, characters or fields
5309 selected with the @option{-b}, @option{-c} or @option{-f} options.
5310 In other words, do @emph{not} print the bytes, characters or fields
5311 specified via those options.  This option is useful when you have
5312 many fields and want to print all but a few of them.
5314 @end table
5316 @exitstatus
5319 @node paste invocation
5320 @section @command{paste}: Merge lines of files
5322 @pindex paste
5323 @cindex merging files
5325 @command{paste} writes to standard output lines consisting of sequentially
5326 corresponding lines of each given file, separated by a TAB character.
5327 Standard input is used for a file name of @samp{-} or if no input files
5328 are given.
5330 For example:
5332 @example
5333 $ cat num2
5336 $ cat let3
5340 $ paste num2 let3
5341 1       a
5342 2       b
5343        @ c
5344 @end example
5346 Synopsis:
5348 @example
5349 paste [@var{option}]@dots{} [@var{file}]@dots{}
5350 @end example
5352 The program accepts the following options.  Also see @ref{Common options}.
5354 @table @samp
5356 @item -s
5357 @itemx --serial
5358 @opindex -s
5359 @opindex --serial
5360 Paste the lines of one file at a time rather than one line from each
5361 file.  Using the above example data:
5363 @example
5364 $ paste -s num2 let3
5365 1       2
5366 a       b       c
5367 @end example
5369 @item -d @var{delim-list}
5370 @itemx --delimiters=@var{delim-list}
5371 @opindex -d
5372 @opindex --delimiters
5373 Consecutively use the characters in @var{delim-list} instead of
5374 TAB to separate merged lines.  When @var{delim-list} is
5375 exhausted, start again at its beginning.  Using the above example data:
5377 @example
5378 $ paste -d '%_' num2 let3 num2
5379 1%a_1
5380 2%b_2
5382 @end example
5384 @end table
5386 @exitstatus
5389 @node join invocation
5390 @section @command{join}: Join lines on a common field
5392 @pindex join
5393 @cindex common field, joining on
5395 @command{join} writes to standard output a line for each pair of input
5396 lines that have identical join fields.  Synopsis:
5398 @example
5399 join [@var{option}]@dots{} @var{file1} @var{file2}
5400 @end example
5402 Either @var{file1} or @var{file2} (but not both) can be @samp{-},
5403 meaning standard input.  @var{file1} and @var{file2} should be
5404 sorted on the join fields.
5406 @vindex LC_COLLATE
5407 Normally, the sort order is that of the
5408 collating sequence specified by the @env{LC_COLLATE} locale.  Unless
5409 the @option{-t} option is given, the sort comparison ignores blanks at
5410 the start of the join field, as in @code{sort -b}.  If the
5411 @option{--ignore-case} option is given, the sort comparison ignores
5412 the case of characters in the join field, as in @code{sort -f}.
5414 The @command{sort} and @command{join} commands should use consistent
5415 locales and options if the output of @command{sort} is fed to
5416 @command{join}.  You can use a command like @samp{sort -k 1b,1} to
5417 sort a file on its default join field, but if you select a non-default
5418 locale, join field, separator, or comparison options, then you should
5419 do so consistently between @command{join} and @command{sort}.
5421 If the input has no unpairable lines, a @acronym{GNU} extension is
5422 available; the sort order can be any order that considers two fields
5423 to be equal if and only if the sort comparison described above
5424 considers them to be equal.  For example:
5426 @example
5427 $ cat file1
5428 a a1
5429 c c1
5430 b b1
5431 $ cat file2
5432 a a2
5433 c c2
5434 b b2
5435 $ join file1 file2
5436 a a1 a2
5437 c c1 c2
5438 b b1 b2
5439 @end example
5441 @checkOrderOption{join}
5443 The defaults are:
5444 @itemize
5445 @item the join field is the first field in each line;
5446 @item fields in the input are separated by one or more blanks, with leading
5447 blanks on the line ignored;
5448 @item fields in the output are separated by a space;
5449 @item each output line consists of the join field, the remaining
5450 fields from @var{file1}, then the remaining fields from @var{file2}.
5451 @end itemize
5453 The program accepts the following options.  Also see @ref{Common options}.
5455 @table @samp
5457 @item -a @var{file-number}
5458 @opindex -a
5459 Print a line for each unpairable line in file @var{file-number} (either
5460 @samp{1} or @samp{2}), in addition to the normal output.
5462 @item --check-order
5463 Fail with an error message if either input file is wrongly ordered.
5465 @item --nocheck-order
5466 Do not check that both input files are in sorted order.  This is the default.
5468 @item -e @var{string}
5469 @opindex -e
5470 Replace those output fields that are missing in the input with
5471 @var{string}.
5473 @item -i
5474 @itemx --ignore-case
5475 @opindex -i
5476 @opindex --ignore-case
5477 Ignore differences in case when comparing keys.
5478 With this option, the lines of the input files must be ordered in the same way.
5479 Use @samp{sort -f} to produce this ordering.
5481 @item -1 @var{field}
5482 @opindex -1
5483 Join on field @var{field} (a positive integer) of file 1.
5485 @item -2 @var{field}
5486 @opindex -2
5487 Join on field @var{field} (a positive integer) of file 2.
5489 @item -j @var{field}
5490 Equivalent to @option{-1 @var{field} -2 @var{field}}.
5492 @item -o @var{field-list}
5493 Construct each output line according to the format in @var{field-list}.
5494 Each element in @var{field-list} is either the single character @samp{0} or
5495 has the form @var{m.n} where the file number, @var{m}, is @samp{1} or
5496 @samp{2} and @var{n} is a positive field number.
5498 A field specification of @samp{0} denotes the join field.
5499 In most cases, the functionality of the @samp{0} field spec
5500 may be reproduced using the explicit @var{m.n} that corresponds
5501 to the join field.  However, when printing unpairable lines
5502 (using either of the @option{-a} or @option{-v} options), there is no way
5503 to specify the join field using @var{m.n} in @var{field-list}
5504 if there are unpairable lines in both files.
5505 To give @command{join} that functionality, @acronym{POSIX} invented the @samp{0}
5506 field specification notation.
5508 The elements in @var{field-list}
5509 are separated by commas or blanks.
5510 Blank separators typically need to be quoted for the shell.  For
5511 example, the commands @samp{join -o 1.2,2.2} and @samp{join -o '1.2
5512 2.2'} are equivalent.
5514 All output lines---including those printed because of any -a or -v
5515 option---are subject to the specified @var{field-list}.
5517 @item -t @var{char}
5518 Use character @var{char} as the input and output field separator.
5519 Treat as significant each occurrence of @var{char} in the input file.
5520 Use @samp{sort -t @var{char}}, without the @option{-b} option of
5521 @samp{sort}, to produce this ordering.
5523 @item -v @var{file-number}
5524 Print a line for each unpairable line in file @var{file-number}
5525 (either @samp{1} or @samp{2}), instead of the normal output.
5527 @end table
5529 @exitstatus
5532 @node Operating on characters
5533 @chapter Operating on characters
5535 @cindex operating on characters
5537 This commands operate on individual characters.
5539 @menu
5540 * tr invocation::               Translate, squeeze, and/or delete characters.
5541 * expand invocation::           Convert tabs to spaces.
5542 * unexpand invocation::         Convert spaces to tabs.
5543 @end menu
5546 @node tr invocation
5547 @section @command{tr}: Translate, squeeze, and/or delete characters
5549 @pindex tr
5551 Synopsis:
5553 @example
5554 tr [@var{option}]@dots{} @var{set1} [@var{set2}]
5555 @end example
5557 @command{tr} copies standard input to standard output, performing
5558 one of the following operations:
5560 @itemize @bullet
5561 @item
5562 translate, and optionally squeeze repeated characters in the result,
5563 @item
5564 squeeze repeated characters,
5565 @item
5566 delete characters,
5567 @item
5568 delete characters, then squeeze repeated characters from the result.
5569 @end itemize
5571 The @var{set1} and (if given) @var{set2} arguments define ordered
5572 sets of characters, referred to below as @var{set1} and @var{set2}.  These
5573 sets are the characters of the input that @command{tr} operates on.
5574 The @option{--complement} (@option{-c}, @option{-C}) option replaces
5575 @var{set1} with its
5576 complement (all of the characters that are not in @var{set1}).
5578 Currently @command{tr} fully supports only single-byte characters.
5579 Eventually it will support multibyte characters; when it does, the
5580 @option{-C} option will cause it to complement the set of characters,
5581 whereas @option{-c} will cause it to complement the set of values.
5582 This distinction will matter only when some values are not characters,
5583 and this is possible only in locales using multibyte encodings when
5584 the input contains encoding errors.
5586 The program accepts the @option{--help} and @option{--version}
5587 options.  @xref{Common options}.  Options must precede operands.
5589 @exitstatus
5591 @menu
5592 * Character sets::              Specifying sets of characters.
5593 * Translating::                 Changing one set of characters to another.
5594 * Squeezing::                   Squeezing repeats and deleting.
5595 @end menu
5598 @node Character sets
5599 @subsection Specifying sets of characters
5601 @cindex specifying sets of characters
5603 The format of the @var{set1} and @var{set2} arguments resembles
5604 the format of regular expressions; however, they are not regular
5605 expressions, only lists of characters.  Most characters simply
5606 represent themselves in these strings, but the strings can contain
5607 the shorthands listed below, for convenience.  Some of them can be
5608 used only in @var{set1} or @var{set2}, as noted below.
5610 @table @asis
5612 @item Backslash escapes
5613 @cindex backslash escapes
5615 The following backslash escape sequences are recognized:
5617 @table @samp
5618 @item \a
5619 Control-G.
5620 @item \b
5621 Control-H.
5622 @item \f
5623 Control-L.
5624 @item \n
5625 Control-J.
5626 @item \r
5627 Control-M.
5628 @item \t
5629 Control-I.
5630 @item \v
5631 Control-K.
5632 @item \@var{ooo}
5633 The character with the value given by @var{ooo}, which is 1 to 3
5634 octal digits,
5635 @item \\
5636 A backslash.
5637 @end table
5639 While a backslash followed by a character not listed above is
5640 interpreted as that character, the backslash also effectively
5641 removes any special significance, so it is useful to escape
5642 @samp{[}, @samp{]}, @samp{*}, and @samp{-}.
5644 @item Ranges
5645 @cindex ranges
5647 The notation @samp{@var{m}-@var{n}} expands to all of the characters
5648 from @var{m} through @var{n}, in ascending order.  @var{m} should
5649 collate before @var{n}; if it doesn't, an error results.  As an example,
5650 @samp{0-9} is the same as @samp{0123456789}.
5652 @sc{gnu} @command{tr} does not support the System V syntax that uses square
5653 brackets to enclose ranges.  Translations specified in that format
5654 sometimes work as expected, since the brackets are often transliterated
5655 to themselves.  However, they should be avoided because they sometimes
5656 behave unexpectedly.  For example, @samp{tr -d '[0-9]'} deletes brackets
5657 as well as digits.
5659 Many historically common and even accepted uses of ranges are not
5660 portable.  For example, on @acronym{EBCDIC} hosts using the @samp{A-Z}
5661 range will not do what most would expect because @samp{A} through @samp{Z}
5662 are not contiguous as they are in @acronym{ASCII}.
5663 If you can rely on a @acronym{POSIX} compliant version of @command{tr}, then
5664 the best way to work around this is to use character classes (see below).
5665 Otherwise, it is most portable (and most ugly) to enumerate the members
5666 of the ranges.
5668 @item Repeated characters
5669 @cindex repeated characters
5671 The notation @samp{[@var{c}*@var{n}]} in @var{set2} expands to @var{n}
5672 copies of character @var{c}.  Thus, @samp{[y*6]} is the same as
5673 @samp{yyyyyy}.  The notation @samp{[@var{c}*]} in @var{string2} expands
5674 to as many copies of @var{c} as are needed to make @var{set2} as long as
5675 @var{set1}.  If @var{n} begins with @samp{0}, it is interpreted in
5676 octal, otherwise in decimal.
5678 @item Character classes
5679 @cindex character classes
5681 The notation @samp{[:@var{class}:]} expands to all of the characters in
5682 the (predefined) class @var{class}.  The characters expand in no
5683 particular order, except for the @code{upper} and @code{lower} classes,
5684 which expand in ascending order.  When the @option{--delete} (@option{-d})
5685 and @option{--squeeze-repeats} (@option{-s}) options are both given, any
5686 character class can be used in @var{set2}.  Otherwise, only the
5687 character classes @code{lower} and @code{upper} are accepted in
5688 @var{set2}, and then only if the corresponding character class
5689 (@code{upper} and @code{lower}, respectively) is specified in the same
5690 relative position in @var{set1}.  Doing this specifies case conversion.
5691 The class names are given below; an error results when an invalid class
5692 name is given.
5694 @table @code
5695 @item alnum
5696 @opindex alnum
5697 Letters and digits.
5698 @item alpha
5699 @opindex alpha
5700 Letters.
5701 @item blank
5702 @opindex blank
5703 Horizontal whitespace.
5704 @item cntrl
5705 @opindex cntrl
5706 Control characters.
5707 @item digit
5708 @opindex digit
5709 Digits.
5710 @item graph
5711 @opindex graph
5712 Printable characters, not including space.
5713 @item lower
5714 @opindex lower
5715 Lowercase letters.
5716 @item print
5717 @opindex print
5718 Printable characters, including space.
5719 @item punct
5720 @opindex punct
5721 Punctuation characters.
5722 @item space
5723 @opindex space
5724 Horizontal or vertical whitespace.
5725 @item upper
5726 @opindex upper
5727 Uppercase letters.
5728 @item xdigit
5729 @opindex xdigit
5730 Hexadecimal digits.
5731 @end table
5733 @item Equivalence classes
5734 @cindex equivalence classes
5736 The syntax @samp{[=@var{c}=]} expands to all of the characters that are
5737 equivalent to @var{c}, in no particular order.  Equivalence classes are
5738 a relatively recent invention intended to support non-English alphabets.
5739 But there seems to be no standard way to define them or determine their
5740 contents.  Therefore, they are not fully implemented in @sc{gnu} @command{tr};
5741 each character's equivalence class consists only of that character,
5742 which is of no particular use.
5744 @end table
5747 @node Translating
5748 @subsection Translating
5750 @cindex translating characters
5752 @command{tr} performs translation when @var{set1} and @var{set2} are
5753 both given and the @option{--delete} (@option{-d}) option is not given.
5754 @command{tr} translates each character of its input that is in @var{set1}
5755 to the corresponding character in @var{set2}.  Characters not in
5756 @var{set1} are passed through unchanged.  When a character appears more
5757 than once in @var{set1} and the corresponding characters in @var{set2}
5758 are not all the same, only the final one is used.  For example, these
5759 two commands are equivalent:
5761 @example
5762 tr aaa xyz
5763 tr a z
5764 @end example
5766 A common use of @command{tr} is to convert lowercase characters to
5767 uppercase.  This can be done in many ways.  Here are three of them:
5769 @example
5770 tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
5771 tr a-z A-Z
5772 tr '[:lower:]' '[:upper:]'
5773 @end example
5775 @noindent
5776 But note that using ranges like @code{a-z} above is not portable.
5778 When @command{tr} is performing translation, @var{set1} and @var{set2}
5779 typically have the same length.  If @var{set1} is shorter than
5780 @var{set2}, the extra characters at the end of @var{set2} are ignored.
5782 On the other hand, making @var{set1} longer than @var{set2} is not
5783 portable; @acronym{POSIX} says that the result is undefined.  In this situation,
5784 BSD @command{tr} pads @var{set2} to the length of @var{set1} by repeating
5785 the last character of @var{set2} as many times as necessary.  System V
5786 @command{tr} truncates @var{set1} to the length of @var{set2}.
5788 By default, @sc{gnu} @command{tr} handles this case like BSD @command{tr}.
5789 When the @option{--truncate-set1} (@option{-t}) option is given,
5790 @sc{gnu} @command{tr} handles this case like the System V @command{tr}
5791 instead.  This option is ignored for operations other than translation.
5793 Acting like System V @command{tr} in this case breaks the relatively common
5794 BSD idiom:
5796 @example
5797 tr -cs A-Za-z0-9 '\012'
5798 @end example
5800 @noindent
5801 because it converts only zero bytes (the first element in the
5802 complement of @var{set1}), rather than all non-alphanumerics, to
5803 newlines.
5805 @noindent
5806 By the way, the above idiom is not portable because it uses ranges, and
5807 it assumes that the octal code for newline is 012.
5808 Assuming a @acronym{POSIX} compliant @command{tr}, here is a better way to write it:
5810 @example
5811 tr -cs '[:alnum:]' '[\n*]'
5812 @end example
5815 @node Squeezing
5816 @subsection Squeezing repeats and deleting
5818 @cindex squeezing repeat characters
5819 @cindex deleting characters
5821 When given just the @option{--delete} (@option{-d}) option, @command{tr}
5822 removes any input characters that are in @var{set1}.
5824 When given just the @option{--squeeze-repeats} (@option{-s}) option,
5825 @command{tr} replaces each input sequence of a repeated character that
5826 is in @var{set1} with a single occurrence of that character.
5828 When given both @option{--delete} and @option{--squeeze-repeats}, @command{tr}
5829 first performs any deletions using @var{set1}, then squeezes repeats
5830 from any remaining characters using @var{set2}.
5832 The @option{--squeeze-repeats} option may also be used when translating,
5833 in which case @command{tr} first performs translation, then squeezes
5834 repeats from any remaining characters using @var{set2}.
5836 Here are some examples to illustrate various combinations of options:
5838 @itemize @bullet
5840 @item
5841 Remove all zero bytes:
5843 @example
5844 tr -d '\0'
5845 @end example
5847 @item
5848 Put all words on lines by themselves.  This converts all
5849 non-alphanumeric characters to newlines, then squeezes each string
5850 of repeated newlines into a single newline:
5852 @example
5853 tr -cs '[:alnum:]' '[\n*]'
5854 @end example
5856 @item
5857 Convert each sequence of repeated newlines to a single newline:
5859 @example
5860 tr -s '\n'
5861 @end example
5863 @item
5864 Find doubled occurrences of words in a document.
5865 @c Separate the following two "the"s, so typo checkers don't complain.
5866 For example, people often write ``the @w{}the'' with the repeated words
5867 separated by a newline.  The Bourne shell script below works first
5868 by converting each sequence of punctuation and blank characters to a
5869 single newline.  That puts each ``word'' on a line by itself.
5870 Next it maps all uppercase characters to lower case, and finally it
5871 runs @command{uniq} with the @option{-d} option to print out only the words
5872 that were repeated.
5874 @example
5875 #!/bin/sh
5876 cat -- "$@@" \
5877   | tr -s '[:punct:][:blank:]' '[\n*]' \
5878   | tr '[:upper:]' '[:lower:]' \
5879   | uniq -d
5880 @end example
5882 @item
5883 Deleting a small set of characters is usually straightforward.  For example,
5884 to remove all @samp{a}s, @samp{x}s, and @samp{M}s you would do this:
5886 @example
5887 tr -d axM
5888 @end example
5890 However, when @samp{-} is one of those characters, it can be tricky because
5891 @samp{-} has special meanings.  Performing the same task as above but also
5892 removing all @samp{-} characters, we might try @code{tr -d -axM}, but
5893 that would fail because @command{tr} would try to interpret @option{-a} as
5894 a command-line option.  Alternatively, we could try putting the hyphen
5895 inside the string, @code{tr -d a-xM}, but that wouldn't work either because
5896 it would make @command{tr} interpret @code{a-x} as the range of characters
5897 @samp{a}@dots{}@samp{x} rather than the three.
5898 One way to solve the problem is to put the hyphen at the end of the list
5899 of characters:
5901 @example
5902 tr -d axM-
5903 @end example
5905 Or you can use @samp{--} to terminate option processing:
5907 @example
5908 tr -d -- -axM
5909 @end example
5911 More generally, use the character class notation @code{[=c=]}
5912 with @samp{-} (or any other character) in place of the @samp{c}:
5914 @example
5915 tr -d '[=-=]axM'
5916 @end example
5918 Note how single quotes are used in the above example to protect the
5919 square brackets from interpretation by a shell.
5921 @end itemize
5924 @node expand invocation
5925 @section @command{expand}: Convert tabs to spaces
5927 @pindex expand
5928 @cindex tabs to spaces, converting
5929 @cindex converting tabs to spaces
5931 @command{expand} writes the contents of each given @var{file}, or standard
5932 input if none are given or for a @var{file} of @samp{-}, to standard
5933 output, with tab characters converted to the appropriate number of
5934 spaces.  Synopsis:
5936 @example
5937 expand [@var{option}]@dots{} [@var{file}]@dots{}
5938 @end example
5940 By default, @command{expand} converts all tabs to spaces.  It preserves
5941 backspace characters in the output; they decrement the column count for
5942 tab calculations.  The default action is equivalent to @option{-t 8} (set
5943 tabs every 8 columns).
5945 The program accepts the following options.  Also see @ref{Common options}.
5947 @table @samp
5949 @item -t @var{tab1}[,@var{tab2}]@dots{}
5950 @itemx --tabs=@var{tab1}[,@var{tab2}]@dots{}
5951 @opindex -t
5952 @opindex --tabs
5953 @cindex tab stops, setting
5954 If only one tab stop is given, set the tabs @var{tab1} spaces apart
5955 (default is 8).  Otherwise, set the tabs at columns @var{tab1},
5956 @var{tab2}, @dots{} (numbered from 0), and replace any tabs beyond the
5957 last tab stop given with single spaces.  Tab stops can be separated by
5958 blanks as well as by commas.
5960 For compatibility, GNU @command{expand} also accepts the obsolete
5961 option syntax, @option{-@var{t1}[,@var{t2}]@dots{}}.  New scripts
5962 should use @option{-t @var{t1}[,@var{t2}]@dots{}} instead.
5964 @item -i
5965 @itemx --initial
5966 @opindex -i
5967 @opindex --initial
5968 @cindex initial tabs, converting
5969 Only convert initial tabs (those that precede all non-space or non-tab
5970 characters) on each line to spaces.
5972 @end table
5974 @exitstatus
5977 @node unexpand invocation
5978 @section @command{unexpand}: Convert spaces to tabs
5980 @pindex unexpand
5982 @command{unexpand} writes the contents of each given @var{file}, or
5983 standard input if none are given or for a @var{file} of @samp{-}, to
5984 standard output, converting blanks at the beginning of each line into
5985 as many tab characters as needed.  In the default @acronym{POSIX}
5986 locale, a @dfn{blank} is a space or a tab; other locales may specify
5987 additional blank characters.  Synopsis:
5989 @example
5990 unexpand [@var{option}]@dots{} [@var{file}]@dots{}
5991 @end example
5993 By default, @command{unexpand} converts only initial blanks (those
5994 that precede all non-blank characters) on each line.  It
5995 preserves backspace characters in the output; they decrement the column
5996 count for tab calculations.  By default, tabs are set at every 8th
5997 column.
5999 The program accepts the following options.  Also see @ref{Common options}.
6001 @table @samp
6003 @item -t @var{tab1}[,@var{tab2}]@dots{}
6004 @itemx --tabs=@var{tab1}[,@var{tab2}]@dots{}
6005 @opindex -t
6006 @opindex --tabs
6007 If only one tab stop is given, set the tabs @var{tab1} columns apart
6008 instead of the default 8.  Otherwise, set the tabs at columns
6009 @var{tab1}, @var{tab2}, @dots{} (numbered from 0), and leave blanks
6010 beyond the tab stops given unchanged.  Tab stops can be separated by
6011 blanks as well as by commas.  This option implies the @option{-a} option.
6013 For compatibility, GNU @command{unexpand} supports the obsolete option syntax,
6014 @option{-@var{tab1}[,@var{tab2}]@dots{}}, where tab stops must be
6015 separated by commas.  (Unlike @option{-t}, this obsolete option does
6016 not imply @option{-a}.)  New scripts should use @option{--first-only -t
6017 @var{tab1}[,@var{tab2}]@dots{}} instead.
6019 @item -a
6020 @itemx --all
6021 @opindex -a
6022 @opindex --all
6023 Also convert all sequences of two or more blanks just before a tab stop,
6024 even if they occur after non-blank characters in a line.
6026 @end table
6028 @exitstatus
6031 @node Directory listing
6032 @chapter Directory listing
6034 This chapter describes the @command{ls} command and its variants @command{dir}
6035 and @command{vdir}, which list information about files.
6037 @menu
6038 * ls invocation::               List directory contents.
6039 * dir invocation::              Briefly ls.
6040 * vdir invocation::             Verbosely ls.
6041 * dircolors invocation::        Color setup for ls, etc.
6042 @end menu
6045 @node ls invocation
6046 @section @command{ls}: List directory contents
6048 @pindex ls
6049 @cindex directory listing
6051 The @command{ls} program lists information about files (of any type,
6052 including directories).  Options and file arguments can be intermixed
6053 arbitrarily, as usual.
6055 For non-option command-line arguments that are directories, by default
6056 @command{ls} lists the contents of directories, not recursively, and
6057 omitting files with names beginning with @samp{.}.  For other non-option
6058 arguments, by default @command{ls} lists just the file name.  If no
6059 non-option argument is specified, @command{ls} operates on the current
6060 directory, acting as if it had been invoked with a single argument of @samp{.}.
6062 @vindex LC_ALL
6063 By default, the output is sorted alphabetically, according to the locale
6064 settings in effect.@footnote{If you use a non-@acronym{POSIX}
6065 locale (e.g., by setting @env{LC_ALL} to @samp{en_US}), then @command{ls} may
6066 produce output that is sorted differently than you're accustomed to.
6067 In that case, set the @env{LC_ALL} environment variable to @samp{C}.}
6068 If standard output is
6069 a terminal, the output is in columns (sorted vertically) and control
6070 characters are output as question marks; otherwise, the output is listed
6071 one per line and control characters are output as-is.
6073 Because @command{ls} is such a fundamental program, it has accumulated many
6074 options over the years.  They are described in the subsections below;
6075 within each section, options are listed alphabetically (ignoring case).
6076 The division of options into the subsections is not absolute, since some
6077 options affect more than one aspect of @command{ls}'s operation.
6079 @cindex exit status of @command{ls}
6080 Exit status:
6082 @display
6083 0 success
6084 1 minor problems  (e.g., failure to access a file or directory not
6085   specified as a command line argument.  This happens when listing a
6086   directory in which entries are actively being removed or renamed.)
6087 2 serious trouble (e.g., memory exhausted, invalid option or failure
6088   to access file or directory specified as a command line argument)
6089 @end display
6091 Also see @ref{Common options}.
6093 @menu
6094 * Which files are listed::
6095 * What information is listed::
6096 * Sorting the output::
6097 * More details about version sort::
6098 * General output formatting::
6099 * Formatting file timestamps::
6100 * Formatting the file names::
6101 @end menu
6104 @node Which files are listed
6105 @subsection Which files are listed
6107 These options determine which files @command{ls} lists information for.
6108 By default, @command{ls} lists files and the contents of any
6109 directories on the command line, except that in directories it ignores
6110 files whose names start with @samp{.}.
6112 @table @samp
6114 @item -a
6115 @itemx --all
6116 @opindex -a
6117 @opindex --all
6118 In directories, do not ignore file names that start with @samp{.}.
6120 @item -A
6121 @itemx --almost-all
6122 @opindex -A
6123 @opindex --almost-all
6124 In directories, do not ignore all file names that start with @samp{.};
6125 ignore only @file{.} and @file{..}.  The @option{--all} (@option{-a})
6126 option overrides this option.
6128 @item -B
6129 @itemx --ignore-backups
6130 @opindex -B
6131 @opindex --ignore-backups
6132 @cindex backup files, ignoring
6133 In directories, ignore files that end with @samp{~}.  This option is
6134 equivalent to @samp{--ignore='*~' --ignore='.*~'}.
6136 @item -d
6137 @itemx --directory
6138 @opindex -d
6139 @opindex --directory
6140 List just the names of directories, as with other types of files, rather
6141 than listing their contents.
6142 @c The following sentence is the same as the one for -F.
6143 Do not follow symbolic links listed on the
6144 command line unless the @option{--dereference-command-line} (@option{-H}),
6145 @option{--dereference} (@option{-L}), or
6146 @option{--dereference-command-line-symlink-to-dir} options are specified.
6148 @item -H
6149 @itemx --dereference-command-line
6150 @opindex -H
6151 @opindex --dereference-command-line
6152 @cindex symbolic links, dereferencing
6153 If a command line argument specifies a symbolic link, show information
6154 for the file the link references rather than for the link itself.
6156 @itemx --dereference-command-line-symlink-to-dir
6157 @opindex --dereference-command-line-symlink-to-dir
6158 @cindex symbolic links, dereferencing
6159 Do not dereference symbolic links, with one exception:
6160 if a command line argument specifies a symbolic link that refers to
6161 a directory, show information for that directory rather than for the
6162 link itself.
6163 This is the default behavior when no other dereferencing-related
6164 option has been specified (@option{--classify} (@option{-F}),
6165 @option{--directory} (@option{-d}),
6166 (@option{-l}),
6167 @option{--dereference} (@option{-L}), or
6168 @option{--dereference-command-line} (@option{-H})).
6170 @item --group-directories-first
6171 @opindex --group-directories-first
6172 Group all the directories before the files and then sort the
6173 directories and the files separately using the selected sort key
6174 (see --sort option).
6175 That is, this option specifies a primary sort key,
6176 and the --sort option specifies a secondary key.
6177 However, any use of @option{--sort=none}
6178 (@option{-U}) disables this option altogether.
6180 @item --hide=PATTERN
6181 @opindex --hide=@var{pattern}
6182 In directories, ignore files whose names match the shell pattern
6183 @var{pattern}, unless the @option{--all} (@option{-a}) or
6184 @option{--almost-all} (@option{-A}) is also given.  This
6185 option acts like @option{--ignore=@var{pattern}} except that it has no
6186 effect if @option{--all} (@option{-a}) or @option{--almost-all}
6187 (@option{-A}) is also given.
6189 This option can be useful in shell aliases.  For example, if
6190 @command{lx} is an alias for @samp{ls --hide='*~'} and @command{ly} is
6191 an alias for @samp{ls --ignore='*~'}, then the command @samp{lx -A}
6192 lists the file @file{README~} even though @samp{ly -A} would not.
6194 @item -I @var{pattern}
6195 @itemx --ignore=@var{pattern}
6196 @opindex -I
6197 @opindex --ignore=@var{pattern}
6198 In directories, ignore files whose names match the shell pattern
6199 (not regular expression) @var{pattern}.  As
6200 in the shell, an initial @samp{.} in a file name does not match a
6201 wildcard at the start of @var{pattern}.  Sometimes it is useful
6202 to give this option several times.  For example,
6204 @smallexample
6205 $ ls --ignore='.??*' --ignore='.[^.]' --ignore='#*'
6206 @end smallexample
6208 The first option ignores names of length 3 or more that start with @samp{.},
6209 the second ignores all two-character names that start with @samp{.}
6210 except @samp{..}, and the third ignores names that start with @samp{#}.
6212 @item -L
6213 @itemx --dereference
6214 @opindex -L
6215 @opindex --dereference
6216 @cindex symbolic links, dereferencing
6217 When showing file information for a symbolic link, show information
6218 for the file the link references rather than the link itself.
6219 However, even with this option, @command{ls} still prints the name
6220 of the link itself, not the name of the file that the link points to.
6222 @item -R
6223 @itemx --recursive
6224 @opindex -R
6225 @opindex --recursive
6226 @cindex recursive directory listing
6227 @cindex directory listing, recursive
6228 List the contents of all directories recursively.
6230 @end table
6233 @node What information is listed
6234 @subsection What information is listed
6236 These options affect the information that @command{ls} displays.  By
6237 default, only file names are shown.
6239 @table @samp
6241 @item --author
6242 @opindex --author
6243 @cindex hurd, author, printing
6244 List each file's author when producing long format directory listings.
6245 In GNU/Hurd, file authors can differ from their owners, but in other
6246 operating systems the two are the same.
6248 @item -D
6249 @itemx --dired
6250 @opindex -D
6251 @opindex --dired
6252 @cindex dired Emacs mode support
6253 With the long listing (@option{-l}) format, print an additional line after
6254 the main output:
6256 @example
6257 //DIRED// @var{beg1} @var{end1} @var{beg2} @var{end2} @dots{}
6258 @end example
6260 @noindent
6261 The @var{begn} and @var{endn} are unsigned integers that record the
6262 byte position of the beginning and end of each file name in the output.
6263 This makes it easy for Emacs to find the names, even when they contain
6264 unusual characters such as space or newline, without fancy searching.
6266 If directories are being listed recursively (@option{-R}), output a similar
6267 line with offsets for each subdirectory name:
6269 @example
6270 //SUBDIRED// @var{beg1} @var{end1} @dots{}
6271 @end example
6273 Finally, output a line of the form:
6275 @example
6276 //DIRED-OPTIONS// --quoting-style=@var{word}
6277 @end example
6279 @noindent
6280 where @var{word} is the quoting style (@pxref{Formatting the file names}).
6282 Here is an actual example:
6284 @example
6285 $ mkdir -p a/sub/deeper a/sub2
6286 $ touch a/f1 a/f2
6287 $ touch a/sub/deeper/file
6288 $ ls -gloRF --dired a
6289   a:
6290   total 8
6291   -rw-r--r-- 1    0 Jun 10 12:27 f1
6292   -rw-r--r-- 1    0 Jun 10 12:27 f2
6293   drwxr-xr-x 3 4096 Jun 10 12:27 sub/
6294   drwxr-xr-x 2 4096 Jun 10 12:27 sub2/
6296   a/sub:
6297   total 4
6298   drwxr-xr-x 2 4096 Jun 10 12:27 deeper/
6300   a/sub/deeper:
6301   total 0
6302   -rw-r--r-- 1 0 Jun 10 12:27 file
6304   a/sub2:
6305   total 0
6306 //DIRED// 48 50 84 86 120 123 158 162 217 223 282 286
6307 //SUBDIRED// 2 3 167 172 228 240 290 296
6308 //DIRED-OPTIONS// --quoting-style=literal
6309 @end example
6311 Note that the pairs of offsets on the @samp{//DIRED//} line above delimit
6312 these names: @file{f1}, @file{f2}, @file{sub}, @file{sub2}, @file{deeper},
6313 @file{file}.
6314 The offsets on the @samp{//SUBDIRED//} line delimit the following
6315 directory names: @file{a}, @file{a/sub}, @file{a/sub/deeper}, @file{a/sub2}.
6317 Here is an example of how to extract the fifth entry name, @samp{deeper},
6318 corresponding to the pair of offsets, 222 and 228:
6320 @example
6321 $ ls -gloRF --dired a > out
6322 $ dd bs=1 skip=222 count=6 < out 2>/dev/null; echo
6323 deeper
6324 @end example
6326 Note that although the listing above includes a trailing slash
6327 for the @samp{deeper} entry, the offsets select the name without
6328 the trailing slash.  However, if you invoke @command{ls} with @option{--dired}
6329 along with an option like @option{--escape} (aka @option{-b}) and operate
6330 on a file whose name contains special characters, notice that the backslash
6331 @emph{is} included:
6333 @example
6334 $ touch 'a b'
6335 $ ls -blog --dired 'a b'
6336   -rw-r--r-- 1 0 Jun 10 12:28 a\ b
6337 //DIRED// 30 34
6338 //DIRED-OPTIONS// --quoting-style=escape
6339 @end example
6341 If you use a quoting style that adds quote marks
6342 (e.g., @option{--quoting-style=c}), then the offsets include the quote marks.
6343 So beware that the user may select the quoting style via the environment
6344 variable @env{QUOTING_STYLE}.  Hence, applications using @option{--dired}
6345 should either specify an explicit @option{--quoting-style=literal} option
6346 (aka @option{-N} or @option{--literal}) on the command line, or else be
6347 prepared to parse the escaped names.
6349 @item --full-time
6350 @opindex --full-time
6351 Produce long format directory listings, and list times in full.  It is
6352 equivalent to using @option{--format=long} with
6353 @option{--time-style=full-iso} (@pxref{Formatting file timestamps}).
6355 @item -g
6356 @opindex -g
6357 Produce long format directory listings, but don't display owner information.
6359 @item -G
6360 @itemx --no-group
6361 @opindex -G
6362 @opindex --no-group
6363 Inhibit display of group information in a long format directory listing.
6364 (This is the default in some non-@sc{gnu} versions of @command{ls}, so we
6365 provide this option for compatibility.)
6367 @optHumanReadable
6369 @item -i
6370 @itemx --inode
6371 @opindex -i
6372 @opindex --inode
6373 @cindex inode number, printing
6374 Print the inode number (also called the file serial number and index
6375 number) of each file to the left of the file name.  (This number
6376 uniquely identifies each file within a particular file system.)
6378 @item -l
6379 @itemx --format=long
6380 @itemx --format=verbose
6381 @opindex -l
6382 @opindex --format
6383 @opindex long ls @r{format}
6384 @opindex verbose ls @r{format}
6385 In addition to the name of each file, print the file type, file mode bits,
6386 number of hard links, owner name, group name, size, and
6387 timestamp (@pxref{Formatting file timestamps}), normally
6388 the modification time.  Print question marks for information that
6389 cannot be determined.
6391 Normally the size is printed as a byte count without punctuation, but
6392 this can be overridden (@pxref{Block size}).  For example, @option{-h}
6393 prints an abbreviated, human-readable count, and
6394 @samp{--block-size="'1"} prints a byte count with the thousands
6395 separator of the current locale.
6397 For each directory that is listed, preface the files with a line
6398 @samp{total @var{blocks}}, where @var{blocks} is the total disk allocation
6399 for all files in that directory.  The block size currently defaults to 1024
6400 bytes, but this can be overridden (@pxref{Block size}).
6401 The @var{blocks} computed counts each hard link separately;
6402 this is arguably a deficiency.
6404 The file type is one of the following characters:
6406 @c The commented-out entries are ones we're not sure about.
6408 @table @samp
6409 @item -
6410 regular file
6411 @item b
6412 block special file
6413 @item c
6414 character special file
6415 @item C
6416 high performance (``contiguous data'') file
6417 @item d
6418 directory
6419 @item D
6420 door (Solaris 2.5 and up)
6421 @c @item F
6422 @c semaphore, if this is a distinct file type
6423 @item l
6424 symbolic link
6425 @c @item m
6426 @c multiplexed file (7th edition Unix; obsolete)
6427 @item M
6428 off-line (``migrated'') file (Cray DMF)
6429 @item n
6430 network special file (HP-UX)
6431 @item p
6432 FIFO (named pipe)
6433 @item P
6434 port (Solaris 10 and up)
6435 @c @item Q
6436 @c message queue, if this is a distinct file type
6437 @item s
6438 socket
6439 @c @item S
6440 @c shared memory object, if this is a distinct file type
6441 @c @item T
6442 @c typed memory object, if this is a distinct file type
6443 @c @item w
6444 @c whiteout (4.4BSD; not implemented)
6445 @item ?
6446 some other file type
6447 @end table
6449 @cindex permissions, output by @command{ls}
6450 The file mode bits listed are similar to symbolic mode specifications
6451 (@pxref{Symbolic Modes}).  But @command{ls} combines multiple bits into the
6452 third character of each set of permissions as follows:
6454 @table @samp
6455 @item s
6456 If the set-user-ID or set-group-ID bit and the corresponding executable bit
6457 are both set.
6459 @item S
6460 If the set-user-ID or set-group-ID bit is set but the corresponding
6461 executable bit is not set.
6463 @item t
6464 If the restricted deletion flag or sticky bit, and the
6465 other-executable bit, are both set.  The restricted deletion flag is
6466 another name for the sticky bit.  @xref{Mode Structure}.
6468 @item T
6469 If the restricted deletion flag or sticky bit is set but the
6470 other-executable bit is not set.
6472 @item x
6473 If the executable bit is set and none of the above apply.
6475 @item -
6476 Otherwise.
6477 @end table
6479 Following the file mode bits is a single character that specifies
6480 whether an alternate access method such as an access control list
6481 applies to the file.  When the character following the file mode bits is a
6482 space, there is no alternate access method.  When it is a printing
6483 character, then there is such a method.
6485 GNU @command{ls} uses a @samp{.} character to indicate a file
6486 with an SELinux security context, but no other alternate access method.
6488 A file with any other combination of alternate access methods
6489 is marked with a @samp{+} character.
6491 @item -n
6492 @itemx --numeric-uid-gid
6493 @opindex -n
6494 @opindex --numeric-uid-gid
6495 @cindex numeric uid and gid
6496 @cindex numeric user and group IDs
6497 Produce long format directory listings, but
6498 display numeric user and group IDs instead of the owner and group names.
6500 @item -o
6501 @opindex -o
6502 Produce long format directory listings, but don't display group information.
6503 It is equivalent to using @option{--format=long} with @option{--no-group} .
6505 @item -s
6506 @itemx --size
6507 @opindex -s
6508 @opindex --size
6509 @cindex disk allocation
6510 @cindex size of files, reporting
6511 Print the disk allocation of each file to the left of the file name.
6512 This is the amount of disk space used by the file, which is usually a
6513 bit more than the file's size, but it can be less if the file has holes.
6515 Normally the disk allocation is printed in units of
6516 1024 bytes, but this can be overridden (@pxref{Block size}).
6518 @cindex NFS mounts from BSD to HP-UX
6519 For files that are NFS-mounted from an HP-UX system to a BSD system,
6520 this option reports sizes that are half the correct values.  On HP-UX
6521 systems, it reports sizes that are twice the correct values for files
6522 that are NFS-mounted from BSD systems.  This is due to a flaw in HP-UX;
6523 it also affects the HP-UX @command{ls} program.
6525 @optSi
6527 @end table
6530 @node Sorting the output
6531 @subsection Sorting the output
6533 @cindex sorting @command{ls} output
6534 These options change the order in which @command{ls} sorts the information
6535 it outputs.  By default, sorting is done by character code
6536 (e.g., @acronym{ASCII} order).
6538 @table @samp
6540 @item -c
6541 @itemx --time=ctime
6542 @itemx --time=status
6543 @opindex -c
6544 @opindex --time
6545 @opindex ctime@r{, printing or sorting by}
6546 @opindex status time@r{, printing or sorting by}
6547 @opindex use time@r{, printing or sorting files by}
6548 If the long listing format (e.g., @option{-l}, @option{-o}) is being used,
6549 print the status change time (the @samp{ctime} in the inode) instead of
6550 the modification time.
6551 When explicitly sorting by time (@option{--sort=time} or @option{-t})
6552 or when not using a long listing format,
6553 sort according to the status change time.
6555 @item -f
6556 @opindex -f
6557 @cindex unsorted directory listing
6558 @cindex directory order, listing by
6559 Primarily, like @option{-U}---do not sort; list the files in whatever
6560 order they are stored in the directory.  But also enable @option{-a} (list
6561 all files) and disable @option{-l}, @option{--color}, and @option{-s} (if they
6562 were specified before the @option{-f}).
6564 @item -r
6565 @itemx --reverse
6566 @opindex -r
6567 @opindex --reverse
6568 @cindex reverse sorting
6569 Reverse whatever the sorting method is---e.g., list files in reverse
6570 alphabetical order, youngest first, smallest first, or whatever.
6572 @item -S
6573 @itemx --sort=size
6574 @opindex -S
6575 @opindex --sort
6576 @opindex size of files@r{, sorting files by}
6577 Sort by file size, largest first.
6579 @item -t
6580 @itemx --sort=time
6581 @opindex -t
6582 @opindex --sort
6583 @opindex modification time@r{, sorting files by}
6584 Sort by modification time (the @samp{mtime} in the inode), newest first.
6586 @item -u
6587 @itemx --time=atime
6588 @itemx --time=access
6589 @itemx --time=use
6590 @opindex -u
6591 @opindex --time
6592 @opindex use time@r{, printing or sorting files by}
6593 @opindex atime@r{, printing or sorting files by}
6594 @opindex access time@r{, printing or sorting files by}
6595 If the long listing format (e.g., @option{--format=long}) is being used,
6596 print the last access time (the @samp{atime} in the inode).
6597 When explicitly sorting by time (@option{--sort=time} or @option{-t})
6598 or when not using a long listing format, sort according to the access time.
6600 @item -U
6601 @itemx --sort=none
6602 @opindex -U
6603 @opindex --sort
6604 @opindex none@r{, sorting option for @command{ls}}
6605 Do not sort; list the files in whatever order they are
6606 stored in the directory.  (Do not do any of the other unrelated things
6607 that @option{-f} does.)  This is especially useful when listing very large
6608 directories, since not doing any sorting can be noticeably faster.
6610 @item -v
6611 @itemx --sort=version
6612 @opindex -v
6613 @opindex --sort
6614 @opindex version@r{, sorting option for @command{ls}}
6615 Sort by version name and number, lowest first.  It behaves like a default
6616 sort, except that each sequence of decimal digits is treated numerically
6617 as an index/version number.  (@xref{More details about version sort}.)
6619 @item -X
6620 @itemx --sort=extension
6621 @opindex -X
6622 @opindex --sort
6623 @opindex extension@r{, sorting files by}
6624 Sort directory contents alphabetically by file extension (characters
6625 after the last @samp{.}); files with no extension are sorted first.
6627 @end table
6630 @node More details about version sort
6631 @subsection More details about version sort
6633 The version sort takes into account the fact that file names frequently include
6634 indices or version numbers.  Standard sorting functions usually do not produce
6635 the ordering that people expect because comparisons are made on a
6636 character-by-character basis.  The version
6637 sort addresses this problem, and is especially useful when browsing
6638 directories that contain many files with indices/version numbers in their
6639 names:
6641 @example
6642 $ ls -1            $ ls -1v
6643 foo.zml-1.gz       foo.zml-1.gz
6644 foo.zml-100.gz     foo.zml-2.gz
6645 foo.zml-12.gz      foo.zml-6.gz
6646 foo.zml-13.gz      foo.zml-12.gz
6647 foo.zml-2.gz       foo.zml-13.gz
6648 foo.zml-25.gz      foo.zml-25.gz
6649 foo.zml-6.gz       foo.zml-100.gz
6650 @end example
6652 Note also that numeric parts with leading zeros are considered as
6653 fractional one:
6655 @example
6656 $ ls -1            $ ls -1v
6657 abc-1.007.tgz      abc-1.007.tgz
6658 abc-1.012b.tgz     abc-1.01a.tgz
6659 abc-1.01a.tgz      abc-1.012b.tgz
6660 @end example
6662 This functionality is implemented using the @code{strverscmp} function.
6663 @xref{String/Array Comparison, , , libc, The GNU C Library Reference Manual}.
6664 One result of that implementation decision is that @code{ls -v} does not
6665 use the locale category, @env{LC_COLLATE}.  As a result, non-numeric prefixes
6666 are sorted as if @env{LC_COLLATE} were set to @code{C}.
6668 @node General output formatting
6669 @subsection General output formatting
6671 These options affect the appearance of the overall output.
6673 @table @samp
6675 @item -1
6676 @itemx --format=single-column
6677 @opindex -1
6678 @opindex --format
6679 @opindex single-column @r{output of files}
6680 List one file per line.  This is the default for @command{ls} when standard
6681 output is not a terminal.
6683 @item -C
6684 @itemx --format=vertical
6685 @opindex -C
6686 @opindex --format
6687 @opindex vertical @r{sorted files in columns}
6688 List files in columns, sorted vertically.  This is the default for
6689 @command{ls} if standard output is a terminal.  It is always the default
6690 for the @command{dir} program.
6691 @sc{gnu} @command{ls} uses variable width columns to display as many files as
6692 possible in the fewest lines.
6694 @item --color [=@var{when}]
6695 @opindex --color
6696 @cindex color, distinguishing file types with
6697 Specify whether to use color for distinguishing file types.  @var{when}
6698 may be omitted, or one of:
6699 @itemize @bullet
6700 @item none
6701 @vindex none @r{color option}
6702 - Do not use color at all.  This is the default.
6703 @item auto
6704 @vindex auto @r{color option}
6705 @cindex terminal, using color iff
6706 - Only use color if standard output is a terminal.
6707 @item always
6708 @vindex always @r{color option}
6709 - Always use color.
6710 @end itemize
6711 Specifying @option{--color} and no @var{when} is equivalent to
6712 @option{--color=always}.
6713 Piping a colorized listing through a pager like @command{more} or
6714 @command{less} usually produces unreadable results.  However, using
6715 @code{more -f} does seem to work.
6717 @item -F
6718 @itemx --classify
6719 @itemx --indicator-style=classify
6720 @opindex -F
6721 @opindex --classify
6722 @opindex --indicator-style
6723 @cindex file type and executables, marking
6724 @cindex executables and file type, marking
6725 Append a character to each file name indicating the file type.  Also,
6726 for regular files that are executable, append @samp{*}.  The file type
6727 indicators are @samp{/} for directories, @samp{@@} for symbolic links,
6728 @samp{|} for FIFOs, @samp{=} for sockets, @samp{>} for doors,
6729 and nothing for regular files.
6730 @c The following sentence is the same as the one for -d.
6731 Do not follow symbolic links listed on the
6732 command line unless the @option{--dereference-command-line} (@option{-H}),
6733 @option{--dereference} (@option{-L}), or
6734 @option{--dereference-command-line-symlink-to-dir} options are specified.
6736 @item --file-type
6737 @itemx --indicator-style=file-type
6738 @opindex --file-type
6739 @opindex --indicator-style
6740 @cindex file type, marking
6741 Append a character to each file name indicating the file type.  This is
6742 like @option{-F}, except that executables are not marked.
6744 @item --indicator-style=@var{word}
6745 @opindex --indicator-style
6746 Append a character indicator with style @var{word} to entry names,
6747 as follows:
6749 @table @samp
6750 @item none
6751 Do not append any character indicator; this is the default.
6752 @item slash
6753 Append @samp{/} for directories.  This is the same as the @option{-p}
6754 option.
6755 @item file-type
6756 Append @samp{/} for directories, @samp{@@} for symbolic links, @samp{|}
6757 for FIFOs, @samp{=} for sockets, and nothing for regular files.  This is
6758 the same as the @option{--file-type} option.
6759 @item classify
6760 Append @samp{*} for executable regular files, otherwise behave as for
6761 @samp{file-type}.  This is the same as the @option{-F} or
6762 @option{--classify} option.
6763 @end table
6765 @item -k
6766 @opindex -k
6767 Print file sizes in 1024-byte blocks, overriding the default block
6768 size (@pxref{Block size}).
6769 This option is equivalent to @option{--block-size=1K}.
6771 @item -m
6772 @itemx --format=commas
6773 @opindex -m
6774 @opindex --format
6775 @opindex commas@r{, outputting between files}
6776 List files horizontally, with as many as will fit on each line,
6777 separated by @samp{, } (a comma and a space).
6779 @item -p
6780 @itemx --indicator-style=slash
6781 @opindex -p
6782 @opindex --indicator-style
6783 @cindex file type, marking
6784 Append a @samp{/} to directory names.
6786 @item -x
6787 @itemx --format=across
6788 @itemx --format=horizontal
6789 @opindex -x
6790 @opindex --format
6791 @opindex across@r{, listing files}
6792 @opindex horizontal@r{, listing files}
6793 List the files in columns, sorted horizontally.
6795 @item -T @var{cols}
6796 @itemx --tabsize=@var{cols}
6797 @opindex -T
6798 @opindex --tabsize
6799 Assume that each tab stop is @var{cols} columns wide.  The default is 8.
6800 @command{ls} uses tabs where possible in the output, for efficiency.  If
6801 @var{cols} is zero, do not use tabs at all.
6803 @c FIXME: remove in 2009, if Apple Terminal has been fixed for long enough.
6804 Some terminal emulators (at least Apple Terminal 1.5 (133) from Mac OS X 10.4.8)
6805 do not properly align columns to the right of a TAB following a
6806 non-@acronym{ASCII} byte.  If you use such a terminal emulator, use the
6807 @option{-T0} option or put @code{TABSIZE=0} in your environment to tell
6808 @command{ls} to align using spaces, not tabs.
6810 @item -w
6811 @itemx --width=@var{cols}
6812 @opindex -w
6813 @opindex --width
6814 @vindex COLUMNS
6815 Assume the screen is @var{cols} columns wide.  The default is taken
6816 from the terminal settings if possible; otherwise the environment
6817 variable @env{COLUMNS} is used if it is set; otherwise the default
6818 is 80.
6820 @end table
6823 @node Formatting file timestamps
6824 @subsection Formatting file timestamps
6826 By default, file timestamps are listed in abbreviated form.  Most
6827 locales use a timestamp like @samp{2002-03-30 23:45}.  However, the
6828 default @acronym{POSIX} locale uses a date like @samp{Mar 30@ @ 2002}
6829 for non-recent timestamps, and a date-without-year and time like
6830 @samp{Mar 30 23:45} for recent timestamps.
6832 A timestamp is considered to be @dfn{recent} if it is less than six
6833 months old, and is not dated in the future.  If a timestamp dated
6834 today is not listed in recent form, the timestamp is in the future,
6835 which means you probably have clock skew problems which may break
6836 programs like @command{make} that rely on file timestamps.
6838 @vindex TZ
6839 Time stamps are listed according to the time zone rules specified by
6840 the @env{TZ} environment variable, or by the system default rules if
6841 @env{TZ} is not set.  @xref{TZ Variable,, Specifying the Time Zone
6842 with @env{TZ}, libc, The GNU C Library Reference Manual}.
6844 The following option changes how file timestamps are printed.
6846 @table @samp
6847 @item --time-style=@var{style}
6848 @opindex --time-style
6849 @cindex time style
6850 List timestamps in style @var{style}.  The @var{style} should
6851 be one of the following:
6853 @table @samp
6854 @item +@var{format}
6855 @vindex LC_TIME
6856 List timestamps using @var{format}, where @var{format} is interpreted
6857 like the format argument of @command{date} (@pxref{date invocation}).
6858 For example, @option{--time-style="+%Y-%m-%d %H:%M:%S"} causes
6859 @command{ls} to list timestamps like @samp{2002-03-30 23:45:56}.  As
6860 with @command{date}, @var{format}'s interpretation is affected by the
6861 @env{LC_TIME} locale category.
6863 If @var{format} contains two format strings separated by a newline,
6864 the former is used for non-recent files and the latter for recent
6865 files; if you want output columns to line up, you may need to insert
6866 spaces in one of the two formats.
6868 @item full-iso
6869 List timestamps in full using @acronym{ISO} 8601 date, time, and time zone
6870 format with nanosecond precision, e.g., @samp{2002-03-30
6871 23:45:56.477817180 -0700}.  This style is equivalent to
6872 @samp{+%Y-%m-%d %H:%M:%S.%N %z}.
6874 This is useful because the time output includes all the information that
6875 is available from the operating system.  For example, this can help
6876 explain @command{make}'s behavior, since @acronym{GNU} @command{make}
6877 uses the full timestamp to determine whether a file is out of date.
6879 @item long-iso
6880 List @acronym{ISO} 8601 date and time in minutes, e.g.,
6881 @samp{2002-03-30 23:45}.  These timestamps are shorter than
6882 @samp{full-iso} timestamps, and are usually good enough for everyday
6883 work.  This style is equivalent to @samp{+%Y-%m-%d %H:%M}.
6885 @item iso
6886 List @acronym{ISO} 8601 dates for non-recent timestamps (e.g.,
6887 @samp{2002-03-30@ }), and @acronym{ISO} 8601 month, day, hour, and
6888 minute for recent timestamps (e.g., @samp{03-30 23:45}).  These
6889 timestamps are uglier than @samp{long-iso} timestamps, but they carry
6890 nearly the same information in a smaller space and their brevity helps
6891 @command{ls} output fit within traditional 80-column output lines.
6892 The following two @command{ls} invocations are equivalent:
6894 @example
6895 newline='
6897 ls -l --time-style="+%Y-%m-%d $newline%m-%d %H:%M"
6898 ls -l --time-style="iso"
6899 @end example
6901 @item locale
6902 @vindex LC_TIME
6903 List timestamps in a locale-dependent form.  For example, a Finnish
6904 locale might list non-recent timestamps like @samp{maalis 30@ @ 2002}
6905 and recent timestamps like @samp{maalis 30 23:45}.  Locale-dependent
6906 timestamps typically consume more space than @samp{iso} timestamps and
6907 are harder for programs to parse because locale conventions vary so
6908 widely, but they are easier for many people to read.
6910 The @env{LC_TIME} locale category specifies the timestamp format.  The
6911 default @acronym{POSIX} locale uses timestamps like @samp{Mar 30@
6912 @ 2002} and @samp{Mar 30 23:45}; in this locale, the following two
6913 @command{ls} invocations are equivalent:
6915 @example
6916 newline='
6918 ls -l --time-style="+%b %e  %Y$newline%b %e %H:%M"
6919 ls -l --time-style="locale"
6920 @end example
6922 Other locales behave differently.  For example, in a German locale,
6923 @option{--time-style="locale"} might be equivalent to
6924 @option{--time-style="+%e. %b %Y $newline%e. %b %H:%M"}
6925 and might generate timestamps like @samp{30. M@"ar 2002@ } and
6926 @samp{30. M@"ar 23:45}.
6928 @item posix-@var{style}
6929 @vindex LC_TIME
6930 List @acronym{POSIX}-locale timestamps if the @env{LC_TIME} locale
6931 category is @acronym{POSIX}, @var{style} timestamps otherwise.  For
6932 example, the @samp{posix-long-iso} style lists
6933 timestamps like @samp{Mar 30@ @ 2002} and @samp{Mar 30 23:45} when in
6934 the @acronym{POSIX} locale, and like @samp{2002-03-30 23:45} otherwise.
6935 @end table
6936 @end table
6938 @vindex TIME_STYLE
6939 You can specify the default value of the @option{--time-style} option
6940 with the environment variable @env{TIME_STYLE}; if @env{TIME_STYLE} is not set
6941 the default style is @samp{locale}.  @acronym{GNU} Emacs 21.3 and
6942 later use the @option{--dired} option and therefore can parse any date
6943 format, but if you are using Emacs 21.1 or 21.2 and specify a
6944 non-@acronym{POSIX} locale you may need to set
6945 @samp{TIME_STYLE="posix-long-iso"}.
6947 To avoid certain denial-of-service attacks, timestamps that would be
6948 longer than 1000 bytes may be treated as errors.
6951 @node Formatting the file names
6952 @subsection Formatting the file names
6954 These options change how file names themselves are printed.
6956 @table @samp
6958 @item -b
6959 @itemx --escape
6960 @itemx --quoting-style=escape
6961 @opindex -b
6962 @opindex --escape
6963 @opindex --quoting-style
6964 @cindex backslash sequences for file names
6965 Quote nongraphic characters in file names using alphabetic and octal
6966 backslash sequences like those used in C.
6968 @item -N
6969 @itemx --literal
6970 @itemx --quoting-style=literal
6971 @opindex -N
6972 @opindex --literal
6973 @opindex --quoting-style
6974 Do not quote file names.  However, with @command{ls} nongraphic
6975 characters are still printed as question marks if the output is a
6976 terminal and you do not specify the @option{--show-control-chars}
6977 option.
6979 @item -q
6980 @itemx --hide-control-chars
6981 @opindex -q
6982 @opindex --hide-control-chars
6983 Print question marks instead of nongraphic characters in file names.
6984 This is the default if the output is a terminal and the program is
6985 @command{ls}.
6987 @item -Q
6988 @itemx --quote-name
6989 @itemx --quoting-style=c
6990 @opindex -Q
6991 @opindex --quote-name
6992 @opindex --quoting-style
6993 Enclose file names in double quotes and quote nongraphic characters as
6994 in C.
6996 @item --quoting-style=@var{word}
6997 @opindex --quoting-style
6998 @cindex quoting style
6999 Use style @var{word} to quote file names and other strings that may
7000 contain arbitrary characters.  The @var{word} should
7001 be one of the following:
7003 @table @samp
7004 @item literal
7005 Output strings as-is; this is the same as the @option{-N} or
7006 @option{--literal} option.
7007 @item shell
7008 Quote strings for the shell if they contain shell metacharacters or would
7009 cause ambiguous output.
7010 The quoting is suitable for @acronym{POSIX}-compatible shells like
7011 @command{bash}, but it does not always work for incompatible shells
7012 like @command{csh}.
7013 @item shell-always
7014 Quote strings for the shell, even if they would normally not require quoting.
7015 @item c
7016 Quote strings as for C character string literals, including the
7017 surrounding double-quote characters; this is the same as the
7018 @option{-Q} or @option{--quote-name} option.
7019 @item escape
7020 Quote strings as for C character string literals, except omit the
7021 surrounding double-quote
7022 characters; this is the same as the @option{-b} or @option{--escape} option.
7023 @item clocale
7024 Quote strings as for C character string literals, except use
7025 surrounding quotation marks appropriate for the
7026 locale.
7027 @item locale
7028 @c Use @t instead of @samp to avoid duplicate quoting in some output styles.
7029 Quote strings as for C character string literals, except use
7030 surrounding quotation marks appropriate for the locale, and quote
7031 @t{`like this'} instead of @t{"like
7032 this"} in the default C locale.  This looks nicer on many displays.
7033 @end table
7035 You can specify the default value of the @option{--quoting-style} option
7036 with the environment variable @env{QUOTING_STYLE}.  If that environment
7037 variable is not set, the default value is @samp{literal}, but this
7038 default may change to @samp{shell} in a future version of this package.
7040 @item --show-control-chars
7041 @opindex --show-control-chars
7042 Print nongraphic characters as-is in file names.
7043 This is the default unless the output is a terminal and the program is
7044 @command{ls}.
7046 @end table
7049 @node dir invocation
7050 @section @command{dir}: Briefly list directory contents
7052 @pindex dir
7053 @cindex directory listing, brief
7055 @command{dir} is equivalent to @code{ls -C
7056 -b}; that is, by default files are listed in columns, sorted vertically,
7057 and special characters are represented by backslash escape sequences.
7059 @xref{ls invocation, @command{ls}}.
7062 @node vdir invocation
7063 @section @command{vdir}: Verbosely list directory contents
7065 @pindex vdir
7066 @cindex directory listing, verbose
7068 @command{vdir} is equivalent to @code{ls -l
7069 -b}; that is, by default files are listed in long format and special
7070 characters are represented by backslash escape sequences.
7072 @node dircolors invocation
7073 @section @command{dircolors}: Color setup for @command{ls}
7075 @pindex dircolors
7076 @cindex color setup
7077 @cindex setup for color
7079 @command{dircolors} outputs a sequence of shell commands to set up the
7080 terminal for color output from @command{ls} (and @command{dir}, etc.).
7081 Typical usage:
7083 @example
7084 eval "`dircolors [@var{option}]@dots{} [@var{file}]`"
7085 @end example
7087 If @var{file} is specified, @command{dircolors} reads it to determine which
7088 colors to use for which file types and extensions.  Otherwise, a
7089 precompiled database is used.  For details on the format of these files,
7090 run @samp{dircolors --print-database}.
7092 To make @command{dircolors} read a @file{~/.dircolors} file if it
7093 exists, you can put the following lines in your @file{~/.bashrc} (or
7094 adapt them to your favorite shell):
7096 @example
7097 d=.dircolors
7098 test -r $d && eval "$(dircolors $d)"
7099 @end example
7101 @vindex LS_COLORS
7102 @vindex SHELL @r{environment variable, and color}
7103 The output is a shell command to set the @env{LS_COLORS} environment
7104 variable.  You can specify the shell syntax to use on the command line,
7105 or @command{dircolors} will guess it from the value of the @env{SHELL}
7106 environment variable.
7108 The program accepts the following options.  Also see @ref{Common options}.
7110 @table @samp
7111 @item -b
7112 @itemx --sh
7113 @itemx --bourne-shell
7114 @opindex -b
7115 @opindex --sh
7116 @opindex --bourne-shell
7117 @cindex Bourne shell syntax for color setup
7118 @cindex @command{sh} syntax for color setup
7119 Output Bourne shell commands.  This is the default if the @env{SHELL}
7120 environment variable is set and does not end with @samp{csh} or
7121 @samp{tcsh}.
7123 @item -c
7124 @itemx --csh
7125 @itemx --c-shell
7126 @opindex -c
7127 @opindex --csh
7128 @opindex --c-shell
7129 @cindex C shell syntax for color setup
7130 @cindex @command{csh} syntax for color setup
7131 Output C shell commands.  This is the default if @code{SHELL} ends with
7132 @command{csh} or @command{tcsh}.
7134 @item -p
7135 @itemx --print-database
7136 @opindex -p
7137 @opindex --print-database
7138 @cindex color database, printing
7139 @cindex database for color setup, printing
7140 @cindex printing color database
7141 Print the (compiled-in) default color configuration database.  This
7142 output is itself a valid configuration file, and is fairly descriptive
7143 of the possibilities.
7145 @end table
7147 @exitstatus
7150 @node Basic operations
7151 @chapter Basic operations
7153 @cindex manipulating files
7155 This chapter describes the commands for basic file manipulation:
7156 copying, moving (renaming), and deleting (removing).
7158 @menu
7159 * cp invocation::               Copy files.
7160 * dd invocation::               Convert and copy a file.
7161 * install invocation::          Copy files and set attributes.
7162 * mv invocation::               Move (rename) files.
7163 * rm invocation::               Remove files or directories.
7164 * shred invocation::            Remove files more securely.
7165 @end menu
7168 @node cp invocation
7169 @section @command{cp}: Copy files and directories
7171 @pindex cp
7172 @cindex copying files and directories
7173 @cindex files, copying
7174 @cindex directories, copying
7176 @command{cp} copies files (or, optionally, directories).  The copy is
7177 completely independent of the original.  You can either copy one file to
7178 another, or copy arbitrarily many files to a destination directory.
7179 Synopses:
7181 @example
7182 cp [@var{option}]@dots{} [-T] @var{source} @var{dest}
7183 cp [@var{option}]@dots{} @var{source}@dots{} @var{directory}
7184 cp [@var{option}]@dots{} -t @var{directory} @var{source}@dots{}
7185 @end example
7187 @itemize @bullet
7188 @item
7189 If two file names are given, @command{cp} copies the first file to the
7190 second.
7192 @item
7193 If the @option{--target-directory} (@option{-t}) option is given, or
7194 failing that if the last file is a directory and the
7195 @option{--no-target-directory} (@option{-T}) option is not given,
7196 @command{cp} copies each @var{source} file to the specified directory,
7197 using the @var{source}s' names.
7198 @end itemize
7200 Generally, files are written just as they are read.  For exceptions,
7201 see the @option{--sparse} option below.
7203 By default, @command{cp} does not copy directories.  However, the
7204 @option{-R}, @option{-a}, and @option{-r} options cause @command{cp} to
7205 copy recursively by descending into source directories and copying files
7206 to corresponding destination directories.
7208 When copying from a symbolic link, @command{cp} normally follows the
7209 link only when not copying
7210 recursively.  This default can be overridden with the
7211 @option{--archive} (@option{-a}), @option{-d}, @option{--dereference}
7212 (@option{-L}), @option{--no-dereference} (@option{-P}), and
7213 @option{-H} options.  If more than one of these options is specified,
7214 the last one silently overrides the others.
7216 When copying to a symbolic link, @command{cp} follows the
7217 link only when it refers to an existing regular file.
7218 However, when copying to a dangling symbolic link, @command{cp}
7219 refuses by default, and fails with a diagnostic, since the operation
7220 is inherently dangerous.  This behavior is contrary to historical
7221 practice and to @acronym{POSIX}.
7222 Set @env{POSIXLY_CORRECT} to make @command{cp} attempt to create
7223 the target of a dangling destination symlink, in spite of the possible risk.
7224 Also, when an option like
7225 @option{--backup} or @option{--link} acts to rename or remove the
7226 destination before copying, @command{cp} renames or removes the
7227 symbolic link rather than the file it points to.
7229 By default, @command{cp} copies the contents of special files only
7230 when not copying recursively.  This default can be overridden with the
7231 @option{--copy-contents} option.
7233 @cindex self-backups
7234 @cindex backups, making only
7235 @command{cp} generally refuses to copy a file onto itself, with the
7236 following exception: if @option{--force --backup} is specified with
7237 @var{source} and @var{dest} identical, and referring to a regular file,
7238 @command{cp} will make a backup file, either regular or numbered, as
7239 specified in the usual ways (@pxref{Backup options}).  This is useful when
7240 you simply want to make a backup of an existing file before changing it.
7242 The program accepts the following options.  Also see @ref{Common options}.
7244 @table @samp
7245 @item -a
7246 @itemx --archive
7247 @opindex -a
7248 @opindex --archive
7249 Preserve as much as possible of the structure and attributes of the
7250 original files in the copy (but do not attempt to preserve internal
7251 directory structure; i.e., @samp{ls -U} may list the entries in a copied
7252 directory in a different order).
7253 Equivalent to @option{-dpR}.
7255 @item -b
7256 @itemx @w{@kbd{--backup}[=@var{method}]}
7257 @opindex -b
7258 @opindex --backup
7259 @vindex VERSION_CONTROL
7260 @cindex backups, making
7261 @xref{Backup options}.
7262 Make a backup of each file that would otherwise be overwritten or removed.
7263 As a special case, @command{cp} makes a backup of @var{source} when the force
7264 and backup options are given and @var{source} and @var{dest} are the same
7265 name for an existing, regular file.  One useful application of this
7266 combination of options is this tiny Bourne shell script:
7268 @example
7269 #!/bin/sh
7270 # Usage: backup FILE...
7271 # Create a @sc{gnu}-style backup of each listed FILE.
7272 for i; do
7273   cp --backup --force -- "$i" "$i"
7274 done
7275 @end example
7277 @item --copy-contents
7278 @cindex directories, copying recursively
7279 @cindex copying directories recursively
7280 @cindex recursively copying directories
7281 @cindex non-directories, copying as special files
7282 If copying recursively, copy the contents of any special files (e.g.,
7283 FIFOs and device files) as if they were regular files.  This means
7284 trying to read the data in each source file and writing it to the
7285 destination.  It is usually a mistake to use this option, as it
7286 normally has undesirable effects on special files like FIFOs and the
7287 ones typically found in the @file{/dev} directory.  In most cases,
7288 @code{cp -R --copy-contents} will hang indefinitely trying to read
7289 from FIFOs and special files like @file{/dev/console}, and it will
7290 fill up your destination disk if you use it to copy @file{/dev/zero}.
7291 This option has no effect unless copying recursively, and it does not
7292 affect the copying of symbolic links.
7294 @item -d
7295 @opindex -d
7296 @cindex symbolic links, copying
7297 @cindex hard links, preserving
7298 Copy symbolic links as symbolic links rather than copying the files that
7299 they point to, and preserve hard links between source files in the copies.
7300 Equivalent to @option{--no-dereference --preserve=links}.
7302 @item -f
7303 @itemx --force
7304 @opindex -f
7305 @opindex --force
7306 When copying without this option and an existing destination file cannot
7307 be opened for writing, the copy fails.  However, with @option{--force}),
7308 when a destination file cannot be opened, @command{cp} then removes it and
7309 tries to open it again.  Contrast this behavior with that enabled by
7310 @option{--link} and @option{--symbolic-link}, whereby the destination file
7311 is never opened but rather is removed unconditionally.  Also see the
7312 description of @option{--remove-destination}.
7314 This option is independent of the @option{--interactive} or
7315 @option{-i} option: neither cancels the effect of the other.
7317 This option is redundant if the @option{--no-clobber} or @option{-n} option is
7318 used.
7320 @item -H
7321 @opindex -H
7322 If a command line argument specifies a symbolic link, then copy the
7323 file it points to rather than the symbolic link itself.  However,
7324 copy (preserving its nature) any symbolic link that is encountered
7325 via recursive traversal.
7327 @item -i
7328 @itemx --interactive
7329 @opindex -i
7330 @opindex --interactive
7331 When copying a file other than a directory, prompt whether to
7332 overwrite an existing destination file. The @option{-i} option overrides
7333 a previous @option{-n} option.
7335 @item -l
7336 @itemx --link
7337 @opindex -l
7338 @opindex --link
7339 Make hard links instead of copies of non-directories.
7341 @item -L
7342 @itemx --dereference
7343 @opindex -L
7344 @opindex --dereference
7345 Follow symbolic links when copying from them.
7347 @item -n
7348 @itemx --no-clobber
7349 @opindex -n
7350 @opindex --no-clobber
7351 Do not overwrite an existing file. The @option{-n} option overrides a previous
7352 @option{-i} option. This option is mutually exclusive with @option{-b} or
7353 @option{--backup} option.
7355 @item -P
7356 @itemx --no-dereference
7357 @opindex -P
7358 @opindex --no-dereference
7359 @cindex symbolic links, copying
7360 Copy symbolic links as symbolic links rather than copying the files that
7361 they point to.  This option affects only symbolic links in the source;
7362 symbolic links in the destination are always followed if possible.
7364 @item -p
7365 @itemx @w{@kbd{--preserve}[=@var{attribute_list}]}
7366 @opindex -p
7367 @opindex --preserve
7368 @cindex file information, preserving, extended attributes, xattr
7369 Preserve the specified attributes of the original files.
7370 If specified, the @var{attribute_list} must be a comma-separated list
7371 of one or more of the following strings:
7373 @table @samp
7374 @itemx mode
7375 Preserve the file mode bits and access control lists.
7376 @itemx ownership
7377 Preserve the owner and group.  On most modern systems,
7378 only users with appropriate privileges may change the owner of a file,
7379 and ordinary users
7380 may preserve the group ownership of a file only if they happen to be
7381 a member of the desired group.
7382 @itemx timestamps
7383 Preserve the times of last access and last modification, when possible.
7384 In general, it is not possible to preserve these attributes
7385 when the affected file is a symbolic link.
7386 However, FreeBSD now provides the @code{lutimes} function, which makes
7387 it possible even for symbolic links.  However, this implementation does
7388 not yet take advantage of that.
7389 @c FIXME: once we provide lutimes support, update the above.
7390 @itemx links
7391 Preserve in the destination files
7392 any links between corresponding source files.
7393 @c Give examples illustrating how hard links are preserved.
7394 @c Also, show how soft links map to hard links with -L and -H.
7395 @itemx xattr
7396 Preserve extended attributes if @command{cp} is built with xattr support,
7397 and xattrs are supported and enabled on your file system.
7398 If SELinux context and/or ACLs are implemented using xattrs,
7399 they are preserved by this option as well.
7400 @itemx all
7401 Preserve all file attributes.
7402 Equivalent to specifying all of the above.
7403 @end table
7405 Using @option{--preserve} with no @var{attribute_list} is equivalent
7406 to @option{--preserve=mode,ownership,timestamps}.
7408 In the absence of this option, each destination file is created with the
7409 mode bits of the corresponding source file, minus the bits set in the
7410 umask and minus the set-user-ID and set-group-ID bits.
7411 @xref{File permissions}.
7413 @itemx @w{@kbd{--no-preserve}=@var{attribute_list}}
7414 @cindex file information, preserving
7415 Do not preserve the specified attributes.  The @var{attribute_list}
7416 has the same form as for @option{--preserve}.
7418 @itemx --parents
7419 @opindex --parents
7420 @cindex parent directories and @command{cp}
7421 Form the name of each destination file by appending to the target
7422 directory a slash and the specified name of the source file.  The last
7423 argument given to @command{cp} must be the name of an existing directory.
7424 For example, the command:
7426 @example
7427 cp --parents a/b/c existing_dir
7428 @end example
7430 @noindent
7431 copies the file @file{a/b/c} to @file{existing_dir/a/b/c}, creating
7432 any missing intermediate directories.
7434 @item -R
7435 @itemx -r
7436 @itemx --recursive
7437 @opindex -R
7438 @opindex -r
7439 @opindex --recursive
7440 @cindex directories, copying recursively
7441 @cindex copying directories recursively
7442 @cindex recursively copying directories
7443 @cindex non-directories, copying as special files
7444 Copy directories recursively.  By default, do not follow symbolic
7445 links in the source; see the @option{--archive} (@option{-a}), @option{-d},
7446 @option{--dereference} (@option{-L}), @option{--no-dereference}
7447 (@option{-P}), and @option{-H} options.  Special files are copied by
7448 creating a destination file of the same type as the source; see the
7449 @option{--copy-contents} option.  It is not portable to use
7450 @option{-r} to copy symbolic links or special files.  On some
7451 non-@sc{gnu} systems, @option{-r} implies the equivalent of
7452 @option{-L} and @option{--copy-contents} for historical reasons.
7453 Also, it is not portable to use @option{-R} to copy symbolic links
7454 unless you also specify @option{-P}, as @acronym{POSIX} allows
7455 implementations that dereference symbolic links by default.
7457 @item --remove-destination
7458 @opindex --remove-destination
7459 Remove each existing destination file before attempting to open it
7460 (contrast with @option{-f} above).
7462 @item --sparse=@var{when}
7463 @opindex --sparse=@var{when}
7464 @cindex sparse files, copying
7465 @cindex holes, copying files with
7466 @findex read @r{system call, and holes}
7467 A @dfn{sparse file} contains @dfn{holes}---a sequence of zero bytes that
7468 does not occupy any physical disk blocks; the @samp{read} system call
7469 reads these as zeros.  This can both save considerable disk space and
7470 increase speed, since many binary files contain lots of consecutive zero
7471 bytes.  By default, @command{cp} detects holes in input source files via a crude
7472 heuristic and makes the corresponding output file sparse as well.
7473 Only regular files may be sparse.
7475 The @var{when} value can be one of the following:
7477 @table @samp
7478 @item auto
7479 The default behavior: if the input file is sparse, attempt to make
7480 the output file sparse, too.  However, if an output file exists but
7481 refers to a non-regular file, then do not attempt to make it sparse.
7483 @item always
7484 For each sufficiently long sequence of zero bytes in the input file,
7485 attempt to create a corresponding hole in the output file, even if the
7486 input file does not appear to be sparse.
7487 This is useful when the input file resides on a file system
7488 that does not support sparse files
7489 (for example,  @samp{efs} file systems in SGI IRIX 5.3 and earlier),
7490 but the output file is on a type of file system that does support them.
7491 Holes may be created only in regular files, so if the destination file
7492 is of some other type, @command{cp} does not even try to make it sparse.
7494 @item never
7495 Never make the output file sparse.
7496 This is useful in creating a file for use with the @command{mkswap} command,
7497 since such a file must not have any holes.
7498 @end table
7500 @optStripTrailingSlashes
7502 @item -s
7503 @itemx --symbolic-link
7504 @opindex -s
7505 @opindex --symbolic-link
7506 @cindex symbolic links, copying with
7507 Make symbolic links instead of copies of non-directories.  All source
7508 file names must be absolute (starting with @samp{/}) unless the
7509 destination files are in the current directory.  This option merely
7510 results in an error message on systems that do not support symbolic links.
7512 @optBackupSuffix
7514 @optTargetDirectory
7516 @optNoTargetDirectory
7518 @item -u
7519 @itemx --update
7520 @opindex -u
7521 @opindex --update
7522 @cindex newer files, copying only
7523 Do not copy a non-directory that has an existing destination with the
7524 same or newer modification time.  If time stamps are being preserved,
7525 the comparison is to the source time stamp truncated to the
7526 resolutions of the destination file system and of the system calls
7527 used to update time stamps; this avoids duplicate work if several
7528 @samp{cp -pu} commands are executed with the same source and
7529 destination.
7531 @item -v
7532 @itemx --verbose
7533 @opindex -v
7534 @opindex --verbose
7535 Print the name of each file before copying it.
7537 @item -x
7538 @itemx --one-file-system
7539 @opindex -x
7540 @opindex --one-file-system
7541 @cindex file systems, omitting copying to different
7542 Skip subdirectories that are on different file systems from the one that
7543 the copy started on.
7544 However, mount point directories @emph{are} copied.
7546 @end table
7548 @exitstatus
7551 @node dd invocation
7552 @section @command{dd}: Convert and copy a file
7554 @pindex dd
7555 @cindex converting while copying a file
7557 @command{dd} copies a file (from standard input to standard output, by
7558 default) with a changeable I/O block size, while optionally performing
7559 conversions on it.  Synopses:
7561 @example
7562 dd [@var{operand}]@dots{}
7563 dd @var{option}
7564 @end example
7566 The only options are @option{--help} and @option{--version}.
7567 @xref{Common options}.  @command{dd} accepts the following operands.
7569 @table @samp
7571 @item if=@var{file}
7572 @opindex if
7573 Read from @var{file} instead of standard input.
7575 @item of=@var{file}
7576 @opindex of
7577 Write to @var{file} instead of standard output.  Unless
7578 @samp{conv=notrunc} is given, @command{dd} truncates @var{file} to zero
7579 bytes (or the size specified with @samp{seek=}).
7581 @item ibs=@var{bytes}
7582 @opindex ibs
7583 @cindex block size of input
7584 @cindex input block size
7585 Set the input block size to @var{bytes}.
7586 This makes @command{dd} read @var{bytes} per block.
7588 @item obs=@var{bytes}
7589 @opindex obs
7590 @cindex block size of output
7591 @cindex output block size
7592 Set the output block size to @var{bytes}.
7593 This makes @command{dd} write @var{bytes} per block.
7595 @item bs=@var{bytes}
7596 @opindex bs
7597 @cindex block size
7598 Set both input and output block sizes to @var{bytes}.
7599 This makes @command{dd} read and write @var{bytes} per block,
7600 overriding any @samp{ibs} and @samp{obs} settings.
7601 In addition, if no data-transforming @option{conv} option is specified,
7602 each input block is copied to the output as a single block,
7603 without aggregating short reads.
7605 @item cbs=@var{bytes}
7606 @opindex cbs
7607 @cindex block size of conversion
7608 @cindex conversion block size
7609 @cindex fixed-length records, converting to variable-length
7610 @cindex variable-length records, converting to fixed-length
7611 Set the conversion block size to @var{bytes}.
7612 When converting variable-length records to fixed-length ones
7613 (@option{conv=block}) or the reverse (@option{conv=unblock}),
7614 use @var{bytes} as the fixed record length.
7616 @item skip=@var{blocks}
7617 @opindex skip
7618 Skip @var{blocks} @samp{ibs}-byte blocks in the input file before copying.
7620 @item seek=@var{blocks}
7621 @opindex seek
7622 Skip @var{blocks} @samp{obs}-byte blocks in the output file before copying.
7624 @item count=@var{blocks}
7625 @opindex count
7626 Copy @var{blocks} @samp{ibs}-byte blocks from the input file, instead
7627 of everything until the end of the file.
7629 @item conv=@var{conversion}[,@var{conversion}]@dots{}
7630 @opindex conv
7631 Convert the file as specified by the @var{conversion} argument(s).
7632 (No spaces around any comma(s).)
7634 Conversions:
7636 @table @samp
7638 @item ascii
7639 @opindex ascii@r{, converting to}
7640 Convert @acronym{EBCDIC} to @acronym{ASCII},
7641 using the conversion table specified by @acronym{POSIX}.
7642 This provides a 1:1 translation for all 256 bytes.
7644 @item ebcdic
7645 @opindex ebcdic@r{, converting to}
7646 Convert @acronym{ASCII} to @acronym{EBCDIC}.
7647 This is the inverse of the @samp{ascii} conversion.
7649 @item ibm
7650 @opindex alternate ebcdic@r{, converting to}
7651 Convert @acronym{ASCII} to alternate @acronym{EBCDIC},
7652 using the alternate conversion table specified by @acronym{POSIX}.
7653 This is not a 1:1 translation, but reflects common historical practice
7654 for @samp{~}, @samp{[}, and @samp{]}.
7656 The @samp{ascii}, @samp{ebcdic}, and @samp{ibm} conversions are
7657 mutually exclusive.
7659 @item block
7660 @opindex block @r{(space-padding)}
7661 For each line in the input, output @samp{cbs} bytes, replacing the
7662 input newline with a space and padding with spaces as necessary.
7664 @item unblock
7665 @opindex unblock
7666 Replace trailing spaces in each @samp{cbs}-sized input block with a
7667 newline.
7669 The @samp{block} and @samp{unblock} conversions are mutually exclusive.
7671 @item lcase
7672 @opindex lcase@r{, converting to}
7673 Change uppercase letters to lowercase.
7675 @item ucase
7676 @opindex ucase@r{, converting to}
7677 Change lowercase letters to uppercase.
7679 The @samp{lcase} and @samp{ucase} conversions are mutually exclusive.
7681 @item swab
7682 @opindex swab @r{(byte-swapping)}
7683 @cindex byte-swapping
7684 Swap every pair of input bytes.  @sc{gnu} @command{dd}, unlike others, works
7685 when an odd number of bytes are read---the last byte is simply copied
7686 (since there is nothing to swap it with).
7688 @item noerror
7689 @opindex noerror
7690 @cindex read errors, ignoring
7691 Continue after read errors.
7693 @item nocreat
7694 @opindex nocreat
7695 @cindex creating output file, avoiding
7696 Do not create the output file; the output file must already exist.
7698 @item excl
7699 @opindex excl
7700 @cindex creating output file, requiring
7701 Fail if the output file already exists; @command{dd} must create the
7702 output file itself.
7704 The @samp{excl} and @samp{nocreat} conversions are mutually exclusive.
7706 @item notrunc
7707 @opindex notrunc
7708 @cindex truncating output file, avoiding
7709 Do not truncate the output file.
7711 @item sync
7712 @opindex sync @r{(padding with @acronym{ASCII} @sc{nul}s)}
7713 Pad every input block to size of @samp{ibs} with trailing zero bytes.
7714 When used with @samp{block} or @samp{unblock}, pad with spaces instead of
7715 zero bytes.
7717 @item fdatasync
7718 @opindex fdatasync
7719 @cindex synchronized data writes, before finishing
7720 Synchronize output data just before finishing.  This forces a physical
7721 write of output data.
7723 @item fsync
7724 @opindex fsync
7725 @cindex synchronized data and metadata writes, before finishing
7726 Synchronize output data and metadata just before finishing.  This
7727 forces a physical write of output data and metadata.
7729 @end table
7731 @item iflag=@var{flag}[,@var{flag}]@dots{}
7732 @opindex iflag
7733 Access the input file using the flags specified by the @var{flag}
7734 argument(s).  (No spaces around any comma(s).)
7736 @item oflag=@var{flag}[,@var{flag}]@dots{}
7737 @opindex oflag
7738 Access the output file using the flags specified by the @var{flag}
7739 argument(s).  (No spaces around any comma(s).)
7741 Here are the flags.  Not every flag is supported on every operating
7742 system.
7744 @table @samp
7746 @item append
7747 @opindex append
7748 @cindex appending to the output file
7749 Write in append mode, so that even if some other process is writing to
7750 this file, every @command{dd} write will append to the current
7751 contents of the file.  This flag makes sense only for output.
7752 If you combine this flag with the @samp{of=@var{file}} operand,
7753 you should also specify @samp{conv=notrunc} unless you want the
7754 output file to be truncated before being appended to.
7756 @item cio
7757 @opindex cio
7758 @cindex concurrent I/O
7759 Use concurrent I/O mode for data.  This mode performs direct I/O
7760 and drops the @acronym{POSIX} requirement to serialize all I/O to the same file.
7761 A file cannot be opened in CIO mode and with a standard open at the
7762 same time.
7764 @item direct
7765 @opindex direct
7766 @cindex direct I/O
7767 Use direct I/O for data, avoiding the buffer cache.
7769 @item directory
7770 @opindex directory
7771 @cindex directory I/O
7773 Fail unless the file is a directory.  Most operating systems do not
7774 allow I/O to a directory, so this flag has limited utility.
7776 @item dsync
7777 @opindex dsync
7778 @cindex synchronized data reads
7779 Use synchronized I/O for data.  For the output file, this forces a
7780 physical write of output data on each write.  For the input file,
7781 this flag can matter when reading from a remote file that has been
7782 written to synchronously by some other process.  Metadata (e.g.,
7783 last-access and last-modified time) is not necessarily synchronized.
7785 @item sync
7786 @opindex sync
7787 @cindex synchronized data and metadata I/O
7788 Use synchronized I/O for both data and metadata.
7790 @item nonblock
7791 @opindex nonblock
7792 @cindex nonblocking I/O
7793 Use non-blocking I/O.
7795 @item noatime
7796 @opindex noatime
7797 @cindex access time
7798 Do not update the file's access time.
7799 Some older file systems silently ignore this flag, so it is a good
7800 idea to test it on your files before relying on it.
7802 @item noctty
7803 @opindex noctty
7804 @cindex controlling terminal
7805 Do not assign the file to be a controlling terminal for @command{dd}.
7806 This has no effect when the file is not a terminal.
7807 On many hosts (e.g., @acronym{GNU}/Linux hosts), this option has no effect
7808 at all.
7810 @item nofollow
7811 @opindex nofollow
7812 @cindex symbolic links, following
7813 Do not follow symbolic links.
7815 @item nolinks
7816 @opindex nolinks
7817 @cindex hard links
7818 Fail if the file has multiple hard links.
7820 @item binary
7821 @opindex binary
7822 @cindex binary I/O
7823 Use binary I/O.  This option has an effect only on nonstandard
7824 platforms that distinguish binary from text I/O.
7826 @item text
7827 @opindex text
7828 @cindex text I/O
7829 Use text I/O.  Like @samp{binary}, this option has no effect on
7830 standard platforms.
7832 @item fullblock
7833 @opindex fullblock
7834 Accumulate full blocks from input.  The @code{read} system call
7835 may return early if a full block is not available.
7836 When that happens, continue calling @code{read} to fill the remainder
7837 of the block.
7838 This flag can be used only with @code{iflag}.
7840 @end table
7842 These flags are not supported on all systems, and @samp{dd} rejects
7843 attempts to use them when they are not supported.  When reading from
7844 standard input or writing to standard output, the @samp{nofollow} and
7845 @samp{noctty} flags should not be specified, and the other flags
7846 (e.g., @samp{nonblock}) can affect how other processes behave with the
7847 affected file descriptors, even after @command{dd} exits.
7849 @end table
7851 @cindex multipliers after numbers
7852 The numeric-valued strings above (@var{bytes} and @var{blocks}) can be
7853 followed by a multiplier: @samp{b}=512, @samp{c}=1,
7854 @samp{w}=2, @samp{x@var{m}}=@var{m}, or any of the
7855 standard block size suffixes like @samp{k}=1024 (@pxref{Block size}).
7857 Use different @command{dd} invocations to use different block sizes for
7858 skipping and I/O@.  For example, the following shell commands copy data
7859 in 512 KiB blocks between a disk and a tape, but do not save or restore a
7860 4 KiB label at the start of the disk:
7862 @example
7863 disk=/dev/rdsk/c0t1d0s2
7864 tape=/dev/rmt/0
7866 # Copy all but the label from disk to tape.
7867 (dd bs=4k skip=1 count=0 && dd bs=512k) <$disk >$tape
7869 # Copy from tape back to disk, but leave the disk label alone.
7870 (dd bs=4k seek=1 count=0 && dd bs=512k) <$tape >$disk
7871 @end example
7873 Sending an @samp{INFO} signal to a running @command{dd}
7874 process makes it print I/O statistics to standard error
7875 and then resume copying.  In the example below,
7876 @command{dd} is run in the background to copy 10 million blocks.
7877 The @command{kill} command makes it output intermediate I/O statistics,
7878 and when @command{dd} completes normally or is killed by the
7879 @code{SIGINT} signal, it outputs the final statistics.
7881 @example
7882 $ dd if=/dev/zero of=/dev/null count=10MB & pid=$!
7883 $ kill -s INFO $pid; wait $pid
7884 3385223+0 records in
7885 3385223+0 records out
7886 1733234176 bytes (1.7 GB) copied, 6.42173 seconds, 270 MB/s
7887 10000000+0 records in
7888 10000000+0 records out
7889 5120000000 bytes (5.1 GB) copied, 18.913 seconds, 271 MB/s
7890 @end example
7892 @vindex POSIXLY_CORRECT
7893 On systems lacking the @samp{INFO} signal @command{dd} responds to the
7894 @samp{USR1} signal instead, unless the @env{POSIXLY_CORRECT}
7895 environment variable is set.
7897 @exitstatus
7900 @node install invocation
7901 @section @command{install}: Copy files and set attributes
7903 @pindex install
7904 @cindex copying files and setting attributes
7906 @command{install} copies files while setting their file mode bits and, if
7907 possible, their owner and group.  Synopses:
7909 @example
7910 install [@var{option}]@dots{} [-T] @var{source} @var{dest}
7911 install [@var{option}]@dots{} @var{source}@dots{} @var{directory}
7912 install [@var{option}]@dots{} -t @var{directory} @var{source}@dots{}
7913 install [@var{option}]@dots{} -d @var{directory}@dots{}
7914 @end example
7916 @itemize @bullet
7917 @item
7918 If two file names are given, @command{install} copies the first file to the
7919 second.
7921 @item
7922 If the @option{--target-directory} (@option{-t}) option is given, or
7923 failing that if the last file is a directory and the
7924 @option{--no-target-directory} (@option{-T}) option is not given,
7925 @command{install} copies each @var{source} file to the specified
7926 directory, using the @var{source}s' names.
7928 @item
7929 If the @option{--directory} (@option{-d}) option is given,
7930 @command{install} creates each @var{directory} and any missing parent
7931 directories.  Parent directories are created with mode
7932 @samp{u=rwx,go=rx} (755), regardless of the @option{-m} option or the
7933 current umask.  @xref{Directory Setuid and Setgid}, for how the
7934 set-user-ID and set-group-ID bits of parent directories are inherited.
7935 @end itemize
7937 @cindex Makefiles, installing programs in
7938 @command{install} is similar to @command{cp}, but allows you to control the
7939 attributes of destination files.  It is typically used in Makefiles to
7940 copy programs into their destination directories.  It refuses to copy
7941 files onto themselves.
7943 @cindex extended attributes, xattr
7944 @command{install} never preserves extended attributes (xattr).
7946 The program accepts the following options.  Also see @ref{Common options}.
7948 @table @samp
7950 @optBackup
7952 @item -c
7953 @opindex -c
7954 Ignored; for compatibility with old Unix versions of @command{install}.
7956 @item -D
7957 @opindex -D
7958 Create any missing parent directories of @var{dest},
7959 then copy @var{source} to @var{dest}.
7960 This option is ignored if a destination directory is specified
7961 via @option{--target-directory=DIR}.
7963 @item -d
7964 @itemx --directory
7965 @opindex -d
7966 @opindex --directory
7967 @cindex directories, creating with given attributes
7968 @cindex parent directories, creating missing
7969 @cindex leading directories, creating missing
7970 Create any missing parent directories, giving them the default
7971 attributes.  Then create each given directory, setting their owner,
7972 group and mode as given on the command line or to the defaults.
7974 @item -g @var{group}
7975 @itemx --group=@var{group}
7976 @opindex -g
7977 @opindex --group
7978 @cindex group ownership of installed files, setting
7979 Set the group ownership of installed files or directories to
7980 @var{group}.  The default is the process's current group.  @var{group}
7981 may be either a group name or a numeric group ID.
7983 @item -m @var{mode}
7984 @itemx --mode=@var{mode}
7985 @opindex -m
7986 @opindex --mode
7987 @cindex permissions of installed files, setting
7988 Set the file mode bits for the installed file or directory to @var{mode},
7989 which can be either an octal number, or a symbolic mode as in
7990 @command{chmod}, with @samp{a=} (no access allowed to anyone) as the
7991 point of departure (@pxref{File permissions}).
7992 The default mode is @samp{u=rwx,go=rx,a-s}---read, write, and
7993 execute for the owner, read and execute for group and other, and with
7994 set-user-ID and set-group-ID disabled.
7995 This default is not quite the same as @samp{755}, since it disables
7996 instead of preserving set-user-ID and set-group-ID on directories.
7997 @xref{Directory Setuid and Setgid}.
7999 @item -o @var{owner}
8000 @itemx --owner=@var{owner}
8001 @opindex -o
8002 @opindex --owner
8003 @cindex ownership of installed files, setting
8004 @cindex appropriate privileges
8005 @vindex root @r{as default owner}
8006 If @command{install} has appropriate privileges (is run as root), set the
8007 ownership of installed files or directories to @var{owner}.  The default
8008 is @code{root}.  @var{owner} may be either a user name or a numeric user
8011 @item -p
8012 @itemx --preserve-timestamps
8013 @opindex -p
8014 @opindex --preserve-timestamps
8015 @cindex timestamps of installed files, preserving
8016 Set the time of last access and the time of last modification of each
8017 installed file to match those of each corresponding original file.
8018 When a file is installed without this option, its last access and
8019 last modification times are both set to the time of installation.
8020 This option is useful if you want to use the last modification times
8021 of installed files to keep track of when they were last built as opposed
8022 to when they were last installed.
8024 @item -s
8025 @itemx --strip
8026 @opindex -s
8027 @opindex --strip
8028 @cindex symbol table information, stripping
8029 @cindex stripping symbol table information
8030 Strip the symbol tables from installed binary executables.
8032 @itemx --strip-program=@var{program}
8033 @opindex --strip-program
8034 @cindex symbol table information, stripping, program
8035 Program used to strip binaries.
8037 @optBackupSuffix
8039 @optTargetDirectory
8041 @optNoTargetDirectory
8043 @item -v
8044 @itemx --verbose
8045 @opindex -v
8046 @opindex --verbose
8047 Print the name of each file before copying it.
8049 @end table
8051 @exitstatus
8054 @node mv invocation
8055 @section @command{mv}: Move (rename) files
8057 @pindex mv
8059 @command{mv} moves or renames files (or directories).  Synopses:
8061 @example
8062 mv [@var{option}]@dots{} [-T] @var{source} @var{dest}
8063 mv [@var{option}]@dots{} @var{source}@dots{} @var{directory}
8064 mv [@var{option}]@dots{} -t @var{directory} @var{source}@dots{}
8065 @end example
8067 @itemize @bullet
8068 @item
8069 If two file names are given, @command{mv} moves the first file to the
8070 second.
8072 @item
8073 If the @option{--target-directory} (@option{-t}) option is given, or
8074 failing that if the last file is a directory and the
8075 @option{--no-target-directory} (@option{-T}) option is not given,
8076 @command{mv} moves each @var{source} file to the specified
8077 directory, using the @var{source}s' names.
8078 @end itemize
8080 @command{mv} can move any type of file from one file system to another.
8081 Prior to version @code{4.0} of the fileutils,
8082 @command{mv} could move only regular files between file systems.
8083 For example, now @command{mv} can move an entire directory hierarchy
8084 including special device files from one partition to another.  It first
8085 uses some of the same code that's used by @code{cp -a} to copy the
8086 requested directories and files, then (assuming the copy succeeded)
8087 it removes the originals.  If the copy fails, then the part that was
8088 copied to the destination partition is removed.  If you were to copy
8089 three directories from one partition to another and the copy of the first
8090 directory succeeded, but the second didn't, the first would be left on
8091 the destination partition and the second and third would be left on the
8092 original partition.
8094 @cindex extended attributes, xattr
8095 @command{mv} always tries to copy extended attributes (xattr).
8097 @cindex prompting, and @command{mv}
8098 If a destination file exists but is normally unwritable, standard input
8099 is a terminal, and the @option{-f} or @option{--force} option is not given,
8100 @command{mv} prompts the user for whether to replace the file.  (You might
8101 own the file, or have write permission on its directory.)  If the
8102 response is not affirmative, the file is skipped.
8104 @emph{Warning}: Avoid specifying a source name with a trailing slash,
8105 when it might be a symlink to a directory.
8106 Otherwise, @command{mv} may do something very surprising, since
8107 its behavior depends on the underlying rename system call.
8108 On a system with a modern Linux-based kernel, it fails with @code{errno=ENOTDIR}.
8109 However, on other systems (at least FreeBSD 6.1 and Solaris 10) it silently
8110 renames not the symlink but rather the directory referenced by the symlink.
8111 @xref{Trailing slashes}.
8113 The program accepts the following options.  Also see @ref{Common options}.
8115 @table @samp
8117 @optBackup
8119 @item -f
8120 @itemx --force
8121 @opindex -f
8122 @opindex --force
8123 @cindex prompts, omitting
8124 Do not prompt the user before removing a destination file.
8125 @macro mvOptsIfn
8126 If you specify more than one of the @option{-i}, @option{-f}, @option{-n}
8127 options, only the final one takes effect.
8128 @end macro
8129 @mvOptsIfn
8131 @item -i
8132 @itemx --interactive
8133 @opindex -i
8134 @opindex --interactive
8135 @cindex prompts, forcing
8136 Prompt whether to overwrite each existing destination file, regardless
8137 of its permissions.
8138 If the response is not affirmative, the file is skipped.
8139 @mvOptsIfn
8141 @item -n
8142 @itemx --no-clobber
8143 @opindex -n
8144 @opindex --no-clobber
8145 @cindex prompts, omitting
8146 Do not overwrite an existing file.
8147 @mvOptsIfn
8148 This option is mutually exclusive with @option{-b} or @option{--backup} option.
8150 @item -u
8151 @itemx --update
8152 @opindex -u
8153 @opindex --update
8154 @cindex newer files, moving only
8155 Do not move a non-directory that has an existing destination with the
8156 same or newer modification time.
8157 If the move is across file system boundaries, the comparison is to the
8158 source time stamp truncated to the resolutions of the destination file
8159 system and of the system calls used to update time stamps; this avoids
8160 duplicate work if several @samp{mv -u} commands are executed with the
8161 same source and destination.
8163 @item -v
8164 @itemx --verbose
8165 @opindex -v
8166 @opindex --verbose
8167 Print the name of each file before moving it.
8169 @optStripTrailingSlashes
8171 @optBackupSuffix
8173 @optTargetDirectory
8175 @optNoTargetDirectory
8177 @end table
8179 @exitstatus
8182 @node rm invocation
8183 @section @command{rm}: Remove files or directories
8185 @pindex rm
8186 @cindex removing files or directories
8188 @command{rm} removes each given @var{file}.  By default, it does not remove
8189 directories.  Synopsis:
8191 @example
8192 rm [@var{option}]@dots{} [@var{file}]@dots{}
8193 @end example
8195 @cindex prompting, and @command{rm}
8196 If the @option{-I} or @option{--interactive=once} option is given,
8197 and there are more than three files or the @option{-r}, @option{-R},
8198 or @option{--recursive} are given, then @command{rm} prompts the user
8199 for whether to proceed with the entire operation.  If the response is
8200 not affirmative, the entire command is aborted.
8202 Otherwise, if a file is unwritable, standard input is a terminal, and
8203 the @option{-f} or @option{--force} option is not given, or the
8204 @option{-i} or @option{--interactive=always} option @emph{is} given,
8205 @command{rm} prompts the user for whether to remove the file.
8206 If the response is not affirmative, the file is skipped.
8208 Any attempt to remove a file whose last file name component is
8209 @file{.} or @file{..} is rejected without any prompting.
8211 @emph{Warning}: If you use @command{rm} to remove a file, it is usually
8212 possible to recover the contents of that file.  If you want more assurance
8213 that the contents are truly unrecoverable, consider using @command{shred}.
8215 The program accepts the following options.  Also see @ref{Common options}.
8217 @table @samp
8219 @item -f
8220 @itemx --force
8221 @opindex -f
8222 @opindex --force
8223 Ignore nonexistent files and never prompt the user.
8224 Ignore any previous @option{--interactive} (@option{-i}) option.
8226 @item -i
8227 @opindex -i
8228 Prompt whether to remove each file.
8229 If the response is not affirmative, the file is skipped.
8230 Ignore any previous @option{--force} (@option{-f}) option.
8231 Equivalent to @option{--interactive=always}.
8233 @item -I
8234 @opindex -I
8235 Prompt once whether to proceed with the command, if more than three
8236 files are named or if a recursive removal is requested.  Ignore any
8237 previous @option{--force} (@option{-f}) option.  Equivalent to
8238 @option{--interactive=once}.
8240 @itemx --interactive [=@var{when}]
8241 @opindex --interactive
8242 Specify when to issue an interactive prompt.  @var{when} may be
8243 omitted, or one of:
8244 @itemize @bullet
8245 @item never
8246 @vindex never @r{interactive option}
8247 - Do not prompt at all.
8248 @item once
8249 @vindex once @r{interactive option}
8250 - Prompt once if more than three files are named or if a recursive
8251 removal is requested.  Equivalent to @option{-I}.
8252 @item always
8253 @vindex always @r{interactive option}
8254 - Prompt for every file being removed.  Equivalent to @option{-i}.
8255 @end itemize
8256 @option{--interactive} with no @var{when} is equivalent to
8257 @option{--interactive=always}.
8259 @itemx --one-file-system
8260 @opindex --one-file-system
8261 @cindex one file system, restricting @command{rm} to
8262 When removing a hierarchy recursively, skip any directory that is on a
8263 file system different from that of the corresponding command line argument.
8265 This option is useful when removing a build ``chroot'' hierarchy,
8266 which normally contains no valuable data.  However, it is not uncommon
8267 to bind-mount @file{/home} into such a hierarchy, to make it easier to
8268 use one's start-up file.  The catch is that it's easy to forget to
8269 unmount @file{/home}.  Then, when you use @command{rm -rf} to remove
8270 your normally throw-away chroot, that command will remove everything
8271 under @file{/home}, too.
8272 Use the @option{--one-file-system} option, and it will
8273 warn about and skip directories on other file systems.
8274 Of course, this will not save your @file{/home} if it and your
8275 chroot happen to be on the same file system.
8277 @itemx --preserve-root
8278 @opindex --preserve-root
8279 @cindex root directory, disallow recursive destruction
8280 Fail upon any attempt to remove the root directory, @file{/},
8281 when used with the @option{--recursive} option.
8282 This is the default behavior.
8283 @xref{Treating / specially}.
8285 @itemx --no-preserve-root
8286 @opindex --no-preserve-root
8287 @cindex root directory, allow recursive destruction
8288 Do not treat @file{/} specially when removing recursively.
8289 This option is not recommended unless you really want to
8290 remove all the files on your computer.
8291 @xref{Treating / specially}.
8293 @item -r
8294 @itemx -R
8295 @itemx --recursive
8296 @opindex -r
8297 @opindex -R
8298 @opindex --recursive
8299 @cindex directories, removing (recursively)
8300 Remove the listed directories and their contents recursively.
8302 @item -v
8303 @itemx --verbose
8304 @opindex -v
8305 @opindex --verbose
8306 Print the name of each file before removing it.
8308 @end table
8310 @cindex files beginning with @samp{-}, removing
8311 @cindex @samp{-}, removing files beginning with
8312 One common question is how to remove files whose names begin with a
8313 @samp{-}.  @sc{gnu} @command{rm}, like every program that uses the @code{getopt}
8314 function to parse its arguments, lets you use the @samp{--} option to
8315 indicate that all following arguments are non-options.  To remove a file
8316 called @file{-f} in the current directory, you could type either:
8318 @example
8319 rm -- -f
8320 @end example
8322 @noindent
8325 @example
8326 rm ./-f
8327 @end example
8329 @opindex - @r{and Unix @command{rm}}
8330 The Unix @command{rm} program's use of a single @samp{-} for this purpose
8331 predates the development of the getopt standard syntax.
8333 @exitstatus
8336 @node shred invocation
8337 @section @command{shred}: Remove files more securely
8339 @pindex shred
8340 @cindex data, erasing
8341 @cindex erasing data
8343 @command{shred} overwrites devices or files, to help prevent even
8344 very expensive hardware from recovering the data.
8346 Ordinarily when you remove a file (@pxref{rm invocation}), the data is
8347 not actually destroyed.  Only the index listing where the file is
8348 stored is destroyed, and the storage is made available for reuse.
8349 There are undelete utilities that will attempt to reconstruct the index
8350 and can bring the file back if the parts were not reused.
8352 On a busy system with a nearly-full drive, space can get reused in a few
8353 seconds.  But there is no way to know for sure.  If you have sensitive
8354 data, you may want to be sure that recovery is not possible by actually
8355 overwriting the file with non-sensitive data.
8357 However, even after doing that, it is possible to take the disk back
8358 to a laboratory and use a lot of sensitive (and expensive) equipment
8359 to look for the faint ``echoes'' of the original data underneath the
8360 overwritten data.  If the data has only been overwritten once, it's not
8361 even that hard.
8363 The best way to remove something irretrievably is to destroy the media
8364 it's on with acid, melt it down, or the like.  For cheap removable media
8365 like floppy disks, this is the preferred method.  However, hard drives
8366 are expensive and hard to melt, so the @command{shred} utility tries
8367 to achieve a similar effect non-destructively.
8369 This uses many overwrite passes, with the data patterns chosen to
8370 maximize the damage they do to the old data.  While this will work on
8371 floppies, the patterns are designed for best effect on hard drives.
8372 For more details, see the source code and Peter Gutmann's paper
8373 @uref{http://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html,
8374 @cite{Secure Deletion of Data from Magnetic and Solid-State Memory}},
8375 from the proceedings of the Sixth @acronym{USENIX} Security Symposium (San Jose,
8376 California, July 22--25, 1996).
8378 @strong{Please note} that @command{shred} relies on a very important assumption:
8379 that the file system overwrites data in place.  This is the traditional
8380 way to do things, but many modern file system designs do not satisfy this
8381 assumption.  Exceptions include:
8383 @itemize @bullet
8385 @item
8386 Log-structured or journaled file systems, such as those supplied with
8387 AIX and Solaris, and JFS, ReiserFS, XFS, Ext3 (in @code{data=journal} mode),
8388 BFS, NTFS, etc.@: when they are configured to journal @emph{data}.
8390 @item
8391 File systems that write redundant data and carry on even if some writes
8392 fail, such as RAID-based file systems.
8394 @item
8395 File systems that make snapshots, such as Network Appliance's NFS server.
8397 @item
8398 File systems that cache in temporary locations, such as NFS version 3
8399 clients.
8401 @item
8402 Compressed file systems.
8403 @end itemize
8405 In the particular case of ext3 file systems, the above disclaimer applies (and
8406 @command{shred} is thus of limited effectiveness) only in @code{data=journal}
8407 mode, which journals file data in addition to just metadata. In both
8408 the @code{data=ordered} (default) and @code{data=writeback} modes,
8409 @command{shred} works as usual.  Ext3 journaling modes can be changed
8410 by adding the @code{data=something} option to the mount options for a
8411 particular file system in the @file{/etc/fstab} file, as documented in
8412 the mount man page (man mount).
8414 If you are not sure how your file system operates, then you should assume
8415 that it does not overwrite data in place, which means that shred cannot
8416 reliably operate on regular files in your file system.
8418 Generally speaking, it is more reliable to shred a device than a file,
8419 since this bypasses the problem of file system design mentioned above.
8420 However, even shredding devices is not always completely reliable.  For
8421 example, most disks map out bad sectors invisibly to the application; if
8422 the bad sectors contain sensitive data, @command{shred} won't be able to
8423 destroy it.
8425 @command{shred} makes no attempt to detect or report this problem, just as
8426 it makes no attempt to do anything about backups.  However, since it is
8427 more reliable to shred devices than files, @command{shred} by default does
8428 not truncate or remove the output file.  This default is more suitable
8429 for devices, which typically cannot be truncated and should not be
8430 removed.
8432 Finally, consider the risk of backups and mirrors.
8433 File system backups and remote mirrors may contain copies of the
8434 file that cannot be removed, and that will allow a shredded file
8435 to be recovered later.  So if you keep any data you may later want
8436 to destroy using @command{shred}, be sure that it is not backed up or mirrored.
8438 @example
8439 shred [@var{option}]@dots{} @var{file}[@dots{}]
8440 @end example
8442 The program accepts the following options.  Also see @ref{Common options}.
8444 @table @samp
8446 @item -f
8447 @itemx --force
8448 @opindex -f
8449 @opindex --force
8450 @cindex force deletion
8451 Override file permissions if necessary to allow overwriting.
8453 @item -@var{number}
8454 @itemx -n @var{number}
8455 @itemx --iterations=@var{number}
8456 @opindex -n @var{number}
8457 @opindex --iterations=@var{number}
8458 @cindex iterations, selecting the number of
8459 By default, @command{shred} uses @value{SHRED_DEFAULT_PASSES} passes of
8460 overwrite. You can reduce this to save time, or increase it if you think it's
8461 appropriate. After 25 passes all of the internal overwrite patterns will have
8462 been used at least once.
8464 @item --random-source=@var{file}
8465 @opindex --random-source
8466 @cindex random source for shredding
8467 Use @var{file} as a source of random data used to overwrite and to
8468 choose pass ordering.  @xref{Random sources}.
8470 @item -s @var{bytes}
8471 @itemx --size=@var{bytes}
8472 @opindex -s @var{bytes}
8473 @opindex --size=@var{bytes}
8474 @cindex size of file to shred
8475 Shred the first @var{bytes} bytes of the file.  The default is to shred
8476 the whole file.  @var{bytes} can be followed by a size specification like
8477 @samp{K}, @samp{M}, or @samp{G} to specify a multiple.  @xref{Block size}.
8479 @item -u
8480 @itemx --remove
8481 @opindex -u
8482 @opindex --remove
8483 @cindex removing files after shredding
8484 After shredding a file, truncate it (if possible) and then remove it.
8485 If a file has multiple links, only the named links will be removed.
8487 @item -v
8488 @itemx --verbose
8489 @opindex -v
8490 @opindex --verbose
8491 Display to standard error all status updates as sterilization proceeds.
8493 @item -x
8494 @itemx --exact
8495 @opindex -x
8496 @opindex --exact
8497 By default, @command{shred} rounds the size of a regular file up to the next
8498 multiple of the file system block size to fully erase the last block of the file.
8499 Use @option{--exact} to suppress that behavior.
8500 Thus, by default if you shred a 10-byte regular file on a system with 512-byte
8501 blocks, the resulting file will be 512 bytes long.  With this option,
8502 shred does not increase the apparent size of the file.
8504 @item -z
8505 @itemx --zero
8506 @opindex -z
8507 @opindex --zero
8508 Normally, the last pass that @command{shred} writes is made up of
8509 random data.  If this would be conspicuous on your hard drive (for
8510 example, because it looks like encrypted data), or you just think
8511 it's tidier, the @option{--zero} option adds an additional overwrite pass with
8512 all zero bits.  This is in addition to the number of passes specified
8513 by the @option{--iterations} option.
8515 @end table
8517 You might use the following command to erase all trace of the
8518 file system you'd created on the floppy disk in your first drive.
8519 That command takes about 20 minutes to erase a ``1.44MB'' (actually
8520 1440 KiB) floppy.
8522 @example
8523 shred --verbose /dev/fd0
8524 @end example
8526 Similarly, to erase all data on a selected partition of
8527 your hard disk, you could give a command like this:
8529 @example
8530 shred --verbose /dev/sda5
8531 @end example
8533 A @var{file} of @samp{-} denotes standard output.
8534 The intended use of this is to shred a removed temporary file.
8535 For example:
8537 @example
8538 i=`tempfile -m 0600`
8539 exec 3<>"$i"
8540 rm -- "$i"
8541 echo "Hello, world" >&3
8542 shred - >&3
8543 exec 3>-
8544 @end example
8546 However, the command @samp{shred - >file} does not shred the contents
8547 of @var{file}, since the shell truncates @var{file} before invoking
8548 @command{shred}.  Use the command @samp{shred file} or (if using a
8549 Bourne-compatible shell) the command @samp{shred - 1<>file} instead.
8551 @exitstatus
8554 @node Special file types
8555 @chapter Special file types
8557 @cindex special file types
8558 @cindex file types, special
8560 This chapter describes commands which create special types of files (and
8561 @command{rmdir}, which removes directories, one special file type).
8563 @cindex special file types
8564 @cindex file types
8565 Although Unix-like operating systems have markedly fewer special file
8566 types than others, not @emph{everything} can be treated only as the
8567 undifferentiated byte stream of @dfn{normal files}.  For example, when a
8568 file is created or removed, the system must record this information,
8569 which it does in a @dfn{directory}---a special type of file.  Although
8570 you can read directories as normal files, if you're curious, in order
8571 for the system to do its job it must impose a structure, a certain
8572 order, on the bytes of the file.  Thus it is a ``special'' type of file.
8574 Besides directories, other special file types include named pipes
8575 (FIFOs), symbolic links, sockets, and so-called @dfn{special files}.
8577 @menu
8578 * link invocation::             Make a hard link via the link syscall
8579 * ln invocation::               Make links between files.
8580 * mkdir invocation::            Make directories.
8581 * mkfifo invocation::           Make FIFOs (named pipes).
8582 * mknod invocation::            Make block or character special files.
8583 * readlink invocation::         Print the referent of a symbolic link.
8584 * rmdir invocation::            Remove empty directories.
8585 * unlink invocation::           Remove files via the unlink syscall
8586 @end menu
8589 @node link invocation
8590 @section @command{link}: Make a hard link via the link syscall
8592 @pindex link
8593 @cindex links, creating
8594 @cindex hard links, creating
8595 @cindex creating links (hard only)
8597 @command{link} creates a single hard link at a time.
8598 It is a minimalist interface to the system-provided
8599 @code{link} function.  @xref{Hard Links, , , libc,
8600 The GNU C Library Reference Manual}.
8601 It avoids the bells and whistles of the more commonly-used
8602 @command{ln} command (@pxref{ln invocation}).
8603 Synopsis:
8605 @example
8606 link @var{filename} @var{linkname}
8607 @end example
8609 @var{filename} must specify an existing file, and @var{linkname}
8610 must specify a nonexistent entry in an existing directory.
8611 @command{link} simply calls @code{link (@var{filename}, @var{linkname})}
8612 to create the link.
8614 On a @acronym{GNU} system, this command acts like @samp{ln --directory
8615 --no-target-directory @var{filename} @var{linkname}}.  However, the
8616 @option{--directory} and @option{--no-target-directory} options are
8617 not specified by @acronym{POSIX}, and the @command{link} command is
8618 more portable in practice.
8620 @exitstatus
8623 @node ln invocation
8624 @section @command{ln}: Make links between files
8626 @pindex ln
8627 @cindex links, creating
8628 @cindex hard links, creating
8629 @cindex symbolic (soft) links, creating
8630 @cindex creating links (hard or soft)
8632 @cindex file systems and hard links
8633 @command{ln} makes links between files.  By default, it makes hard links;
8634 with the @option{-s} option, it makes symbolic (or @dfn{soft}) links.
8635 Synopses:
8637 @example
8638 ln [@var{option}]@dots{} [-T] @var{target} @var{linkname}
8639 ln [@var{option}]@dots{} @var{target}
8640 ln [@var{option}]@dots{} @var{target}@dots{} @var{directory}
8641 ln [@var{option}]@dots{} -t @var{directory} @var{target}@dots{}
8642 @end example
8644 @itemize @bullet
8646 @item
8647 If two file names are given, @command{ln} creates a link to the first
8648 file from the second.
8650 @item
8651 If one @var{target} is given, @command{ln} creates a link to that file
8652 in the current directory.
8654 @item
8655 If the @option{--target-directory} (@option{-t}) option is given, or
8656 failing that if the last file is a directory and the
8657 @option{--no-target-directory} (@option{-T}) option is not given,
8658 @command{ln} creates a link to each @var{target} file in the specified
8659 directory, using the @var{target}s' names.
8661 @end itemize
8663 Normally @command{ln} does not remove existing files.  Use the
8664 @option{--force} (@option{-f}) option to remove them unconditionally,
8665 the @option{--interactive} (@option{-i}) option to remove them
8666 conditionally, and the @option{--backup} (@option{-b}) option to
8667 rename them.
8669 @cindex hard link, defined
8670 @cindex inode, and hard links
8671 A @dfn{hard link} is another name for an existing file; the link and the
8672 original are indistinguishable.  Technically speaking, they share the
8673 same inode, and the inode contains all the information about a
8674 file---indeed, it is not incorrect to say that the inode @emph{is} the
8675 file.  On all existing implementations, you cannot make a hard link to
8676 a directory, and hard links cannot cross file system boundaries.  (These
8677 restrictions are not mandated by @acronym{POSIX}, however.)
8679 @cindex dereferencing symbolic links
8680 @cindex symbolic link, defined
8681 @dfn{Symbolic links} (@dfn{symlinks} for short), on the other hand, are
8682 a special file type (which not all kernels support: System V release 3
8683 (and older) systems lack symlinks) in which the link file actually
8684 refers to a different file, by name.  When most operations (opening,
8685 reading, writing, and so on) are passed the symbolic link file, the
8686 kernel automatically @dfn{dereferences} the link and operates on the
8687 target of the link.  But some operations (e.g., removing) work on the
8688 link file itself, rather than on its target.  @xref{Symbolic Links,,,
8689 libc, The GNU C Library Reference Manual}.
8691 The program accepts the following options.  Also see @ref{Common options}.
8693 @table @samp
8695 @optBackup
8697 @item -d
8698 @itemx -F
8699 @itemx --directory
8700 @opindex -d
8701 @opindex -F
8702 @opindex --directory
8703 @cindex hard links to directories
8704 Allow users with appropriate privileges to attempt to make hard links
8705 to directories.
8706 However, note that this will probably fail due to
8707 system restrictions, even for the super-user.
8709 @item -f
8710 @itemx --force
8711 @opindex -f
8712 @opindex --force
8713 Remove existing destination files.
8715 @item -i
8716 @itemx --interactive
8717 @opindex -i
8718 @opindex --interactive
8719 @cindex prompting, and @command{ln}
8720 Prompt whether to remove existing destination files.
8722 @item -n
8723 @itemx --no-dereference
8724 @opindex -n
8725 @opindex --no-dereference
8726 Do not treat the last operand specially when it is a symbolic link to
8727 a directory.  Instead, treat it as if it were a normal file.
8729 When the destination is an actual directory (not a symlink to one),
8730 there is no ambiguity.  The link is created in that directory.
8731 But when the specified destination is a symlink to a directory,
8732 there are two ways to treat the user's request.  @command{ln} can
8733 treat the destination just as it would a normal directory and create
8734 the link in it.  On the other hand, the destination can be viewed as a
8735 non-directory---as the symlink itself.  In that case, @command{ln}
8736 must delete or backup that symlink before creating the new link.
8737 The default is to treat a destination that is a symlink to a directory
8738 just like a directory.
8740 This option is weaker than the @option{--no-target-directory}
8741 (@option{-T}) option, so it has no effect if both options are given.
8743 @item -s
8744 @itemx --symbolic
8745 @opindex -s
8746 @opindex --symbolic
8747 Make symbolic links instead of hard links.  This option merely produces
8748 an error message on systems that do not support symbolic links.
8750 @optBackupSuffix
8752 @optTargetDirectory
8754 @optNoTargetDirectory
8756 @item -v
8757 @itemx --verbose
8758 @opindex -v
8759 @opindex --verbose
8760 Print the name of each file after linking it successfully.
8762 @end table
8764 @exitstatus
8766 Examples:
8768 @smallexample
8769 Bad Example:
8771 # Create link ../a pointing to a in that directory.
8772 # Not really useful because it points to itself.
8773 ln -s a ..
8775 Better Example:
8777 # Change to the target before creating symlinks to avoid being confused.
8778 cd ..
8779 ln -s adir/a .
8781 Bad Example:
8783 # Hard coded file names don't move well.
8784 ln -s $(pwd)/a /some/dir/
8786 Better Example:
8788 # Relative file names survive directory moves and also
8789 # work across networked file systems.
8790 ln -s afile anotherfile
8791 ln -s ../adir/afile yetanotherfile
8792 @end smallexample
8795 @node mkdir invocation
8796 @section @command{mkdir}: Make directories
8798 @pindex mkdir
8799 @cindex directories, creating
8800 @cindex creating directories
8802 @command{mkdir} creates directories with the specified names.  Synopsis:
8804 @example
8805 mkdir [@var{option}]@dots{} @var{name}@dots{}
8806 @end example
8808 @command{mkdir} creates each directory @var{name} in the order given.
8809 It reports an error if @var{name} already exists, unless the
8810 @option{-p} option is given and @var{name} is a directory.
8812 The program accepts the following options.  Also see @ref{Common options}.
8814 @table @samp
8816 @item -m @var{mode}
8817 @itemx --mode=@var{mode}
8818 @opindex -m
8819 @opindex --mode
8820 @cindex modes of created directories, setting
8821 Set the file permission bits of created directories to @var{mode},
8822 which uses the same syntax as
8823 in @command{chmod} and uses @samp{a=rwx} (read, write and execute allowed for
8824 everyone) for the point of the departure.  @xref{File permissions}.
8826 Normally the directory has the desired file mode bits at the moment it
8827 is created.  As a @acronym{GNU} extension, @var{mode} may also mention
8828 special mode bits, but in this case there may be a temporary window
8829 during which the directory exists but its special mode bits are
8830 incorrect.  @xref{Directory Setuid and Setgid}, for how the
8831 set-user-ID and set-group-ID bits of directories are inherited unless
8832 overridden in this way.
8834 @item -p
8835 @itemx --parents
8836 @opindex -p
8837 @opindex --parents
8838 @cindex parent directories, creating
8839 Make any missing parent directories for each argument, setting their
8840 file permission bits to the umask modified by @samp{u+wx}.  Ignore
8841 existing parent directories, and do not change their file permission
8842 bits.
8844 To set the file permission bits of any newly-created parent
8845 directories to a value that includes @samp{u+wx}, you can set the
8846 umask before invoking @command{mkdir}.  For example, if the shell
8847 command @samp{(umask u=rwx,go=rx; mkdir -p P/Q)} creates the parent
8848 @file{P} it sets the parent's permission bits to @samp{u=rwx,go=rx}.
8849 To set a parent's special mode bits as well, you can invoke
8850 @command{chmod} after @command{mkdir}.  @xref{Directory Setuid and
8851 Setgid}, for how the set-user-ID and set-group-ID bits of
8852 newly-created parent directories are inherited.
8854 @item -v
8855 @itemx --verbose
8856 @opindex -v
8857 @opindex --verbose
8858 Print a message for each created directory.  This is most useful with
8859 @option{--parents}.
8860 @end table
8862 @exitstatus
8865 @node mkfifo invocation
8866 @section @command{mkfifo}: Make FIFOs (named pipes)
8868 @pindex mkfifo
8869 @cindex FIFOs, creating
8870 @cindex named pipes, creating
8871 @cindex creating FIFOs (named pipes)
8873 @command{mkfifo} creates FIFOs (also called @dfn{named pipes}) with the
8874 specified names.  Synopsis:
8876 @example
8877 mkfifo [@var{option}] @var{name}@dots{}
8878 @end example
8880 A @dfn{FIFO} is a special file type that permits independent processes
8881 to communicate.  One process opens the FIFO file for writing, and
8882 another for reading, after which data can flow as with the usual
8883 anonymous pipe in shells or elsewhere.
8885 The program accepts the following option.  Also see @ref{Common options}.
8887 @table @samp
8889 @item -m @var{mode}
8890 @itemx --mode=@var{mode}
8891 @opindex -m
8892 @opindex --mode
8893 @cindex modes of created FIFOs, setting
8894 Set the mode of created FIFOs to @var{mode}, which is symbolic as in
8895 @command{chmod} and uses @samp{a=rw} (read and write allowed for everyone)
8896 for the point of departure.  @var{mode} should specify only file
8897 permission bits.  @xref{File permissions}.
8899 @end table
8901 @exitstatus
8904 @node mknod invocation
8905 @section @command{mknod}: Make block or character special files
8907 @pindex mknod
8908 @cindex block special files, creating
8909 @cindex character special files, creating
8911 @command{mknod} creates a FIFO, character special file, or block special
8912 file with the specified name.  Synopsis:
8914 @example
8915 mknod [@var{option}]@dots{} @var{name} @var{type} [@var{major} @var{minor}]
8916 @end example
8918 @cindex special files
8919 @cindex block special files
8920 @cindex character special files
8921 Unlike the phrase ``special file type'' above, the term @dfn{special
8922 file} has a technical meaning on Unix: something that can generate or
8923 receive data.  Usually this corresponds to a physical piece of hardware,
8924 e.g., a printer or a disk.  (These files are typically created at
8925 system-configuration time.)  The @command{mknod} command is what creates
8926 files of this type.  Such devices can be read either a character at a
8927 time or a ``block'' (many characters) at a time, hence we say there are
8928 @dfn{block special} files and @dfn{character special} files.
8930 @c mknod is a shell built-in at least with OpenBSD's /bin/sh
8931 @mayConflictWithShellBuiltIn{mknod}
8933 The arguments after @var{name} specify the type of file to make:
8935 @table @samp
8937 @item p
8938 @opindex p @r{for FIFO file}
8939 for a FIFO
8941 @item b
8942 @opindex b @r{for block special file}
8943 for a block special file
8945 @item c
8946 @c Don't document the `u' option -- it's just a synonym for `c'.
8947 @c Do *any* versions of mknod still use it?
8948 @c @itemx u
8949 @opindex c @r{for character special file}
8950 @c @opindex u @r{for character special file}
8951 for a character special file
8953 @end table
8955 When making a block or character special file, the major and minor
8956 device numbers must be given after the file type.
8957 If a major or minor device number begins with @samp{0x} or @samp{0X},
8958 it is interpreted as hexadecimal; otherwise, if it begins with @samp{0},
8959 as octal; otherwise, as decimal.
8961 The program accepts the following option.  Also see @ref{Common options}.
8963 @table @samp
8965 @item -m @var{mode}
8966 @itemx --mode=@var{mode}
8967 @opindex -m
8968 @opindex --mode
8969 Set the mode of created files to @var{mode}, which is symbolic as in
8970 @command{chmod} and uses @samp{a=rw} as the point of departure.
8971 @var{mode} should specify only file permission bits.
8972 @xref{File permissions}.
8974 @end table
8976 @exitstatus
8979 @node readlink invocation
8980 @section @command{readlink}: Print the referent of a symbolic link
8982 @pindex readlink
8983 @cindex displaying value of a symbolic link
8985 @command{readlink} may work in one of two supported modes:
8987 @table @samp
8989 @item Readlink mode
8991 @command{readlink} outputs the value of the given symbolic link.
8992 If @command{readlink} is invoked with an argument other than the name
8993 of a symbolic link, it produces no output and exits with a nonzero exit code.
8995 @item Canonicalize mode
8997 @command{readlink} outputs the absolute name of the given file which contains
8998 no @file{.}, @file{..} components nor any repeated separators
8999 (@file{/}) or symbolic links.
9001 @end table
9003 @example
9004 readlink [@var{option}] @var{file}
9005 @end example
9007 By default, @command{readlink} operates in readlink mode.
9009 The program accepts the following options.  Also see @ref{Common options}.
9011 @table @samp
9013 @item -f
9014 @itemx --canonicalize
9015 @opindex -f
9016 @opindex --canonicalize
9017 Activate canonicalize mode.
9018 If any component of the file name except the last one is missing or unavailable,
9019 @command{readlink} produces no output and exits with a nonzero exit code.
9021 @item -e
9022 @itemx --canonicalize-existing
9023 @opindex -e
9024 @opindex --canonicalize-existing
9025 Activate canonicalize mode.
9026 If any component is missing or unavailable, @command{readlink} produces
9027 no output and exits with a nonzero exit code.
9029 @item -m
9030 @itemx --canonicalize-missing
9031 @opindex -m
9032 @opindex --canonicalize-missing
9033 Activate canonicalize mode.
9034 If any component is missing or unavailable, @command{readlink} treats it
9035 as a directory.
9037 @item -n
9038 @itemx --no-newline
9039 @opindex -n
9040 @opindex --no-newline
9041 Do not output the trailing newline.
9043 @item -s
9044 @itemx -q
9045 @itemx --silent
9046 @itemx --quiet
9047 @opindex -s
9048 @opindex -q
9049 @opindex --silent
9050 @opindex --quiet
9051 Suppress most error messages.
9053 @item -v
9054 @itemx --verbose
9055 @opindex -v
9056 @opindex --verbose
9057 Report error messages.
9059 @end table
9061 The @command{readlink} utility first appeared in OpenBSD 2.1.
9063 @exitstatus
9066 @node rmdir invocation
9067 @section @command{rmdir}: Remove empty directories
9069 @pindex rmdir
9070 @cindex removing empty directories
9071 @cindex directories, removing empty
9073 @command{rmdir} removes empty directories.  Synopsis:
9075 @example
9076 rmdir [@var{option}]@dots{} @var{directory}@dots{}
9077 @end example
9079 If any @var{directory} argument does not refer to an existing empty
9080 directory, it is an error.
9082 The program accepts the following options.  Also see @ref{Common options}.
9084 @table @samp
9086 @item --ignore-fail-on-non-empty
9087 @opindex --ignore-fail-on-non-empty
9088 @cindex directory deletion, ignoring failures
9089 Ignore each failure to remove a directory that is solely because
9090 the directory is non-empty.
9092 @item -p
9093 @itemx --parents
9094 @opindex -p
9095 @opindex --parents
9096 @cindex parent directories, removing
9097 Remove @var{directory}, then try to remove each component of @var{directory}.
9098 So, for example, @samp{rmdir -p a/b/c} is similar to @samp{rmdir a/b/c a/b a}.
9099 As such, it fails if any of those directories turns out not to be empty.
9100 Use the @option{--ignore-fail-on-non-empty} option to make it so such
9101 a failure does not evoke a diagnostic and does not cause @command{rmdir} to
9102 exit unsuccessfully.
9104 @item -v
9105 @itemx --verbose
9106 @opindex -v
9107 @opindex --verbose
9108 @cindex directory deletion, reporting
9109 Give a diagnostic for each successful removal.
9110 @var{directory} is removed.
9112 @end table
9114 @xref{rm invocation}, for how to remove non-empty directories (recursively).
9116 @exitstatus
9119 @node unlink invocation
9120 @section @command{unlink}: Remove files via the unlink syscall
9122 @pindex unlink
9123 @cindex removing files or directories (via the unlink syscall)
9125 @command{unlink} deletes a single specified file name.
9126 It is a minimalist interface to the system-provided
9127 @code{unlink} function.  @xref{Deleting Files, , , libc,
9128 The GNU C Library Reference Manual}.  Synopsis:
9129 It avoids the bells and whistles of the more commonly-used
9130 @command{rm} command (@pxref{rm invocation}).
9132 @example
9133 unlink @var{filename}
9134 @end example
9136 On some systems @code{unlink} can be used to delete the name of a
9137 directory.  On others, it can be used that way only by a privileged user.
9138 In the GNU system @code{unlink} can never delete the name of a directory.
9140 The @command{unlink} command honors the @option{--help} and
9141 @option{--version} options.  To remove a file whose name begins with
9142 @samp{-}, prefix the name with @samp{./}, e.g., @samp{unlink ./--help}.
9144 @exitstatus
9147 @node Changing file attributes
9148 @chapter Changing file attributes
9150 @cindex changing file attributes
9151 @cindex file attributes, changing
9152 @cindex attributes, file
9154 A file is not merely its contents, a name, and a file type
9155 (@pxref{Special file types}).  A file also has an owner (a user ID), a
9156 group (a group ID), permissions (what the owner can do with the file,
9157 what people in the group can do, and what everyone else can do), various
9158 timestamps, and other information.  Collectively, we call these a file's
9159 @dfn{attributes}.
9161 These commands change file attributes.
9163 @menu
9164 * chgrp invocation::            Change file groups.
9165 * chmod invocation::            Change access permissions.
9166 * chown invocation::            Change file owners and groups.
9167 * touch invocation::            Change file timestamps.
9168 @end menu
9171 @node chown invocation
9172 @section @command{chown}: Change file owner and group
9174 @pindex chown
9175 @cindex file ownership, changing
9176 @cindex group ownership, changing
9177 @cindex changing file ownership
9178 @cindex changing group ownership
9180 @command{chown} changes the user and/or group ownership of each given @var{file}
9181 to @var{new-owner} or to the user and group of an existing reference file.
9182 Synopsis:
9184 @example
9185 chown [@var{option}]@dots{} @{@var{new-owner} | --reference=@var{ref_file}@} @var{file}@dots{}
9186 @end example
9188 If used, @var{new-owner} specifies the new owner and/or group as follows
9189 (with no embedded white space):
9191 @example
9192 [@var{owner}] [ : [@var{group}] ]
9193 @end example
9195 Specifically:
9197 @table @var
9198 @item owner
9199 If only an @var{owner} (a user name or numeric user ID) is given, that
9200 user is made the owner of each given file, and the files' group is not
9201 changed.
9203 @item owner@samp{:}group
9204 If the @var{owner} is followed by a colon and a @var{group} (a
9205 group name or numeric group ID), with no spaces between them, the group
9206 ownership of the files is changed as well (to @var{group}).
9208 @item owner@samp{:}
9209 If a colon but no group name follows @var{owner}, that user is
9210 made the owner of the files and the group of the files is changed to
9211 @var{owner}'s login group.
9213 @item @samp{:}group
9214 If the colon and following @var{group} are given, but the owner
9215 is omitted, only the group of the files is changed; in this case,
9216 @command{chown} performs the same function as @command{chgrp}.
9218 @item @samp{:}
9219 If only a colon is given, or if @var{new-owner} is empty, neither the
9220 owner nor the group is changed.
9222 @end table
9224 If @var{owner} or @var{group} is intended to represent a numeric user
9225 or group ID, then you may specify it with a leading @samp{+}.
9226 @xref{Disambiguating names and IDs}.
9228 Some older scripts may still use @samp{.} in place of the @samp{:} separator.
9229 @acronym{POSIX} 1003.1-2001 (@pxref{Standards conformance}) does not
9230 require support for that, but for backward compatibility @acronym{GNU}
9231 @command{chown} supports @samp{.} so long as no ambiguity results.
9232 New scripts should avoid the use of @samp{.} because it is not
9233 portable, and because it has undesirable results if the entire
9234 @var{owner@samp{.}group} happens to identify a user whose name
9235 contains @samp{.}.
9237 The @command{chown} command sometimes clears the set-user-ID or
9238 set-group-ID permission bits.  This behavior depends on the policy and
9239 functionality of the underlying @code{chown} system call, which may
9240 make system-dependent file mode modifications outside the control of
9241 the @command{chown} command.  For example, the @command{chown} command
9242 might not affect those bits when invoked by a user with appropriate
9243 privileges, or when the
9244 bits signify some function other than executable permission (e.g.,
9245 mandatory locking).
9246 When in doubt, check the underlying system behavior.
9248 The program accepts the following options.  Also see @ref{Common options}.
9250 @table @samp
9252 @item -c
9253 @itemx --changes
9254 @opindex -c
9255 @opindex --changes
9256 @cindex changed owners, verbosely describing
9257 Verbosely describe the action for each @var{file} whose ownership
9258 actually changes.
9260 @item -f
9261 @itemx --silent
9262 @itemx --quiet
9263 @opindex -f
9264 @opindex --silent
9265 @opindex --quiet
9266 @cindex error messages, omitting
9267 Do not print error messages about files whose ownership cannot be
9268 changed.
9270 @itemx @w{@kbd{--from}=@var{old-owner}}
9271 @opindex --from
9272 @cindex symbolic links, changing owner
9273 Change a @var{file}'s ownership only if it has current attributes specified
9274 by @var{old-owner}.  @var{old-owner} has the same form as @var{new-owner}
9275 described above.
9276 This option is useful primarily from a security standpoint in that
9277 it narrows considerably the window of potential abuse.
9278 For example, to reflect a user ID numbering change for one user's files
9279 without an option like this, @code{root} might run
9281 @smallexample
9282 find / -owner OLDUSER -print0 | xargs -0 chown -h NEWUSER
9283 @end smallexample
9285 But that is dangerous because the interval between when the @command{find}
9286 tests the existing file's owner and when the @command{chown} is actually run
9287 may be quite large.
9288 One way to narrow the gap would be to invoke chown for each file
9289 as it is found:
9291 @example
9292 find / -owner OLDUSER -exec chown -h NEWUSER @{@} \;
9293 @end example
9295 But that is very slow if there are many affected files.
9296 With this option, it is safer (the gap is narrower still)
9297 though still not perfect:
9299 @example
9300 chown -h -R --from=OLDUSER NEWUSER /
9301 @end example
9303 @item --dereference
9304 @opindex --dereference
9305 @cindex symbolic links, changing owner
9306 @findex lchown
9307 Do not act on symbolic links themselves but rather on what they point to.
9308 This is the default.
9310 @item -h
9311 @itemx --no-dereference
9312 @opindex -h
9313 @opindex --no-dereference
9314 @cindex symbolic links, changing owner
9315 @findex lchown
9316 Act on symbolic links themselves instead of what they point to.
9317 This mode relies on the @code{lchown} system call.
9318 On systems that do not provide the @code{lchown} system call,
9319 @command{chown} fails when a file specified on the command line
9320 is a symbolic link.
9321 By default, no diagnostic is issued for symbolic links encountered
9322 during a recursive traversal, but see @option{--verbose}.
9324 @itemx --preserve-root
9325 @opindex --preserve-root
9326 @cindex root directory, disallow recursive modification
9327 Fail upon any attempt to recursively change the root directory, @file{/}.
9328 Without @option{--recursive}, this option has no effect.
9329 @xref{Treating / specially}.
9331 @itemx --no-preserve-root
9332 @opindex --no-preserve-root
9333 @cindex root directory, allow recursive modification
9334 Cancel the effect of any preceding @option{--preserve-root} option.
9335 @xref{Treating / specially}.
9337 @item --reference=@var{ref_file}
9338 @opindex --reference
9339 Change the user and group of each @var{file} to be the same as those of
9340 @var{ref_file}.  If @var{ref_file} is a symbolic link, do not use the
9341 user and group of the symbolic link, but rather those of the file it
9342 refers to.
9344 @item -v
9345 @itemx --verbose
9346 @opindex -v
9347 @opindex --verbose
9348 Output a diagnostic for every file processed.
9349 If a symbolic link is encountered during a recursive traversal
9350 on a system without the @code{lchown} system call, and @option{--no-dereference}
9351 is in effect, then issue a diagnostic saying neither the symbolic link nor
9352 its referent is being changed.
9354 @item -R
9355 @itemx --recursive
9356 @opindex -R
9357 @opindex --recursive
9358 @cindex recursively changing file ownership
9359 Recursively change ownership of directories and their contents.
9361 @choptH
9362 @xref{Traversing symlinks}.
9364 @choptL
9365 @xref{Traversing symlinks}.
9367 @choptP
9368 @xref{Traversing symlinks}.
9370 @end table
9372 @exitstatus
9374 Examples:
9376 @smallexample
9377 # Change the owner of /u to "root".
9378 chown root /u
9380 # Likewise, but also change its group to "staff".
9381 chown root:staff /u
9383 # Change the owner of /u and subfiles to "root".
9384 chown -hR root /u
9385 @end smallexample
9388 @node chgrp invocation
9389 @section @command{chgrp}: Change group ownership
9391 @pindex chgrp
9392 @cindex group ownership, changing
9393 @cindex changing group ownership
9395 @command{chgrp} changes the group ownership of each given @var{file}
9396 to @var{group} (which can be either a group name or a numeric group ID)
9397 or to the group of an existing reference file.  Synopsis:
9399 @example
9400 chgrp [@var{option}]@dots{} @{@var{group} | --reference=@var{ref_file}@} @var{file}@dots{}
9401 @end example
9403 If @var{group} is intended to represent a
9404 numeric group ID, then you may specify it with a leading @samp{+}.
9405 @xref{Disambiguating names and IDs}.
9407 The program accepts the following options.  Also see @ref{Common options}.
9409 @table @samp
9411 @item -c
9412 @itemx --changes
9413 @opindex -c
9414 @opindex --changes
9415 @cindex changed files, verbosely describing
9416 Verbosely describe the action for each @var{file} whose group actually
9417 changes.
9419 @item -f
9420 @itemx --silent
9421 @itemx --quiet
9422 @opindex -f
9423 @opindex --silent
9424 @opindex --quiet
9425 @cindex error messages, omitting
9426 Do not print error messages about files whose group cannot be
9427 changed.
9429 @item --dereference
9430 @opindex --dereference
9431 @cindex symbolic links, changing owner
9432 @findex lchown
9433 Do not act on symbolic links themselves but rather on what they point to.
9434 This is the default.
9436 @item -h
9437 @itemx --no-dereference
9438 @opindex -h
9439 @opindex --no-dereference
9440 @cindex symbolic links, changing group
9441 @findex lchown
9442 Act on symbolic links themselves instead of what they point to.
9443 This mode relies on the @code{lchown} system call.
9444 On systems that do not provide the @code{lchown} system call,
9445 @command{chgrp} fails when a file specified on the command line
9446 is a symbolic link.
9447 By default, no diagnostic is issued for symbolic links encountered
9448 during a recursive traversal, but see @option{--verbose}.
9450 @itemx --preserve-root
9451 @opindex --preserve-root
9452 @cindex root directory, disallow recursive modification
9453 Fail upon any attempt to recursively change the root directory, @file{/}.
9454 Without @option{--recursive}, this option has no effect.
9455 @xref{Treating / specially}.
9457 @itemx --no-preserve-root
9458 @opindex --no-preserve-root
9459 @cindex root directory, allow recursive modification
9460 Cancel the effect of any preceding @option{--preserve-root} option.
9461 @xref{Treating / specially}.
9463 @item --reference=@var{ref_file}
9464 @opindex --reference
9465 Change the group of each @var{file} to be the same as that of
9466 @var{ref_file}.  If @var{ref_file} is a symbolic link, do not use the
9467 group of the symbolic link, but rather that of the file it refers to.
9469 @item -v
9470 @itemx --verbose
9471 @opindex -v
9472 @opindex --verbose
9473 Output a diagnostic for every file processed.
9474 If a symbolic link is encountered during a recursive traversal
9475 on a system without the @code{lchown} system call, and @option{--no-dereference}
9476 is in effect, then issue a diagnostic saying neither the symbolic link nor
9477 its referent is being changed.
9479 @item -R
9480 @itemx --recursive
9481 @opindex -R
9482 @opindex --recursive
9483 @cindex recursively changing group ownership
9484 Recursively change the group ownership of directories and their contents.
9486 @choptH
9487 @xref{Traversing symlinks}.
9489 @choptL
9490 @xref{Traversing symlinks}.
9492 @choptP
9493 @xref{Traversing symlinks}.
9495 @end table
9497 @exitstatus
9499 Examples:
9501 @smallexample
9502 # Change the group of /u to "staff".
9503 chgrp staff /u
9505 # Change the group of /u and subfiles to "staff".
9506 chgrp -hR staff /u
9507 @end smallexample
9510 @node chmod invocation
9511 @section @command{chmod}: Change access permissions
9513 @pindex chmod
9514 @cindex changing access permissions
9515 @cindex access permissions, changing
9516 @cindex permissions, changing access
9518 @command{chmod} changes the access permissions of the named files.  Synopsis:
9520 @example
9521 chmod [@var{option}]@dots{} @{@var{mode} | --reference=@var{ref_file}@} @var{file}@dots{}
9522 @end example
9524 @cindex symbolic links, permissions of
9525 @command{chmod} never changes the permissions of symbolic links, since
9526 the @command{chmod} system call cannot change their permissions.
9527 This is not a problem since the permissions of symbolic links are
9528 never used.  However, for each symbolic link listed on the command
9529 line, @command{chmod} changes the permissions of the pointed-to file.
9530 In contrast, @command{chmod} ignores symbolic links encountered during
9531 recursive directory traversals.
9533 A successful use of @command{chmod} clears the set-group-ID bit of a
9534 regular file if the file's group ID does not match the user's
9535 effective group ID or one of the user's supplementary group IDs,
9536 unless the user has appropriate privileges.  Additional restrictions
9537 may cause the set-user-ID and set-group-ID bits of @var{mode} or
9538 @var{ref_file} to be ignored.  This behavior depends on the policy and
9539 functionality of the underlying @code{chmod} system call.  When in
9540 doubt, check the underlying system behavior.
9542 If used, @var{mode} specifies the new file mode bits.
9543 For details, see the section on @ref{File permissions}.
9544 If you really want @var{mode} to have a leading @samp{-}, you should
9545 use @option{--} first, e.g., @samp{chmod -- -w file}.  Typically,
9546 though, @samp{chmod a-w file} is preferable, and @command{chmod -w
9547 file} (without the @option{--}) complains if it behaves differently
9548 from what @samp{chmod a-w file} would do.
9550 The program accepts the following options.  Also see @ref{Common options}.
9552 @table @samp
9554 @item -c
9555 @itemx --changes
9556 @opindex -c
9557 @opindex --changes
9558 Verbosely describe the action for each @var{file} whose permissions
9559 actually changes.
9561 @item -f
9562 @itemx --silent
9563 @itemx --quiet
9564 @opindex -f
9565 @opindex --silent
9566 @opindex --quiet
9567 @cindex error messages, omitting
9568 Do not print error messages about files whose permissions cannot be
9569 changed.
9571 @itemx --preserve-root
9572 @opindex --preserve-root
9573 @cindex root directory, disallow recursive modification
9574 Fail upon any attempt to recursively change the root directory, @file{/}.
9575 Without @option{--recursive}, this option has no effect.
9576 @xref{Treating / specially}.
9578 @itemx --no-preserve-root
9579 @opindex --no-preserve-root
9580 @cindex root directory, allow recursive modification
9581 Cancel the effect of any preceding @option{--preserve-root} option.
9582 @xref{Treating / specially}.
9584 @item -v
9585 @itemx --verbose
9586 @opindex -v
9587 @opindex --verbose
9588 Verbosely describe the action or non-action taken for every @var{file}.
9590 @item --reference=@var{ref_file}
9591 @opindex --reference
9592 Change the mode of each @var{file} to be the same as that of @var{ref_file}.
9593 @xref{File permissions}.
9594 If @var{ref_file} is a symbolic link, do not use the mode
9595 of the symbolic link, but rather that of the file it refers to.
9597 @item -R
9598 @itemx --recursive
9599 @opindex -R
9600 @opindex --recursive
9601 @cindex recursively changing access permissions
9602 Recursively change permissions of directories and their contents.
9604 @end table
9606 @exitstatus
9609 @node touch invocation
9610 @section @command{touch}: Change file timestamps
9612 @pindex touch
9613 @cindex changing file timestamps
9614 @cindex file timestamps, changing
9615 @cindex timestamps, changing file
9617 @command{touch} changes the access and/or modification times of the
9618 specified files.  Synopsis:
9620 @example
9621 touch [@var{option}]@dots{} @var{file}@dots{}
9622 @end example
9624 @cindex empty files, creating
9625 Any @var{file} argument that does not exist is created empty.
9627 A @var{file} argument string of @samp{-} is handled specially and
9628 causes @command{touch} to change the times of the file associated with
9629 standard output.
9631 @cindex permissions, for changing file timestamps
9632 If changing both the access and modification times to the current
9633 time, @command{touch} can change the timestamps for files that the user
9634 running it does not own but has write permission for.  Otherwise, the
9635 user must own the files.
9637 Although @command{touch} provides options for changing two of the times---the
9638 times of last access and modification---of a file, there is actually
9639 a third one as well: the inode change time.  This is often referred to
9640 as a file's @code{ctime}.
9641 The inode change time represents the time when the file's meta-information
9642 last changed.  One common example of this is when the permissions of a
9643 file change.  Changing the permissions doesn't access the file, so
9644 the atime doesn't change, nor does it modify the file, so the mtime
9645 doesn't change.  Yet, something about the file itself has changed,
9646 and this must be noted somewhere.  This is the job of the ctime field.
9647 This is necessary, so that, for example, a backup program can make a
9648 fresh copy of the file, including the new permissions value.
9649 Another operation that modifies a file's ctime without affecting
9650 the others is renaming.  In any case, it is not possible, in normal
9651 operations, for a user to change the ctime field to a user-specified value.
9653 @vindex TZ
9654 Time stamps assume the time zone rules specified by the @env{TZ}
9655 environment variable, or by the system default rules if @env{TZ} is
9656 not set.  @xref{TZ Variable,, Specifying the Time Zone with @env{TZ},
9657 libc, The GNU C Library Reference Manual}.
9658 You can avoid ambiguities during
9659 daylight saving transitions by using @sc{utc} time stamps.
9661 The program accepts the following options.  Also see @ref{Common options}.
9663 @table @samp
9665 @item -a
9666 @itemx --time=atime
9667 @itemx --time=access
9668 @itemx --time=use
9669 @opindex -a
9670 @opindex --time
9671 @opindex atime@r{, changing}
9672 @opindex access @r{time, changing}
9673 @opindex use @r{time, changing}
9674 Change the access time only.
9676 @item -c
9677 @itemx --no-create
9678 @opindex -c
9679 @opindex --no-create
9680 Do not create files that do not exist.
9682 @item -d
9683 @itemx --date=@var{time}
9684 @opindex -d
9685 @opindex --date
9686 @opindex time
9687 Use @var{time} instead of the current time.  It can contain month names,
9688 time zones, @samp{am} and @samp{pm}, @samp{yesterday}, etc.  For
9689 example, @option{--date="2004-02-27 14:19:13.489392193 +0530"}
9690 specifies the instant of time that is 489,392,193 nanoseconds after
9691 February 27, 2004 at 2:19:13 PM in a time zone that is 5 hours and 30
9692 minutes east of @acronym{UTC}.  @xref{Date input formats}.
9693 File systems that do not support high-resolution time stamps
9694 silently ignore any excess precision here.
9696 @item -f
9697 @opindex -f
9698 @cindex BSD @command{touch} compatibility
9699 Ignored; for compatibility with BSD versions of @command{touch}.
9701 @item -m
9702 @itemx --time=mtime
9703 @itemx --time=modify
9704 @opindex -m
9705 @opindex --time
9706 @opindex mtime@r{, changing}
9707 @opindex modify @r{time, changing}
9708 Change the modification time only.
9710 @item -r @var{file}
9711 @itemx --reference=@var{file}
9712 @opindex -r
9713 @opindex --reference
9714 Use the times of the reference @var{file} instead of the current time.
9715 If this option is combined with the @option{--date=@var{time}}
9716 (@option{-d @var{time}}) option, the reference @var{file}'s time is
9717 the origin for any relative @var{time}s given, but is otherwise ignored.
9718 For example, @samp{-r foo -d '-5 seconds'} specifies a time stamp
9719 equal to five seconds before the corresponding time stamp for @file{foo}.
9721 @item -t [[@var{cc}]@var{yy}]@var{mmddhhmm}[.@var{ss}]
9722 Use the argument (optional four-digit or two-digit years, months,
9723 days, hours, minutes, optional seconds) instead of the current time.
9724 If the year is specified with only two digits, then @var{cc}
9725 is 20 for years in the range 0 @dots{} 68, and 19 for years in
9726 69 @dots{} 99.  If no digits of the year are specified,
9727 the argument is interpreted as a date in the current year.
9729 @end table
9731 @vindex _POSIX2_VERSION
9732 On older systems, @command{touch} supports an obsolete syntax, as follows.
9733 If no timestamp is given with any of the @option{-d}, @option{-r}, or
9734 @option{-t} options, and if there are two or more @var{file}s and the
9735 first @var{file} is of the form @samp{@var{mmddhhmm}[@var{yy}]} and this
9736 would be a valid argument to the @option{-t} option (if the @var{yy}, if
9737 any, were moved to the front), and if the represented year
9738 is in the range 1969--1999, that argument is interpreted as the time
9739 for the other files instead of as a file name.
9740 This obsolete behavior can be enabled or disabled with the
9741 @env{_POSIX2_VERSION} environment variable (@pxref{Standards
9742 conformance}), but portable scripts should avoid commands whose
9743 behavior depends on this variable.
9744 For example, use @samp{touch ./12312359 main.c} or @samp{touch -t
9745 12312359 main.c} rather than the ambiguous @samp{touch 12312359 main.c}.
9747 @exitstatus
9750 @node Disk usage
9751 @chapter Disk usage
9753 @cindex disk usage
9755 No disk can hold an infinite amount of data.  These commands report
9756 how much disk storage is in use or available, report other file and
9757 file status information, and write buffers to disk.
9759 @menu
9760 * df invocation::               Report file system disk space usage.
9761 * du invocation::               Estimate file space usage.
9762 * stat invocation::             Report file or file system status.
9763 * sync invocation::             Synchronize memory and disk.
9764 * truncate invocation::         Shrink or extend the size of a file.
9765 @end menu
9768 @node df invocation
9769 @section @command{df}: Report file system disk space usage
9771 @pindex df
9772 @cindex file system disk usage
9773 @cindex disk usage by file system
9775 @command{df} reports the amount of disk space used and available on
9776 file systems.  Synopsis:
9778 @example
9779 df [@var{option}]@dots{} [@var{file}]@dots{}
9780 @end example
9782 With no arguments, @command{df} reports the space used and available on all
9783 currently mounted file systems (of all types).  Otherwise, @command{df}
9784 reports on the file system containing each argument @var{file}.
9786 Normally the disk space is printed in units of
9787 1024 bytes, but this can be overridden (@pxref{Block size}).
9788 Non-integer quantities are rounded up to the next higher unit.
9790 @cindex disk device file
9791 @cindex device file, disk
9792 If an argument @var{file} is a disk device file containing a mounted
9793 file system, @command{df} shows the space available on that file system
9794 rather than on the file system containing the device node (i.e., the root
9795 file system).  @sc{gnu} @command{df} does not attempt to determine the disk usage
9796 on unmounted file systems, because on most kinds of systems doing so
9797 requires extremely nonportable intimate knowledge of file system
9798 structures.
9800 The program accepts the following options.  Also see @ref{Common options}.
9802 @table @samp
9804 @item -a
9805 @itemx --all
9806 @opindex -a
9807 @opindex --all
9808 @cindex automounter file systems
9809 @cindex ignore file systems
9810 Include in the listing dummy file systems, which
9811 are omitted by default.  Such file systems are typically special-purpose
9812 pseudo-file-systems, such as automounter entries.
9814 @item -B @var{size}
9815 @itemx --block-size=@var{size}
9816 @opindex -B
9817 @opindex --block-size
9818 @cindex file system sizes
9819 Scale sizes by @var{size} before printing them (@pxref{Block size}).
9820 For example, @option{-BG} prints sizes in units of 1,073,741,824 bytes.
9822 @itemx --total
9823 @opindex --total
9824 @cindex grand total of disk size, usage and available space
9825 Print a grand total of all arguments after all arguments have
9826 been processed.  This can be used to find out the total disk size, usage
9827 and available space of all listed devices.
9829 @optHumanReadable
9831 @item -H
9832 @opindex -H
9833 Equivalent to @option{--si}.
9835 @item -i
9836 @itemx --inodes
9837 @opindex -i
9838 @opindex --inodes
9839 @cindex inode usage
9840 List inode usage information instead of block usage.  An inode (short
9841 for index node) contains information about a file such as its owner,
9842 permissions, timestamps, and location on the disk.
9844 @item -k
9845 @opindex -k
9846 @cindex kibibytes for file system sizes
9847 Print sizes in 1024-byte blocks, overriding the default block size
9848 (@pxref{Block size}).
9849 This option is equivalent to @option{--block-size=1K}.
9851 @item -l
9852 @itemx --local
9853 @opindex -l
9854 @opindex --local
9855 @cindex file system types, limiting output to certain
9856 Limit the listing to local file systems.  By default, remote file systems
9857 are also listed.
9859 @item --no-sync
9860 @opindex --no-sync
9861 @cindex file system space, retrieving old data more quickly
9862 Do not invoke the @code{sync} system call before getting any usage data.
9863 This may make @command{df} run significantly faster on systems with many
9864 disks, but on some systems (notably SunOS) the results may be slightly
9865 out of date.  This is the default.
9867 @item -P
9868 @itemx --portability
9869 @opindex -P
9870 @opindex --portability
9871 @cindex one-line output format
9872 @cindex @acronym{POSIX} output format
9873 @cindex portable output format
9874 @cindex output format, portable
9875 Use the @acronym{POSIX} output format.  This is like the default format except
9876 for the following:
9878 @enumerate
9879 @item
9880 The information about each file system is always printed on exactly
9881 one line; a mount device is never put on a line by itself.  This means
9882 that if the mount device name is more than 20 characters long (e.g., for
9883 some network mounts), the columns are misaligned.
9885 @item
9886 The labels in the header output line are changed to conform to @acronym{POSIX}.
9888 @item
9889 The default block size and output format are unaffected by the
9890 @env{DF_BLOCK_SIZE}, @env{BLOCK_SIZE} and @env{BLOCKSIZE} environment
9891 variables.  However, the default block size is still affected by
9892 @env{POSIXLY_CORRECT}: it is 512 if @env{POSIXLY_CORRECT} is set, 1024
9893 otherwise.  @xref{Block size}.
9894 @end enumerate
9896 @optSi
9898 @item --sync
9899 @opindex --sync
9900 @cindex file system space, retrieving current data more slowly
9901 Invoke the @code{sync} system call before getting any usage data.  On
9902 some systems (notably SunOS), doing this yields more up to date results,
9903 but in general this option makes @command{df} much slower, especially when
9904 there are many or very busy file systems.
9906 @item -t @var{fstype}
9907 @itemx --type=@var{fstype}
9908 @opindex -t
9909 @opindex --type
9910 @cindex file system types, limiting output to certain
9911 Limit the listing to file systems of type @var{fstype}.  Multiple
9912 file system types can be specified by giving multiple @option{-t} options.
9913 By default, nothing is omitted.
9915 @item -T
9916 @itemx --print-type
9917 @opindex -T
9918 @opindex --print-type
9919 @cindex file system types, printing
9920 Print each file system's type.  The types printed here are the same ones
9921 you can include or exclude with @option{-t} and @option{-x}.  The particular
9922 types printed are whatever is supported by the system.  Here are some of
9923 the common names (this list is certainly not exhaustive):
9925 @table @samp
9927 @item nfs
9928 @cindex @acronym{NFS} file system type
9929 An @acronym{NFS} file system, i.e., one mounted over a network from another
9930 machine.  This is the one type name which seems to be used uniformly by
9931 all systems.
9933 @item 4.2@r{, }ufs@r{, }efs@dots{}
9934 @cindex Linux file system types
9935 @cindex local file system types
9936 @opindex 4.2 @r{file system type}
9937 @opindex ufs @r{file system type}
9938 @opindex efs @r{file system type}
9939 A file system on a locally-mounted hard disk.  (The system might even
9940 support more than one type here; Linux does.)
9942 @item hsfs@r{, }cdfs
9943 @cindex CD-ROM file system type
9944 @cindex High Sierra file system
9945 @opindex hsfs @r{file system type}
9946 @opindex cdfs @r{file system type}
9947 A file system on a CD-ROM drive.  HP-UX uses @samp{cdfs}, most other
9948 systems use @samp{hsfs} (@samp{hs} for ``High Sierra'').
9950 @item pcfs
9951 @cindex PC file system
9952 @cindex DOS file system
9953 @cindex MS-DOS file system
9954 @cindex diskette file system
9955 @opindex pcfs
9956 An MS-DOS file system, usually on a diskette.
9958 @end table
9960 @item -x @var{fstype}
9961 @itemx --exclude-type=@var{fstype}
9962 @opindex -x
9963 @opindex --exclude-type
9964 Limit the listing to file systems not of type @var{fstype}.
9965 Multiple file system types can be eliminated by giving multiple
9966 @option{-x} options.  By default, no file system types are omitted.
9968 @item -v
9969 Ignored; for compatibility with System V versions of @command{df}.
9971 @end table
9973 @exitstatus
9974 Failure includes the case where no output is generated, so you can
9975 inspect the exit status of a command like @samp{df -t ext3 -t reiserfs
9976 @var{dir}} to test whether @var{dir} is on a file system of type
9977 @samp{ext3} or @samp{reiserfs}.
9980 @node du invocation
9981 @section @command{du}: Estimate file space usage
9983 @pindex du
9984 @cindex file space usage
9985 @cindex disk usage for files
9987 @command{du} reports the amount of disk space used by the specified files
9988 and for each subdirectory (of directory arguments).  Synopsis:
9990 @example
9991 du [@var{option}]@dots{} [@var{file}]@dots{}
9992 @end example
9994 With no arguments, @command{du} reports the disk space for the current
9995 directory.  Normally the disk space is printed in units of
9996 1024 bytes, but this can be overridden (@pxref{Block size}).
9997 Non-integer quantities are rounded up to the next higher unit.
9999 If two or more hard links point to the same file, only one of the hard
10000 links is counted.  The @var{file} argument order affects which links
10001 are counted, and changing the argument order may change the numbers
10002 that @command{du} outputs.
10004 The program accepts the following options.  Also see @ref{Common options}.
10006 @table @samp
10008 @item -a
10009 @itemx --all
10010 @opindex -a
10011 @opindex --all
10012 Show counts for all files, not just directories.
10014 @itemx --apparent-size
10015 @opindex --apparent-size
10016 Print apparent sizes, rather than disk usage.  The apparent size of a
10017 file is the number of bytes reported by @code{wc -c} on regular files,
10018 or more generally, @code{ls -l --block-size=1} or @code{stat --format=%s}.
10019 For example, a file containing the word @samp{zoo} with no newline would,
10020 of course, have an apparent size of 3.  Such a small file may require
10021 anywhere from 0 to 16 KiB or more of disk space, depending on
10022 the type and configuration of the file system on which the file resides.
10023 However, a sparse file created with this command:
10025 @example
10026 dd bs=1 seek=2GiB if=/dev/null of=big
10027 @end example
10029 @noindent
10030 has an apparent size of 2 GiB, yet on most modern
10031 systems, it actually uses almost no disk space.
10033 @item -b
10034 @itemx --bytes
10035 @opindex -b
10036 @opindex --bytes
10037 Equivalent to @code{--apparent-size --block-size=1}.
10039 @item -B @var{size}
10040 @itemx --block-size=@var{size}
10041 @opindex -B
10042 @opindex --block-size
10043 @cindex file sizes
10044 Scale sizes by @var{size} before printing them (@pxref{Block size}).
10045 For example, @option{-BG} prints sizes in units of 1,073,741,824 bytes.
10047 @item -c
10048 @itemx --total
10049 @opindex -c
10050 @opindex --total
10051 @cindex grand total of disk space
10052 Print a grand total of all arguments after all arguments have
10053 been processed.  This can be used to find out the total disk usage of
10054 a given set of files or directories.
10056 @item -D
10057 @itemx --dereference-args
10058 @opindex -D
10059 @opindex --dereference-args
10060 Dereference symbolic links that are command line arguments.
10061 Does not affect other symbolic links.  This is helpful for finding
10062 out the disk usage of directories, such as @file{/usr/tmp}, which
10063 are often symbolic links.
10065 @c --files0-from=FILE
10066 @filesZeroFromOption{du,, with the @option{--total} (@option{-c}) option}
10068 @optHumanReadable
10070 @item -H
10071 @opindex -H
10072 Equivalent to @option{--dereference-args} (@option{-D}).
10074 @item -k
10075 @opindex -k
10076 @cindex kibibytes for file sizes
10077 Print sizes in 1024-byte blocks, overriding the default block size
10078 (@pxref{Block size}).
10079 This option is equivalent to @option{--block-size=1K}.
10081 @item -l
10082 @itemx --count-links
10083 @opindex -l
10084 @opindex --count-links
10085 @cindex hard links, counting in @command{du}
10086 Count the size of all files, even if they have appeared already (as a
10087 hard link).
10089 @item -L
10090 @itemx --dereference
10091 @opindex -L
10092 @opindex --dereference
10093 @cindex symbolic links, dereferencing in @command{du}
10094 Dereference symbolic links (show the disk space used by the file
10095 or directory that the link points to instead of the space used by
10096 the link).
10098 @item -m
10099 @opindex -m
10100 @cindex mebibytes for file sizes
10101 Print sizes in 1,048,576-byte blocks, overriding the default block size
10102 (@pxref{Block size}).
10103 This option is equivalent to @option{--block-size=1M}.
10105 @item -P
10106 @itemx --no-dereference
10107 @opindex -P
10108 @opindex --no-dereference
10109 @cindex symbolic links, dereferencing in @command{du}
10110 For each symbolic links encountered by @command{du},
10111 consider the disk space used by the symbolic link.
10113 @item --max-depth=@var{depth}
10114 @opindex --max-depth=@var{depth}
10115 @cindex limiting output of @command{du}
10116 Show the total for each directory (and file if --all) that is at
10117 most MAX_DEPTH levels down from the root of the hierarchy.  The root
10118 is at level 0, so @code{du --max-depth=0} is equivalent to @code{du -s}.
10120 @item -0
10121 @opindex -0
10122 @itemx --null
10123 @opindex --null
10124 @cindex output null-byte-terminated lines
10125 Output a zero byte (@acronym{ASCII} @sc{nul}) at the end of each line,
10126 rather than a newline. This option enables other programs to parse the
10127 output of @command{du} even when that output would contain file names
10128 with embedded newlines.
10130 @optSi
10132 @item -s
10133 @itemx --summarize
10134 @opindex -s
10135 @opindex --summarize
10136 Display only a total for each argument.
10138 @item -S
10139 @itemx --separate-dirs
10140 @opindex -S
10141 @opindex --separate-dirs
10142 Normally, in the output of @command{du} (when not using @option{--summarize}),
10143 the size listed next to a directory name, @var{d}, represents the sum
10144 of sizes of all entries beneath @var{d} as well as the size of @var{d} itself.
10145 With @option{--separate-dirs}, the size reported for a directory name,
10146 @var{d}, is merely the @code{stat.st_size}-derived size of the directory
10147 entry, @var{d}.
10149 @itemx --time
10150 @opindex --time
10151 @cindex last modified dates, displaying in @command{du}
10152 Show time of the most recent modification of any file in the directory,
10153 or any of its subdirectories.
10155 @itemx --time=ctime
10156 @itemx --time=status
10157 @itemx --time=use
10158 @opindex --time
10159 @opindex ctime@r{, show the most recent}
10160 @opindex status time@r{, show the most recent}
10161 @opindex use time@r{, show the most recent}
10162 Show the most recent status change time (the @samp{ctime} in the inode) of
10163 any file in the directory, instead of the modification time.
10165 @itemx --time=atime
10166 @itemx --time=access
10167 @opindex --time
10168 @opindex atime@r{, show the most recent}
10169 @opindex access time@r{, show the most recent}
10170 Show the most recent access time (the @samp{atime} in the inode) of
10171 any file in the directory, instead of the modification time.
10173 @item --time-style=@var{style}
10174 @opindex --time-style
10175 @cindex time style
10176 List timestamps in style @var{style}.  This option has an effect only if
10177 the @option{--time} option is also specified.  The @var{style} should
10178 be one of the following:
10180 @table @samp
10181 @item +@var{format}
10182 @vindex LC_TIME
10183 List timestamps using @var{format}, where @var{format} is interpreted
10184 like the format argument of @command{date} (@pxref{date invocation}).
10185 For example, @option{--time-style="+%Y-%m-%d %H:%M:%S"} causes
10186 @command{du} to list timestamps like @samp{2002-03-30 23:45:56}.  As
10187 with @command{date}, @var{format}'s interpretation is affected by the
10188 @env{LC_TIME} locale category.
10190 @item full-iso
10191 List timestamps in full using @acronym{ISO} 8601 date, time, and time zone
10192 format with nanosecond precision, e.g., @samp{2002-03-30
10193 23:45:56.477817180 -0700}.  This style is equivalent to
10194 @samp{+%Y-%m-%d %H:%M:%S.%N %z}.
10196 @item long-iso
10197 List @acronym{ISO} 8601 date and time in minutes, e.g.,
10198 @samp{2002-03-30 23:45}.  These timestamps are shorter than
10199 @samp{full-iso} timestamps, and are usually good enough for everyday
10200 work.  This style is equivalent to @samp{+%Y-%m-%d %H:%M}.
10202 @item iso
10203 List @acronym{ISO} 8601 dates for timestamps, e.g., @samp{2002-03-30}.
10204 This style is equivalent to @samp{+%Y-%m-%d}.
10205 @end table
10207 @vindex TIME_STYLE
10208 You can specify the default value of the @option{--time-style} option
10209 with the environment variable @env{TIME_STYLE}; if @env{TIME_STYLE} is not set
10210 the default style is @samp{long-iso}.  For compatibility with @command{ls},
10211 if @env{TIME_STYLE} begins with @samp{+} and contains a newline,
10212 the newline and any later characters are ignored; if @env{TIME_STYLE}
10213 begins with @samp{posix-} the @samp{posix-} is ignored; and if
10214 @env{TIME_STYLE} is @samp{locale} it is ignored.
10216 @item -x
10217 @itemx --one-file-system
10218 @opindex -x
10219 @opindex --one-file-system
10220 @cindex one file system, restricting @command{du} to
10221 Skip directories that are on different file systems from the one that
10222 the argument being processed is on.
10224 @item --exclude=@var{pattern}
10225 @opindex --exclude=@var{pattern}
10226 @cindex excluding files from @command{du}
10227 When recursing, skip subdirectories or files matching @var{pattern}.
10228 For example, @code{du --exclude='*.o'} excludes files whose names
10229 end in @samp{.o}.
10231 @item -X @var{file}
10232 @itemx --exclude-from=@var{file}
10233 @opindex -X @var{file}
10234 @opindex --exclude-from=@var{file}
10235 @cindex excluding files from @command{du}
10236 Like @option{--exclude}, except take the patterns to exclude from @var{file},
10237 one per line.  If @var{file} is @samp{-}, take the patterns from standard
10238 input.
10240 @end table
10242 @cindex NFS mounts from BSD to HP-UX
10243 On BSD systems, @command{du} reports sizes that are half the correct
10244 values for files that are NFS-mounted from HP-UX systems.  On HP-UX
10245 systems, it reports sizes that are twice the correct values for
10246 files that are NFS-mounted from BSD systems.  This is due to a flaw
10247 in HP-UX; it also affects the HP-UX @command{du} program.
10249 @exitstatus
10252 @node stat invocation
10253 @section @command{stat}: Report file or file system status
10255 @pindex stat
10256 @cindex file status
10257 @cindex file system status
10259 @command{stat} displays information about the specified file(s).  Synopsis:
10261 @example
10262 stat [@var{option}]@dots{} [@var{file}]@dots{}
10263 @end example
10265 With no option, @command{stat} reports all information about the given files.
10266 But it also can be used to report the information of the file systems the
10267 given files are located on.  If the files are links, @command{stat} can
10268 also give information about the files the links point to.
10270 @mayConflictWithShellBuiltIn{stat}
10272 @table @samp
10274 @item -L
10275 @itemx --dereference
10276 @opindex -L
10277 @opindex --dereference
10278 @cindex symbolic links, dereferencing in @command{stat}
10279 Change how @command{stat} treats symbolic links.
10280 With this option, @command{stat} acts on the file referenced
10281 by each symbolic link argument.
10282 Without it, @command{stat} acts on any symbolic link argument directly.
10284 @item -f
10285 @itemx --file-system
10286 @opindex -f
10287 @opindex --file-system
10288 @cindex file systems
10289 Report information about the file systems where the given files are located
10290 instead of information about the files themselves.
10292 @item -c
10293 @itemx --format=@var{format}
10294 @opindex -c
10295 @opindex --format=@var{format}
10296 @cindex output format
10297 Use @var{format} rather than the default format.
10298 @var{format} is automatically newline-terminated, so
10299 running a command like the following with two or more @var{file}
10300 operands produces a line of output for each operand:
10301 @example
10302 $ stat --format=%d:%i / /usr
10303 2050:2
10304 2057:2
10305 @end example
10307 @itemx --printf=@var{format}
10308 @opindex --printf=@var{format}
10309 @cindex output format
10310 Use @var{format} rather than the default format.
10311 Like @option{--format}, but interpret backslash escapes,
10312 and do not output a mandatory trailing newline.
10313 If you want a newline, include @samp{\n} in the @var{format}.
10314 Here's how you would use @option{--printf} to print the device
10315 and inode numbers of @file{/} and @file{/usr}:
10316 @example
10317 $ stat --printf='%d:%i\n' / /usr
10318 2050:2
10319 2057:2
10320 @end example
10322 @item -t
10323 @itemx --terse
10324 @opindex -t
10325 @opindex --terse
10326 @cindex terse output
10327 Print the information in terse form, suitable for parsing by other programs.
10329 @end table
10331 The valid @var{format} directives for files with @option{--format} and
10332 @option{--printf} are:
10334 @itemize @bullet
10335 @item %a - Access rights in octal
10336 @item %A - Access rights in human readable form
10337 @item %b - Number of blocks allocated (see @samp{%B})
10338 @item %B - The size in bytes of each block reported by @samp{%b}
10339 @item %d - Device number in decimal
10340 @item %D - Device number in hex
10341 @item %f - Raw mode in hex
10342 @item %F - File type
10343 @item %g - Group ID of owner
10344 @item %G - Group name of owner
10345 @item %h - Number of hard links
10346 @item %i - Inode number
10347 @item %n - File name
10348 @item %N - Quoted file name with dereference if symbolic link
10349 @item %o - I/O block size
10350 @item %s - Total size, in bytes
10351 @item %t - Major device type in hex
10352 @item %T - Minor device type in hex
10353 @item %u - User ID of owner
10354 @item %U - User name of owner
10355 @item %x - Time of last access
10356 @item %X - Time of last access as seconds since Epoch
10357 @item %y - Time of last modification
10358 @item %Y - Time of last modification as seconds since Epoch
10359 @item %z - Time of last change
10360 @item %Z - Time of last change as seconds since Epoch
10361 @end itemize
10363 When listing file system information (@option{--file-system} (@option{-f})),
10364 you must use a different set of @var{format} directives:
10366 @itemize @bullet
10367 @item %a - Free blocks available to non-super-user
10368 @item %b - Total data blocks in file system
10369 @item %c - Total file nodes in file system
10370 @item %d - Free file nodes in file system
10371 @item %f - Free blocks in file system
10372 @item %i - File System ID in hex
10373 @item %l - Maximum length of file names
10374 @item %n - File name
10375 @item %s - Block size (for faster transfers)
10376 @item %S - Fundamental block size (for block counts)
10377 @item %t - Type in hex
10378 @item %T - Type in human readable form
10379 @end itemize
10381 @vindex TZ
10382 Time stamps are listed according to the time zone rules specified by
10383 the @env{TZ} environment variable, or by the system default rules if
10384 @env{TZ} is not set.  @xref{TZ Variable,, Specifying the Time Zone
10385 with @env{TZ}, libc, The GNU C Library Reference Manual}.
10387 @exitstatus
10390 @node sync invocation
10391 @section @command{sync}: Synchronize data on disk with memory
10393 @pindex sync
10394 @cindex synchronize disk and memory
10396 @cindex superblock, writing
10397 @cindex inodes, written buffered
10398 @command{sync} writes any data buffered in memory out to disk.  This can
10399 include (but is not limited to) modified superblocks, modified inodes,
10400 and delayed reads and writes.  This must be implemented by the kernel;
10401 The @command{sync} program does nothing but exercise the @code{sync} system
10402 call.
10404 @cindex crashes and corruption
10405 The kernel keeps data in memory to avoid doing (relatively slow) disk
10406 reads and writes.  This improves performance, but if the computer
10407 crashes, data may be lost or the file system corrupted as a
10408 result.  The @command{sync} command ensures everything in memory
10409 is written to disk.
10411 Any arguments are ignored, except for a lone @option{--help} or
10412 @option{--version} (@pxref{Common options}).
10414 @exitstatus
10417 @node truncate invocation
10418 @section @command{truncate}: Shrink or extend the size of a file
10420 @pindex truncate
10421 @cindex truncating, file sizes
10423 @command{truncate} shrinks or extends the size of each @var{file} to the
10424 specified size. Synopsis:
10426 @example
10427 truncate @var{option}@dots{} @var{file}@dots{}
10428 @end example
10430 @cindex files, creating
10431 Any @var{file} that does not exist is created.
10433 @cindex sparse files, creating
10434 @cindex holes, creating files with
10435 If a @var{file} is larger than the specified size, the extra data is lost.
10436 If a @var{file} is shorter, it is extended and the extended part (or hole)
10437 reads as zero bytes.
10439 The program accepts the following options.  Also see @ref{Common options}.
10441 @table @samp
10443 @item -c
10444 @itemx --no-create
10445 @opindex -c
10446 @opindex --no-create
10447 Do not create files that do not exist.
10449 @item -o
10450 @itemx --io-blocks
10451 @opindex -o
10452 @opindex --io-blocks
10453 Treat @var{size} as number of I/O blocks of the @var{file} rather than bytes.
10455 @item -r @var{rfile}
10456 @itemx --reference=@var{rfile}
10457 @opindex -r
10458 @opindex --reference
10459 Set the size of each @var{file} to the same size as @var{rfile}.
10461 @item -s @var{size}
10462 @itemx --size=@var{size}
10463 @opindex -s
10464 @opindex --size
10465 Set the size of each @var{file} to this @var{size}.
10466 @multiplierSuffixesNoBlocks{size}
10468 @var{size} may also be prefixed by one of the following to adjust
10469 the size of each @var{file} based on their current size:
10470 @example
10471 @samp{+}  => extend by
10472 @samp{-}  => reduce by
10473 @samp{<}  => at most
10474 @samp{>}  => at least
10475 @samp{/}  => round down to multiple of
10476 @samp{%}  => round up to multiple of
10477 @end example
10479 @end table
10481 @exitstatus
10484 @node Printing text
10485 @chapter Printing text
10487 @cindex printing text, commands for
10488 @cindex commands for printing text
10490 This section describes commands that display text strings.
10492 @menu
10493 * echo invocation::             Print a line of text.
10494 * printf invocation::           Format and print data.
10495 * yes invocation::              Print a string until interrupted.
10496 @end menu
10499 @node echo invocation
10500 @section @command{echo}: Print a line of text
10502 @pindex echo
10503 @cindex displaying text
10504 @cindex printing text
10505 @cindex text, displaying
10506 @cindex arbitrary text, displaying
10508 @command{echo} writes each given @var{string} to standard output, with a
10509 space between each and a newline after the last one.  Synopsis:
10511 @example
10512 echo [@var{option}]@dots{} [@var{string}]@dots{}
10513 @end example
10515 @mayConflictWithShellBuiltIn{echo}
10517 The program accepts the following options.  Also see @ref{Common options}.
10518 Options must precede operands, and the normally-special argument
10519 @samp{--} has no special meaning and is treated like any other
10520 @var{string}.
10522 @table @samp
10523 @item -n
10524 @opindex -n
10525 Do not output the trailing newline.
10527 @item -e
10528 @opindex -e
10529 @cindex backslash escapes
10530 Enable interpretation of the following backslash-escaped characters in
10531 each @var{string}:
10533 @table @samp
10534 @item \a
10535 alert (bell)
10536 @item \b
10537 backspace
10538 @item \c
10539 produce no further output
10540 @item \f
10541 form feed
10542 @item \n
10543 newline
10544 @item \r
10545 carriage return
10546 @item \t
10547 horizontal tab
10548 @item \v
10549 vertical tab
10550 @item \\
10551 backslash
10552 @item \0@var{nnn}
10553 the eight-bit value that is the octal number @var{nnn}
10554 (zero to three octal digits)
10555 @item \@var{nnn}
10556 the eight-bit value that is the octal number @var{nnn}
10557 (one to three octal digits)
10558 @item \x@var{hh}
10559 the eight-bit value that is the hexadecimal number @var{hh}
10560 (one or two hexadecimal digits)
10561 @end table
10563 @item -E
10564 @opindex -E
10565 @cindex backslash escapes
10566 Disable interpretation of backslash escapes in each @var{string}.
10567 This is the default.  If @option{-e} and @option{-E} are both
10568 specified, the last one given takes effect.
10570 @end table
10572 @vindex POSIXLY_CORRECT
10573 If the @env{POSIXLY_CORRECT} environment variable is set, then when
10574 @command{echo}'s first argument is not @option{-n} it outputs
10575 option-like arguments instead of treating them as options.  For
10576 example, @code{echo -ne hello} outputs @samp{-ne hello} instead of
10577 plain @samp{hello}.
10579 @acronym{POSIX} does not require support for any options, and says
10580 that the behavior of @command{echo} is implementation-defined if any
10581 @var{string} contains a backslash or if the first argument is
10582 @option{-n}.  Portable programs can use the @command{printf} command
10583 if they need to omit trailing newlines or output control characters or
10584 backslashes.  @xref{printf invocation}.
10586 @exitstatus
10589 @node printf invocation
10590 @section @command{printf}: Format and print data
10592 @pindex printf
10593 @command{printf} does formatted printing of text.  Synopsis:
10595 @example
10596 printf @var{format} [@var{argument}]@dots{}
10597 @end example
10599 @command{printf} prints the @var{format} string, interpreting @samp{%}
10600 directives and @samp{\} escapes to format numeric and string arguments
10601 in a way that is mostly similar to the C @samp{printf} function.
10602 @xref{Output Conversion Syntax,, @command{printf} format directives,
10603 libc, The GNU C Library Reference Manual}, for details.
10604 The differences are listed below.
10606 @mayConflictWithShellBuiltIn{printf}
10608 @itemize @bullet
10610 @item
10611 The @var{format} argument is reused as necessary to convert all the
10612 given @var{argument}s.  For example, the command @samp{printf %s a b}
10613 outputs @samp{ab}.
10615 @item
10616 Missing @var{argument}s are treated as null strings or as zeros,
10617 depending on whether the context expects a string or a number.  For
10618 example, the command @samp{printf %sx%d} prints @samp{x0}.
10620 @item
10621 @kindex \c
10622 An additional escape, @samp{\c}, causes @command{printf} to produce no
10623 further output.  For example, the command @samp{printf 'A%sC\cD%sF' B
10624 E} prints @samp{ABC}.
10626 @item
10627 The hexadecimal escape sequence @samp{\x@var{hh}} has at most two
10628 digits, as opposed to C where it can have an unlimited number of
10629 digits.  For example, the command @samp{printf '\x07e'} prints two
10630 bytes, whereas the C statement @samp{printf ("\x07e")} prints just
10631 one.
10633 @item
10634 @kindex %b
10635 @command{printf} has an additional directive, @samp{%b}, which prints its
10636 argument string with @samp{\} escapes interpreted in the same way as in
10637 the @var{format} string, except that octal escapes are of the form
10638 @samp{\0@var{ooo}} where @var{ooo} is 0 to 3 octal digits.
10639 If a precision is also given, it limits the number of bytes printed
10640 from the converted string.
10642 @item
10643 Numeric arguments must be single C constants, possibly with leading
10644 @samp{+} or @samp{-}.  For example, @samp{printf %.4d -3} outputs
10645 @samp{-0003}.
10647 @item
10648 @vindex POSIXLY_CORRECT
10649 If the leading character of a numeric argument is @samp{"} or @samp{'}
10650 then its value is the numeric value of the immediately following
10651 character.  Any remaining characters are silently ignored if the
10652 @env{POSIXLY_CORRECT} environment variable is set; otherwise, a
10653 warning is printed.  For example, @samp{printf "%d" "'a"} outputs
10654 @samp{97} on hosts that use the @acronym{ASCII} character set, since
10655 @samp{a} has the numeric value 97 in @acronym{ASCII}.
10657 @end itemize
10659 @vindex LC_NUMERIC
10660 A floating-point argument must use a period before any fractional
10661 digits, but is printed according to the @env{LC_NUMERIC} category of the
10662 current locale.  For example, in a locale whose radix character is a
10663 comma, the command @samp{printf %g 3.14} outputs @samp{3,14} whereas
10664 the command @samp{printf %g 3,14} is an error.
10666 @kindex \@var{ooo}
10667 @kindex \x@var{hh}
10668 @command{printf} interprets @samp{\@var{ooo}} in @var{format} as an octal number
10669 (if @var{ooo} is 1 to 3 octal digits) specifying a character to print,
10670 and @samp{\x@var{hh}} as a hexadecimal number (if @var{hh} is 1 to 2 hex
10671 digits) specifying a character to print.
10673 @kindex \uhhhh
10674 @kindex \Uhhhhhhhh
10675 @cindex Unicode
10676 @cindex ISO/IEC 10646
10677 @vindex LC_CTYPE
10678 @command{printf} interprets two character syntaxes introduced in
10679 @acronym{ISO} C 99:
10680 @samp{\u} for 16-bit Unicode (@acronym{ISO}/@acronym{IEC} 10646)
10681 characters, specified as
10682 four hexadecimal digits @var{hhhh}, and @samp{\U} for 32-bit Unicode
10683 characters, specified as eight hexadecimal digits @var{hhhhhhhh}.
10684 @command{printf} outputs the Unicode characters
10685 according to the @env{LC_CTYPE} locale.  Unicode characters in the ranges
10686 U+0000...U+009F, U+D800...U+DFFF cannot be specified by this syntax, except
10687 for U+0024 ($), U+0040 (@@), and U+0060 (@`).
10689 The processing of @samp{\u} and @samp{\U} requires a full-featured
10690 @code{iconv} facility.  It is activated on systems with glibc 2.2 (or newer),
10691 or when @code{libiconv} is installed prior to this package.  Otherwise
10692 @samp{\u} and @samp{\U} will print as-is.
10694 The only options are a lone @option{--help} or
10695 @option{--version}.  @xref{Common options}.
10696 Options must precede operands.
10698 The Unicode character syntaxes are useful for writing strings in a locale
10699 independent way.  For example, a string containing the Euro currency symbol
10701 @example
10702 $ env printf '\u20AC 14.95'
10703 @end example
10705 @noindent
10706 will be output correctly in all locales supporting the Euro symbol
10707 (@acronym{ISO}-8859-15, UTF-8, and others).  Similarly, a Chinese string
10709 @example
10710 $ env printf '\u4e2d\u6587'
10711 @end example
10713 @noindent
10714 will be output correctly in all Chinese locales (GB2312, BIG5, UTF-8, etc).
10716 Note that in these examples, the @command{printf} command has been
10717 invoked via @command{env} to ensure that we run the program found via
10718 your shell's search path, and not a shell alias or a built-in function.
10720 For larger strings, you don't need to look up the hexadecimal code
10721 values of each character one by one.  @acronym{ASCII} characters mixed with \u
10722 escape sequences is also known as the JAVA source file encoding.  You can
10723 use GNU recode 3.5c (or newer) to convert strings to this encoding.  Here
10724 is how to convert a piece of text into a shell script which will output
10725 this text in a locale-independent way:
10727 @smallexample
10728 $ LC_CTYPE=zh_CN.big5 /usr/local/bin/printf \
10729     '\u4e2d\u6587\n' > sample.txt
10730 $ recode BIG5..JAVA < sample.txt \
10731     | sed -e "s|^|/usr/local/bin/printf '|" -e "s|$|\\\\n'|" \
10732     > sample.sh
10733 @end smallexample
10735 @exitstatus
10738 @node yes invocation
10739 @section @command{yes}: Print a string until interrupted
10741 @pindex yes
10742 @cindex repeated output of a string
10744 @command{yes} prints the command line arguments, separated by spaces and
10745 followed by a newline, forever until it is killed.  If no arguments are
10746 given, it prints @samp{y} followed by a newline forever until killed.
10748 Upon a write error, @command{yes} exits with status @samp{1}.
10750 The only options are a lone @option{--help} or @option{--version}.
10751 To output an argument that begins with
10752 @samp{-}, precede it with @option{--}, e.g., @samp{yes -- --help}.
10753 @xref{Common options}.
10756 @node Conditions
10757 @chapter Conditions
10759 @cindex conditions
10760 @cindex commands for exit status
10761 @cindex exit status commands
10763 This section describes commands that are primarily useful for their exit
10764 status, rather than their output.  Thus, they are often used as the
10765 condition of shell @code{if} statements, or as the last command in a
10766 pipeline.
10768 @menu
10769 * false invocation::            Do nothing, unsuccessfully.
10770 * true invocation::             Do nothing, successfully.
10771 * test invocation::             Check file types and compare values.
10772 * expr invocation::             Evaluate expressions.
10773 @end menu
10776 @node false invocation
10777 @section @command{false}: Do nothing, unsuccessfully
10779 @pindex false
10780 @cindex do nothing, unsuccessfully
10781 @cindex failure exit status
10782 @cindex exit status of @command{false}
10784 @command{false} does nothing except return an exit status of 1, meaning
10785 @dfn{failure}.  It can be used as a place holder in shell scripts
10786 where an unsuccessful command is needed.
10787 In most modern shells, @command{false} is a built-in command, so when
10788 you use @samp{false} in a script, you're probably using the built-in
10789 command, not the one documented here.
10791 @command{false} honors the @option{--help} and @option{--version} options.
10793 This version of @command{false} is implemented as a C program, and is thus
10794 more secure and faster than a shell script implementation, and may safely
10795 be used as a dummy shell for the purpose of disabling accounts.
10797 Note that @command{false} (unlike all other programs documented herein)
10798 exits unsuccessfully, even when invoked with
10799 @option{--help} or @option{--version}.
10801 Portable programs should not assume that the exit status of
10802 @command{false} is 1, as it is greater than 1 on some
10803 non-@acronym{GNU} hosts.
10806 @node true invocation
10807 @section @command{true}: Do nothing, successfully
10809 @pindex true
10810 @cindex do nothing, successfully
10811 @cindex no-op
10812 @cindex successful exit
10813 @cindex exit status of @command{true}
10815 @command{true} does nothing except return an exit status of 0, meaning
10816 @dfn{success}.  It can be used as a place holder in shell scripts
10817 where a successful command is needed, although the shell built-in
10818 command @code{:} (colon) may do the same thing faster.
10819 In most modern shells, @command{true} is a built-in command, so when
10820 you use @samp{true} in a script, you're probably using the built-in
10821 command, not the one documented here.
10823 @command{true} honors the @option{--help} and @option{--version} options.
10825 Note, however, that it is possible to cause @command{true}
10826 to exit with nonzero status: with the @option{--help} or @option{--version}
10827 option, and with standard
10828 output already closed or redirected to a file that evokes an I/O error.
10829 For example, using a Bourne-compatible shell:
10831 @example
10832 $ ./true --version >&-
10833 ./true: write error: Bad file number
10834 $ ./true --version > /dev/full
10835 ./true: write error: No space left on device
10836 @end example
10838 This version of @command{true} is implemented as a C program, and is thus
10839 more secure and faster than a shell script implementation, and may safely
10840 be used as a dummy shell for the purpose of disabling accounts.
10842 @node test invocation
10843 @section @command{test}: Check file types and compare values
10845 @pindex test
10846 @cindex check file types
10847 @cindex compare values
10848 @cindex expression evaluation
10850 @command{test} returns a status of 0 (true) or 1 (false) depending on the
10851 evaluation of the conditional expression @var{expr}.  Each part of the
10852 expression must be a separate argument.
10854 @command{test} has file status checks, string operators, and numeric
10855 comparison operators.
10857 @command{test} has an alternate form that uses opening and closing
10858 square brackets instead a leading @samp{test}.  For example, instead
10859 of @samp{test -d /}, you can write @samp{[ -d / ]}.  The square
10860 brackets must be separate arguments; for example, @samp{[-d /]} does
10861 not have the desired effect.  Since @samp{test @var{expr}} and @samp{[
10862 @var{expr} ]} have the same meaning, only the former form is discussed
10863 below.
10865 Synopses:
10867 @example
10868 test @var{expression}
10869 test
10870 [ @var{expression} ]
10871 [ ]
10872 [ @var{option}
10873 @end example
10875 @mayConflictWithShellBuiltIn{test}
10877 If @var{expression} is omitted, @command{test} returns false.
10878 If @var{expression} is a single argument,
10879 @command{test} returns false if the argument is null and true otherwise.  The argument
10880 can be any string, including strings like @samp{-d}, @samp{-1},
10881 @samp{--}, @samp{--help}, and @samp{--version} that most other
10882 programs would treat as options.  To get help and version information,
10883 invoke the commands @samp{[ --help} and @samp{[ --version}, without
10884 the usual closing brackets.  @xref{Common options}.
10886 @cindex exit status of @command{test}
10887 Exit status:
10889 @display
10890 0 if the expression is true,
10891 1 if the expression is false,
10892 2 if an error occurred.
10893 @end display
10895 @menu
10896 * File type tests::             -[bcdfhLpSt]
10897 * Access permission tests::     -[gkruwxOG]
10898 * File characteristic tests::   -e -s -nt -ot -ef
10899 * String tests::                -z -n = !=
10900 * Numeric tests::               -eq -ne -lt -le -gt -ge
10901 * Connectives for test::        ! -a -o
10902 @end menu
10905 @node File type tests
10906 @subsection File type tests
10908 @cindex file type tests
10910 These options test for particular types of files.  (Everything's a file,
10911 but not all files are the same!)
10913 @table @samp
10915 @item -b @var{file}
10916 @opindex -b
10917 @cindex block special check
10918 True if @var{file} exists and is a block special device.
10920 @item -c @var{file}
10921 @opindex -c
10922 @cindex character special check
10923 True if @var{file} exists and is a character special device.
10925 @item -d @var{file}
10926 @opindex -d
10927 @cindex directory check
10928 True if @var{file} exists and is a directory.
10930 @item -f @var{file}
10931 @opindex -f
10932 @cindex regular file check
10933 True if @var{file} exists and is a regular file.
10935 @item -h @var{file}
10936 @itemx -L @var{file}
10937 @opindex -L
10938 @opindex -h
10939 @cindex symbolic link check
10940 True if @var{file} exists and is a symbolic link.
10941 Unlike all other file-related tests, this test does not dereference
10942 @var{file} if it is a symbolic link.
10944 @item -p @var{file}
10945 @opindex -p
10946 @cindex named pipe check
10947 True if @var{file} exists and is a named pipe.
10949 @item -S @var{file}
10950 @opindex -S
10951 @cindex socket check
10952 True if @var{file} exists and is a socket.
10954 @item -t @var{fd}
10955 @opindex -t
10956 @cindex terminal check
10957 True if @var{fd} is a file descriptor that is associated with a
10958 terminal.
10960 @end table
10963 @node Access permission tests
10964 @subsection Access permission tests
10966 @cindex access permission tests
10967 @cindex permission tests
10969 These options test for particular access permissions.
10971 @table @samp
10973 @item -g @var{file}
10974 @opindex -g
10975 @cindex set-group-ID check
10976 True if @var{file} exists and has its set-group-ID bit set.
10978 @item -k @var{file}
10979 @opindex -k
10980 @cindex sticky bit check
10981 True if @var{file} exists and has its @dfn{sticky} bit set.
10983 @item -r @var{file}
10984 @opindex -r
10985 @cindex readable file check
10986 True if @var{file} exists and read permission is granted.
10988 @item -u @var{file}
10989 @opindex -u
10990 @cindex set-user-ID check
10991 True if @var{file} exists and has its set-user-ID bit set.
10993 @item -w @var{file}
10994 @opindex -w
10995 @cindex writable file check
10996 True if @var{file} exists and write permission is granted.
10998 @item -x @var{file}
10999 @opindex -x
11000 @cindex executable file check
11001 True if @var{file} exists and execute permission is granted
11002 (or search permission, if it is a directory).
11004 @item -O @var{file}
11005 @opindex -O
11006 @cindex owned by effective user ID check
11007 True if @var{file} exists and is owned by the current effective user ID.
11009 @item -G @var{file}
11010 @opindex -G
11011 @cindex owned by effective group ID check
11012 True if @var{file} exists and is owned by the current effective group ID.
11014 @end table
11016 @node File characteristic tests
11017 @subsection File characteristic tests
11019 @cindex file characteristic tests
11021 These options test other file characteristics.
11023 @table @samp
11025 @item -e @var{file}
11026 @opindex -e
11027 @cindex existence-of-file check
11028 True if @var{file} exists.
11030 @item -s @var{file}
11031 @opindex -s
11032 @cindex nonempty file check
11033 True if @var{file} exists and has a size greater than zero.
11035 @item @var{file1} -nt @var{file2}
11036 @opindex -nt
11037 @cindex newer-than file check
11038 True if @var{file1} is newer (according to modification date) than
11039 @var{file2}, or if @var{file1} exists and @var{file2} does not.
11041 @item @var{file1} -ot @var{file2}
11042 @opindex -ot
11043 @cindex older-than file check
11044 True if @var{file1} is older (according to modification date) than
11045 @var{file2}, or if @var{file2} exists and @var{file1} does not.
11047 @item @var{file1} -ef @var{file2}
11048 @opindex -ef
11049 @cindex same file check
11050 @cindex hard link check
11051 True if @var{file1} and @var{file2} have the same device and inode
11052 numbers, i.e., if they are hard links to each other.
11054 @end table
11057 @node String tests
11058 @subsection String tests
11060 @cindex string tests
11062 These options test string characteristics.  You may need to quote
11063 @var{string} arguments for the shell.  For example:
11065 @example
11066 test -n "$V"
11067 @end example
11069 The quotes here prevent the wrong arguments from being passed to
11070 @command{test} if @samp{$V} is empty or contains special characters.
11072 @table @samp
11074 @item -z @var{string}
11075 @opindex -z
11076 @cindex zero-length string check
11077 True if the length of @var{string} is zero.
11079 @item -n @var{string}
11080 @itemx @var{string}
11081 @opindex -n
11082 @cindex nonzero-length string check
11083 True if the length of @var{string} is nonzero.
11085 @item @var{string1} = @var{string2}
11086 @opindex =
11087 @cindex equal string check
11088 True if the strings are equal.
11090 @item @var{string1} != @var{string2}
11091 @opindex !=
11092 @cindex not-equal string check
11093 True if the strings are not equal.
11095 @end table
11098 @node Numeric tests
11099 @subsection Numeric tests
11101 @cindex numeric tests
11102 @cindex arithmetic tests
11104 Numeric relational operators.  The arguments must be entirely numeric
11105 (possibly negative), or the special expression @w{@code{-l @var{string}}},
11106 which evaluates to the length of @var{string}.
11108 @table @samp
11110 @item @var{arg1} -eq @var{arg2}
11111 @itemx @var{arg1} -ne @var{arg2}
11112 @itemx @var{arg1} -lt @var{arg2}
11113 @itemx @var{arg1} -le @var{arg2}
11114 @itemx @var{arg1} -gt @var{arg2}
11115 @itemx @var{arg1} -ge @var{arg2}
11116 @opindex -eq
11117 @opindex -ne
11118 @opindex -lt
11119 @opindex -le
11120 @opindex -gt
11121 @opindex -ge
11122 These arithmetic binary operators return true if @var{arg1} is equal,
11123 not-equal, less-than, less-than-or-equal, greater-than, or
11124 greater-than-or-equal than @var{arg2}, respectively.
11126 @end table
11128 For example:
11130 @example
11131 test -1 -gt -2 && echo yes
11132 @result{} yes
11133 test -l abc -gt 1 && echo yes
11134 @result{} yes
11135 test 0x100 -eq 1
11136 @error{} test: integer expression expected before -eq
11137 @end example
11140 @node Connectives for test
11141 @subsection Connectives for @command{test}
11143 @cindex logical connectives
11144 @cindex connectives, logical
11146 The usual logical connectives.
11148 @table @samp
11150 @item ! @var{expr}
11151 @opindex !
11152 True if @var{expr} is false.
11154 @item @var{expr1} -a @var{expr2}
11155 @opindex -a
11156 @cindex logical and operator
11157 @cindex and operator
11158 True if both @var{expr1} and @var{expr2} are true.
11160 @item @var{expr1} -o @var{expr2}
11161 @opindex -o
11162 @cindex logical or operator
11163 @cindex or operator
11164 True if either @var{expr1} or @var{expr2} is true.
11166 @end table
11169 @node expr invocation
11170 @section @command{expr}: Evaluate expressions
11172 @pindex expr
11173 @cindex expression evaluation
11174 @cindex evaluation of expressions
11176 @command{expr} evaluates an expression and writes the result on standard
11177 output.  Each token of the expression must be a separate argument.
11179 Operands are either integers or strings.  Integers consist of one or
11180 more decimal digits, with an optional leading @samp{-}.
11181 @command{expr} converts
11182 anything appearing in an operand position to an integer or a string
11183 depending on the operation being applied to it.
11185 Strings are not quoted for @command{expr} itself, though you may need to
11186 quote them to protect characters with special meaning to the shell,
11187 e.g., spaces.  However, regardless of whether it is quoted, a string
11188 operand should not be a parenthesis or any of @command{expr}'s
11189 operators like @code{+}, so you cannot safely pass an arbitrary string
11190 @code{$str} to expr merely by quoting it to the shell.  One way to
11191 work around this is to use the @sc{gnu} extension @code{+},
11192 (e.g., @code{+ "$str" = foo}); a more portable way is to use
11193 @code{@w{" $str"}} and to adjust the rest of the expression to take
11194 the leading space into account (e.g., @code{@w{" $str" = " foo"}}).
11196 You should not pass a negative integer or a string with leading
11197 @samp{-} as @command{expr}'s first argument, as it might be
11198 misinterpreted as an option; this can be avoided by parenthesization.
11199 Also, portable scripts should not use a string operand that happens to
11200 take the form of an integer; this can be worked around by inserting
11201 leading spaces as mentioned above.
11203 @cindex parentheses for grouping
11204 Operators may be given as infix symbols or prefix keywords.  Parentheses
11205 may be used for grouping in the usual manner.  You must quote
11206 parentheses and many operators to avoid the shell evaluating them,
11207 however.
11209 When built with support for the GNU MP library, @command{expr} uses
11210 arbitrary-precision arithmetic; otherwise, it uses native arithmetic
11211 types and may fail due to arithmetic overflow.
11213 The only options are @option{--help} and @option{--version}.  @xref{Common
11214 options}.  Options must precede operands.
11216 @cindex exit status of @command{expr}
11217 Exit status:
11219 @display
11220 0 if the expression is neither null nor 0,
11221 1 if the expression is null or 0,
11222 2 if the expression is invalid,
11223 3 if an internal error occurred (e.g., arithmetic overflow).
11224 @end display
11226 @menu
11227 * String expressions::          + : match substr index length
11228 * Numeric expressions::         + - * / %
11229 * Relations for expr::          | & < <= = == != >= >
11230 * Examples of expr::            Examples.
11231 @end menu
11234 @node String expressions
11235 @subsection String expressions
11237 @cindex string expressions
11238 @cindex expressions, string
11240 @command{expr} supports pattern matching and other string operators.  These
11241 have higher precedence than both the numeric and relational operators (in
11242 the next sections).
11244 @table @samp
11246 @item @var{string} : @var{regex}
11247 @cindex pattern matching
11248 @cindex regular expression matching
11249 @cindex matching patterns
11250 Perform pattern matching.  The arguments are converted to strings and the
11251 second is considered to be a (basic, a la GNU @code{grep}) regular
11252 expression, with a @code{^} implicitly prepended.  The first argument is
11253 then matched against this regular expression.
11255 If the match succeeds and @var{regex} uses @samp{\(} and @samp{\)}, the
11256 @code{:} expression returns the part of @var{string} that matched the
11257 subexpression; otherwise, it returns the number of characters matched.
11259 If the match fails, the @code{:} operator returns the null string if
11260 @samp{\(} and @samp{\)} are used in @var{regex}, otherwise 0.
11262 @kindex \( @r{regexp operator}
11263 Only the first @samp{\( @dots{} \)} pair is relevant to the return
11264 value; additional pairs are meaningful only for grouping the regular
11265 expression operators.
11267 @kindex \+ @r{regexp operator}
11268 @kindex \? @r{regexp operator}
11269 @kindex \| @r{regexp operator}
11270 In the regular expression, @code{\+}, @code{\?}, and @code{\|} are
11271 operators which respectively match one or more, zero or one, or separate
11272 alternatives.  SunOS and other @command{expr}'s treat these as regular
11273 characters.  (@acronym{POSIX} allows either behavior.)
11274 @xref{Top, , Regular Expression Library, regex, Regex}, for details of
11275 regular expression syntax.  Some examples are in @ref{Examples of expr}.
11277 @item match @var{string} @var{regex}
11278 @findex match
11279 An alternative way to do pattern matching.  This is the same as
11280 @w{@samp{@var{string} : @var{regex}}}.
11282 @item substr @var{string} @var{position} @var{length}
11283 @findex substr
11284 Returns the substring of @var{string} beginning at @var{position}
11285 with length at most @var{length}.  If either @var{position} or
11286 @var{length} is negative, zero, or non-numeric, returns the null string.
11288 @item index @var{string} @var{charset}
11289 @findex index
11290 Returns the first position in @var{string} where the first character in
11291 @var{charset} was found.  If no character in @var{charset} is found in
11292 @var{string}, return 0.
11294 @item length @var{string}
11295 @findex length
11296 Returns the length of @var{string}.
11298 @item + @var{token}
11299 @kindex +
11300 Interpret @var{token} as a string, even if it is a keyword like @var{match}
11301 or an operator like @code{/}.
11302 This makes it possible to test @code{expr length + "$x"} or
11303 @code{expr + "$x" : '.*/\(.\)'} and have it do the right thing even if
11304 the value of @var{$x} happens to be (for example) @code{/} or @code{index}.
11305 This operator is a @acronym{GNU} extension.  Portable shell scripts should use
11306 @code{@w{" $token"} : @w{' \(.*\)'}} instead of @code{+ "$token"}.
11308 @end table
11310 To make @command{expr} interpret keywords as strings, you must use the
11311 @code{quote} operator.
11314 @node Numeric expressions
11315 @subsection Numeric expressions
11317 @cindex numeric expressions
11318 @cindex expressions, numeric
11320 @command{expr} supports the usual numeric operators, in order of increasing
11321 precedence.  These numeric operators have lower precedence than the
11322 string operators described in the previous section, and higher precedence
11323 than the connectives (next section).
11325 @table @samp
11327 @item + -
11328 @kindex +
11329 @kindex -
11330 @cindex addition
11331 @cindex subtraction
11332 Addition and subtraction.  Both arguments are converted to integers;
11333 an error occurs if this cannot be done.
11335 @item * / %
11336 @kindex *
11337 @kindex /
11338 @kindex %
11339 @cindex multiplication
11340 @cindex division
11341 @cindex remainder
11342 Multiplication, division, remainder.  Both arguments are converted to
11343 integers; an error occurs if this cannot be done.
11345 @end table
11348 @node Relations for expr
11349 @subsection Relations for @command{expr}
11351 @cindex connectives, logical
11352 @cindex logical connectives
11353 @cindex relations, numeric or string
11355 @command{expr} supports the usual logical connectives and relations.  These
11356 have lower precedence than the string and numeric operators
11357 (previous sections).  Here is the list, lowest-precedence operator first.
11359 @table @samp
11361 @item |
11362 @kindex |
11363 @cindex logical or operator
11364 @cindex or operator
11365 Returns its first argument if that is neither null nor zero, otherwise
11366 its second argument if it is neither null nor zero, otherwise 0.  It
11367 does not evaluate its second argument if its first argument is neither
11368 null nor zero.
11370 @item &
11371 @kindex &
11372 @cindex logical and operator
11373 @cindex and operator
11374 Return its first argument if neither argument is null or zero, otherwise
11375 0.  It does not evaluate its second argument if its first argument is
11376 null or zero.
11378 @item < <= = == != >= >
11379 @kindex <
11380 @kindex <=
11381 @kindex =
11382 @kindex ==
11383 @kindex >
11384 @kindex >=
11385 @cindex comparison operators
11386 @vindex LC_COLLATE
11387 Compare the arguments and return 1 if the relation is true, 0 otherwise.
11388 @code{==} is a synonym for @code{=}.  @command{expr} first tries to convert
11389 both arguments to integers and do a numeric comparison; if either
11390 conversion fails, it does a lexicographic comparison using the character
11391 collating sequence specified by the @env{LC_COLLATE} locale.
11393 @end table
11396 @node Examples of expr
11397 @subsection Examples of using @command{expr}
11399 @cindex examples of @command{expr}
11400 Here are a few examples, including quoting for shell metacharacters.
11402 To add 1 to the shell variable @code{foo}, in Bourne-compatible shells:
11404 @example
11405 foo=`expr $foo + 1`
11406 @end example
11408 To print the non-directory part of the file name stored in
11409 @code{$fname}, which need not contain a @code{/}:
11411 @example
11412 expr $fname : '.*/\(.*\)' '|' $fname
11413 @end example
11415 An example showing that @code{\+} is an operator:
11417 @example
11418 expr aaa : 'a\+'
11419 @result{} 3
11420 @end example
11422 @example
11423 expr abc : 'a\(.\)c'
11424 @result{} b
11425 expr index abcdef cz
11426 @result{} 3
11427 expr index index a
11428 @error{} expr: syntax error
11429 expr index + index a
11430 @result{} 0
11431 @end example
11434 @node Redirection
11435 @chapter Redirection
11437 @cindex redirection
11438 @cindex commands for redirection
11440 Unix shells commonly provide several forms of @dfn{redirection}---ways
11441 to change the input source or output destination of a command.  But one
11442 useful redirection is performed by a separate command, not by the shell;
11443 it's described here.
11445 @menu
11446 * tee invocation::              Redirect output to multiple files or processes.
11447 @end menu
11450 @node tee invocation
11451 @section @command{tee}: Redirect output to multiple files or processes
11453 @pindex tee
11454 @cindex pipe fitting
11455 @cindex destinations, multiple output
11456 @cindex read from stdin and write to stdout and files
11458 The @command{tee} command copies standard input to standard output and also
11459 to any files given as arguments.  This is useful when you want not only
11460 to send some data down a pipe, but also to save a copy.  Synopsis:
11462 @example
11463 tee [@var{option}]@dots{} [@var{file}]@dots{}
11464 @end example
11466 If a file being written to does not already exist, it is created.  If a
11467 file being written to already exists, the data it previously contained
11468 is overwritten unless the @option{-a} option is used.
11470 A @var{file} of @samp{-} causes @command{tee} to send another copy of
11471 input to standard output, but this is typically not that useful as the
11472 copies are interleaved.
11474 The program accepts the following options.  Also see @ref{Common options}.
11476 @table @samp
11477 @item -a
11478 @itemx --append
11479 @opindex -a
11480 @opindex --append
11481 Append standard input to the given files rather than overwriting
11482 them.
11484 @item -i
11485 @itemx --ignore-interrupts
11486 @opindex -i
11487 @opindex --ignore-interrupts
11488 Ignore interrupt signals.
11490 @end table
11492 The @command{tee} command is useful when you happen to be transferring a large
11493 amount of data and also want to summarize that data without reading
11494 it a second time.  For example, when you are downloading a DVD image,
11495 you often want to verify its signature or checksum right away.
11496 The inefficient way to do it is simply:
11498 @example
11499 wget http://example.com/some.iso && sha1sum some.iso
11500 @end example
11502 One problem with the above is that it makes you wait for the
11503 download to complete before starting the time-consuming SHA1 computation.
11504 Perhaps even more importantly, the above requires reading
11505 the DVD image a second time (the first was from the network).
11507 The efficient way to do it is to interleave the download
11508 and SHA1 computation.  Then, you'll get the checksum for
11509 free, because the entire process parallelizes so well:
11511 @example
11512 # slightly contrived, to demonstrate process substitution
11513 wget -O - http://example.com/dvd.iso \
11514   | tee >(sha1sum > dvd.sha1) > dvd.iso
11515 @end example
11517 That makes @command{tee} write not just to the expected output file,
11518 but also to a pipe running @command{sha1sum} and saving the final
11519 checksum in a file named @file{dvd.sha1}.
11521 Note, however, that this example relies on a feature of modern shells
11522 called @dfn{process substitution}
11523 (the @samp{>(command)} syntax, above;
11524 @xref{Process Substitution,,Process Substitution, bashref,
11525 The Bash Reference Manual}.),
11526 so it works with @command{zsh}, @command{bash}, and @command{ksh},
11527 but not with @command{/bin/sh}.  So if you write code like this
11528 in a shell script, be sure to start the script with @samp{#!/bin/bash}.
11530 Since the above example writes to one file and one process,
11531 a more conventional and portable use of @command{tee} is even better:
11533 @example
11534 wget -O - http://example.com/dvd.iso \
11535   | tee dvd.iso | sha1sum > dvd.sha1
11536 @end example
11538 You can extend this example to make @command{tee} write to two processes,
11539 computing MD5 and SHA1 checksums in parallel.  In this case,
11540 process substitution is required:
11542 @example
11543 wget -O - http://example.com/dvd.iso \
11544   | tee >(sha1sum > dvd.sha1) \
11545         >(md5sum > dvd.md5) \
11546   > dvd.iso
11547 @end example
11549 This technique is also useful when you want to make a @emph{compressed}
11550 copy of the contents of a pipe.
11551 Consider a tool to graphically summarize disk usage data from @samp{du -ak}.
11552 For a large hierarchy, @samp{du -ak} can run for a long time,
11553 and can easily produce terabytes of data, so you won't want to
11554 rerun the command unnecessarily.  Nor will you want to save
11555 the uncompressed output.
11557 Doing it the inefficient way, you can't even start the GUI
11558 until after you've compressed all of the @command{du} output:
11560 @example
11561 du -ak | gzip -9 > /tmp/du.gz
11562 gzip -d /tmp/du.gz | xdiskusage -a
11563 @end example
11565 With @command{tee} and process substitution, you start the GUI
11566 right away and eliminate the decompression completely:
11568 @example
11569 du -ak | tee >(gzip -9 > /tmp/du.gz) | xdiskusage -a
11570 @end example
11572 Finally, if you regularly create more than one type of
11573 compressed tarball at once, for example when @code{make dist} creates
11574 both @command{gzip}-compressed and @command{bzip2}-compressed tarballs,
11575 there may be a better way.
11576 Typical @command{automake}-generated @file{Makefile} rules create
11577 the two compressed tar archives with commands in sequence, like this
11578 (slightly simplified):
11580 @example
11581 tardir=your-pkg-M.N
11582 tar chof - "$tardir" | gzip  -9 -c > your-pkg-M.N.tar.gz
11583 tar chof - "$tardir" | bzip2 -9 -c > your-pkg-M.N.tar.bz2
11584 @end example
11586 However, if the hierarchy you are archiving and compressing is larger
11587 than a couple megabytes, and especially if you are using a multi-processor
11588 system with plenty of memory, then you can do much better by reading the
11589 directory contents only once and running the compression programs in parallel:
11591 @example
11592 tardir=your-pkg-M.N
11593 tar chof - "$tardir" \
11594   | tee >(gzip -9 -c > your-pkg-M.N.tar.gz) \
11595   | bzip2 -9 -c > your-pkg-M.N.tar.bz2
11596 @end example
11598 @exitstatus
11601 @node File name manipulation
11602 @chapter File name manipulation
11604 @cindex file name manipulation
11605 @cindex manipulation of file names
11606 @cindex commands for file name manipulation
11608 This section describes commands that manipulate file names.
11610 @menu
11611 * basename invocation::         Strip directory and suffix from a file name.
11612 * dirname invocation::          Strip non-directory suffix from a file name.
11613 * pathchk invocation::          Check file name validity and portability.
11614 @end menu
11617 @node basename invocation
11618 @section @command{basename}: Strip directory and suffix from a file name
11620 @pindex basename
11621 @cindex strip directory and suffix from file names
11622 @cindex directory, stripping from file names
11623 @cindex suffix, stripping from file names
11624 @cindex file names, stripping directory and suffix
11625 @cindex leading directory components, stripping
11627 @command{basename} removes any leading directory components from
11628 @var{name}.  Synopsis:
11630 @example
11631 basename @var{name} [@var{suffix}]
11632 @end example
11634 If @var{suffix} is specified and is identical to the end of @var{name},
11635 it is removed from @var{name} as well.  Note that since trailing slashes
11636 are removed prior to suffix matching, @var{suffix} will do nothing if it
11637 contains slashes.  @command{basename} prints the result on standard
11638 output.
11640 @c This test is used both here and in the section on dirname.
11641 @macro basenameAndDirname
11642 Together, @command{basename} and @command{dirname} are designed such
11643 that if @samp{ls "$name"} succeeds, then the command sequence @samp{cd
11644 "$(dirname "$name")"; ls "$(basename "$name")"} will, too.  This works
11645 for everything except file names containing a trailing newline.
11646 @end macro
11647 @basenameAndDirname
11649 @acronym{POSIX} allows the implementation to define the results if
11650 @var{name} is empty or @samp{//}.  In the former case, @acronym{GNU}
11651 @command{basename} returns the empty string.  In the latter case, the
11652 result is @samp{//} on platforms where @var{//} is distinct from
11653 @var{/}, and @samp{/} on platforms where there is no difference.
11655 The only options are @option{--help} and @option{--version}.  @xref{Common
11656 options}.  Options must precede operands.
11658 @exitstatus
11660 Examples:
11662 @smallexample
11663 # Output "sort".
11664 basename /usr/bin/sort
11666 # Output "stdio".
11667 basename include/stdio.h .h
11668 @end smallexample
11671 @node dirname invocation
11672 @section @command{dirname}: Strip non-directory suffix from a file name
11674 @pindex dirname
11675 @cindex directory components, printing
11676 @cindex stripping non-directory suffix
11677 @cindex non-directory suffix, stripping
11679 @command{dirname} prints all but the final slash-delimited component of
11680 a string (presumably a file name).  Synopsis:
11682 @example
11683 dirname @var{name}
11684 @end example
11686 If @var{name} is a single component, @command{dirname} prints @samp{.}
11687 (meaning the current directory).
11689 @basenameAndDirname
11691 @acronym{POSIX} allows the implementation to define the results if
11692 @var{name} is @samp{//}.  With @acronym{GNU} @command{dirname}, the
11693 result is @samp{//} on platforms where @var{//} is distinct from
11694 @var{/}, and @samp{/} on platforms where there is no difference.
11696 The only options are @option{--help} and @option{--version}.  @xref{Common
11697 options}.
11699 @exitstatus
11701 Examples:
11703 @smallexample
11704 # Output "/usr/bin".
11705 dirname /usr/bin/sort
11707 # Output ".".
11708 dirname stdio.h
11709 @end smallexample
11712 @node pathchk invocation
11713 @section @command{pathchk}: Check file name validity and portability
11715 @pindex pathchk
11716 @cindex file names, checking validity and portability
11717 @cindex valid file names, checking for
11718 @cindex portable file names, checking for
11720 @command{pathchk} checks validity and portability of file names.  Synopsis:
11722 @example
11723 pathchk [@var{option}]@dots{} @var{name}@dots{}
11724 @end example
11726 For each @var{name}, @command{pathchk} prints an error message if any of
11727 these conditions is true:
11729 @enumerate
11730 @item
11731 One of the existing directories in @var{name} does not have search
11732 (execute) permission,
11733 @item
11734 The length of @var{name} is larger than the maximum supported by the
11735 operating system.
11736 @item
11737 The length of one component of @var{name} is longer than
11738 its file system's maximum.
11739 @end enumerate
11741 A nonexistent @var{name} is not an error, so long a file with that
11742 name could be created under the above conditions.
11744 The program accepts the following options.  Also see @ref{Common options}.
11745 Options must precede operands.
11747 @table @samp
11749 @item -p
11750 @opindex -p
11751 Instead of performing checks based on the underlying file system,
11752 print an error message if any of these conditions is true:
11754 @enumerate
11755 @item
11756 A file name is empty.
11758 @item
11759 A file name contains a character outside the @acronym{POSIX} portable file
11760 name character set, namely, the ASCII letters and digits, @samp{.},
11761 @samp{_}, @samp{-}, and @samp{/}.
11763 @item
11764 The length of a file name or one of its components exceeds the
11765 @acronym{POSIX} minimum limits for portability.
11766 @end enumerate
11768 @item -P
11769 @opindex -P
11770 Print an error message if a file name is empty, or if it contains a component
11771 that begins with @samp{-}.
11773 @item --portability
11774 @opindex --portability
11775 Print an error message if a file name is not portable to all @acronym{POSIX}
11776 hosts.  This option is equivalent to @samp{-p -P}.
11778 @end table
11780 @cindex exit status of @command{pathchk}
11781 Exit status:
11783 @display
11784 0 if all specified file names passed all checks,
11785 1 otherwise.
11786 @end display
11789 @node Working context
11790 @chapter Working context
11792 @cindex working context
11793 @cindex commands for printing the working context
11795 This section describes commands that display or alter the context in
11796 which you are working: the current directory, the terminal settings, and
11797 so forth.  See also the user-related commands in the next section.
11799 @menu
11800 * pwd invocation::              Print working directory.
11801 * stty invocation::             Print or change terminal characteristics.
11802 * printenv invocation::         Print environment variables.
11803 * tty invocation::              Print file name of terminal on standard input.
11804 @end menu
11807 @node pwd invocation
11808 @section @command{pwd}: Print working directory
11810 @pindex pwd
11811 @cindex print name of current directory
11812 @cindex current working directory, printing
11813 @cindex working directory, printing
11815 @cindex symbolic links and @command{pwd}
11816 @command{pwd} prints the fully resolved name of the current directory.
11817 That is, all components of the printed name will be actual directory
11818 names---none will be symbolic links.
11820 The only options are a lone @option{--help} or
11821 @option{--version}.  @xref{Common options}.
11823 @mayConflictWithShellBuiltIn{pwd}
11825 @exitstatus
11828 @node stty invocation
11829 @section @command{stty}: Print or change terminal characteristics
11831 @pindex stty
11832 @cindex change or print terminal settings
11833 @cindex terminal settings
11834 @cindex line settings of terminal
11836 @command{stty} prints or changes terminal characteristics, such as baud rate.
11837 Synopses:
11839 @example
11840 stty [@var{option}] [@var{setting}]@dots{}
11841 stty [@var{option}]
11842 @end example
11844 If given no line settings, @command{stty} prints the baud rate, line
11845 discipline number (on systems that support it), and line settings
11846 that have been changed from the values set by @samp{stty sane}.
11847 By default, mode reading and setting are performed on the tty line
11848 connected to standard input, although this can be modified by the
11849 @option{--file} option.
11851 @command{stty} accepts many non-option arguments that change aspects of
11852 the terminal line operation, as described below.
11854 The program accepts the following options.  Also see @ref{Common options}.
11856 @table @samp
11857 @item -a
11858 @itemx --all
11859 @opindex -a
11860 @opindex --all
11861 Print all current settings in human-readable form.  This option may not
11862 be used in combination with any line settings.
11864 @item -F @var{device}
11865 @itemx --file=@var{device}
11866 @opindex -F
11867 @opindex --file
11868 Set the line opened by the file name specified in @var{device} instead of
11869 the tty line connected to standard input.  This option is necessary
11870 because opening a @acronym{POSIX} tty requires use of the @code{O_NONDELAY} flag to
11871 prevent a @acronym{POSIX} tty from blocking until the carrier detect line is high if
11872 the @code{clocal} flag is not set.  Hence, it is not always possible
11873 to allow the shell to open the device in the traditional manner.
11875 @item -g
11876 @itemx --save
11877 @opindex -g
11878 @opindex --save
11879 @cindex machine-readable @command{stty} output
11880 Print all current settings in a form that can be used as an argument to
11881 another @command{stty} command to restore the current settings.  This option
11882 may not be used in combination with any line settings.
11884 @end table
11886 Many settings can be turned off by preceding them with a @samp{-}.
11887 Such arguments are marked below with ``May be negated'' in their
11888 description.  The descriptions themselves refer to the positive
11889 case, that is, when @emph{not} negated (unless stated otherwise,
11890 of course).
11892 Some settings are not available on all @acronym{POSIX} systems, since they use
11893 extensions.  Such arguments are marked below with ``Non-@acronym{POSIX}'' in their
11894 description.  On non-@acronym{POSIX} systems, those or other settings also may not
11895 be available, but it's not feasible to document all the variations: just
11896 try it and see.
11898 @exitstatus
11900 @menu
11901 * Control::                     Control settings
11902 * Input::                       Input settings
11903 * Output::                      Output settings
11904 * Local::                       Local settings
11905 * Combination::                 Combination settings
11906 * Characters::                  Special characters
11907 * Special::                     Special settings
11908 @end menu
11911 @node Control
11912 @subsection Control settings
11914 @cindex control settings
11915 Control settings:
11917 @table @samp
11918 @item parenb
11919 @opindex parenb
11920 @cindex two-way parity
11921 Generate parity bit in output and expect parity bit in input.
11922 May be negated.
11924 @item parodd
11925 @opindex parodd
11926 @cindex odd parity
11927 @cindex even parity
11928 Set odd parity (even if negated).  May be negated.
11930 @item cs5
11931 @itemx cs6
11932 @itemx cs7
11933 @itemx cs8
11934 @opindex cs@var{n}
11935 @cindex character size
11936 @cindex eight-bit characters
11937 Set character size to 5, 6, 7, or 8 bits.
11939 @item hup
11940 @itemx hupcl
11941 @opindex hup[cl]
11942 Send a hangup signal when the last process closes the tty.  May be
11943 negated.
11945 @item cstopb
11946 @opindex cstopb
11947 @cindex stop bits
11948 Use two stop bits per character (one if negated).  May be negated.
11950 @item cread
11951 @opindex cread
11952 Allow input to be received.  May be negated.
11954 @item clocal
11955 @opindex clocal
11956 @cindex modem control
11957 Disable modem control signals.  May be negated.
11959 @item crtscts
11960 @opindex crtscts
11961 @cindex hardware flow control
11962 @cindex flow control, hardware
11963 @cindex RTS/CTS flow control
11964 Enable RTS/CTS flow control.  Non-@acronym{POSIX}.  May be negated.
11965 @end table
11968 @node Input
11969 @subsection Input settings
11971 @cindex input settings
11972 These settings control operations on data received from the terminal.
11974 @table @samp
11975 @item ignbrk
11976 @opindex ignbrk
11977 @cindex breaks, ignoring
11978 Ignore break characters.  May be negated.
11980 @item brkint
11981 @opindex brkint
11982 @cindex breaks, cause interrupts
11983 Make breaks cause an interrupt signal.  May be negated.
11985 @item ignpar
11986 @opindex ignpar
11987 @cindex parity, ignoring
11988 Ignore characters with parity errors.  May be negated.
11990 @item parmrk
11991 @opindex parmrk
11992 @cindex parity errors, marking
11993 Mark parity errors (with a 255-0-character sequence).  May be negated.
11995 @item inpck
11996 @opindex inpck
11997 Enable input parity checking.  May be negated.
11999 @item istrip
12000 @opindex istrip
12001 @cindex eight-bit input
12002 Clear high (8th) bit of input characters.  May be negated.
12004 @item inlcr
12005 @opindex inlcr
12006 @cindex newline, translating to return
12007 Translate newline to carriage return.  May be negated.
12009 @item igncr
12010 @opindex igncr
12011 @cindex return, ignoring
12012 Ignore carriage return.  May be negated.
12014 @item icrnl
12015 @opindex icrnl
12016 @cindex return, translating to newline
12017 Translate carriage return to newline.  May be negated.
12019 @item iutf8
12020 @opindex iutf8
12021 @cindex input encoding, UTF-8
12022 Assume input characters are UTF-8 encoded.  May be negated.
12024 @item ixon
12025 @opindex ixon
12026 @kindex C-s/C-q flow control
12027 @cindex XON/XOFF flow control
12028 Enable XON/XOFF flow control (that is, @kbd{CTRL-S}/@kbd{CTRL-Q}).  May
12029 be negated.
12031 @item ixoff
12032 @itemx tandem
12033 @opindex ixoff
12034 @opindex tandem
12035 @cindex software flow control
12036 @cindex flow control, software
12037 Enable sending of @code{stop} character when the system input buffer
12038 is almost full, and @code{start} character when it becomes almost
12039 empty again.  May be negated.
12041 @item iuclc
12042 @opindex iuclc
12043 @cindex uppercase, translating to lowercase
12044 Translate uppercase characters to lowercase.  Non-@acronym{POSIX}.  May be
12045 negated. Note ilcuc is not implemented, as one would not be able to issue
12046 almost any (lowercase) Unix command, after invoking it.
12048 @item ixany
12049 @opindex ixany
12050 Allow any character to restart output (only the start character
12051 if negated).  Non-@acronym{POSIX}.  May be negated.
12053 @item imaxbel
12054 @opindex imaxbel
12055 @cindex beeping at input buffer full
12056 Enable beeping and not flushing input buffer if a character arrives
12057 when the input buffer is full.  Non-@acronym{POSIX}.  May be negated.
12058 @end table
12061 @node Output
12062 @subsection Output settings
12064 @cindex output settings
12065 These settings control operations on data sent to the terminal.
12067 @table @samp
12068 @item opost
12069 @opindex opost
12070 Postprocess output.  May be negated.
12072 @item olcuc
12073 @opindex olcuc
12074 @cindex lowercase, translating to output
12075 Translate lowercase characters to uppercase.  Non-@acronym{POSIX}.  May be
12076 negated. (Note ouclc is not currently implemented.)
12078 @item ocrnl
12079 @opindex ocrnl
12080 @cindex return, translating to newline
12081 Translate carriage return to newline.  Non-@acronym{POSIX}.  May be negated.
12083 @item onlcr
12084 @opindex onlcr
12085 @cindex newline, translating to crlf
12086 Translate newline to carriage return-newline.  Non-@acronym{POSIX}.  May be
12087 negated.
12089 @item onocr
12090 @opindex onocr
12091 Do not print carriage returns in the first column.  Non-@acronym{POSIX}.
12092 May be negated.
12094 @item onlret
12095 @opindex onlret
12096 Newline performs a carriage return.  Non-@acronym{POSIX}.  May be negated.
12098 @item ofill
12099 @opindex ofill
12100 @cindex pad instead of timing for delaying
12101 Use fill (padding) characters instead of timing for delays.  Non-@acronym{POSIX}.
12102 May be negated.
12104 @item ofdel
12105 @opindex ofdel
12106 @cindex pad character
12107 Use @acronym{ASCII} @sc{del} characters for fill instead of
12108 @acronym{ASCII} @sc{nul} characters.  Non-@acronym{POSIX}.
12109 May be negated.
12111 @item nl1
12112 @itemx nl0
12113 @opindex nl@var{n}
12114 Newline delay style.  Non-@acronym{POSIX}.
12116 @item cr3
12117 @itemx cr2
12118 @itemx cr1
12119 @itemx cr0
12120 @opindex cr@var{n}
12121 Carriage return delay style.  Non-@acronym{POSIX}.
12123 @item tab3
12124 @itemx tab2
12125 @itemx tab1
12126 @itemx tab0
12127 @opindex tab@var{n}
12128 Horizontal tab delay style.  Non-@acronym{POSIX}.
12130 @item bs1
12131 @itemx bs0
12132 @opindex bs@var{n}
12133 Backspace delay style.  Non-@acronym{POSIX}.
12135 @item vt1
12136 @itemx vt0
12137 @opindex vt@var{n}
12138 Vertical tab delay style.  Non-@acronym{POSIX}.
12140 @item ff1
12141 @itemx ff0
12142 @opindex ff@var{n}
12143 Form feed delay style.  Non-@acronym{POSIX}.
12144 @end table
12147 @node Local
12148 @subsection Local settings
12150 @cindex local settings
12152 @table @samp
12153 @item isig
12154 @opindex isig
12155 Enable @code{interrupt}, @code{quit}, and @code{suspend} special
12156 characters.  May be negated.
12158 @item icanon
12159 @opindex icanon
12160 Enable @code{erase}, @code{kill}, @code{werase}, and @code{rprnt}
12161 special characters.  May be negated.
12163 @item iexten
12164 @opindex iexten
12165 Enable non-@acronym{POSIX} special characters.  May be negated.
12167 @item echo
12168 @opindex echo
12169 Echo input characters.  May be negated.
12171 @item echoe
12172 @itemx crterase
12173 @opindex echoe
12174 @opindex crterase
12175 Echo @code{erase} characters as backspace-space-backspace.  May be
12176 negated.
12178 @item echok
12179 @opindex echok
12180 @cindex newline echoing after @code{kill}
12181 Echo a newline after a @code{kill} character.  May be negated.
12183 @item echonl
12184 @opindex echonl
12185 @cindex newline, echoing
12186 Echo newline even if not echoing other characters.  May be negated.
12188 @item noflsh
12189 @opindex noflsh
12190 @cindex flushing, disabling
12191 Disable flushing after @code{interrupt} and @code{quit} special
12192 characters.  May be negated.
12194 @item xcase
12195 @opindex xcase
12196 @cindex case translation
12197 Enable input and output of uppercase characters by preceding their
12198 lowercase equivalents with @samp{\}, when @code{icanon} is set.
12199 Non-@acronym{POSIX}.  May be negated.
12201 @item tostop
12202 @opindex tostop
12203 @cindex background jobs, stopping at terminal write
12204 Stop background jobs that try to write to the terminal.  Non-@acronym{POSIX}.
12205 May be negated.
12207 @item echoprt
12208 @itemx prterase
12209 @opindex echoprt
12210 @opindex prterase
12211 Echo erased characters backward, between @samp{\} and @samp{/}.
12212 Non-@acronym{POSIX}.  May be negated.
12214 @item echoctl
12215 @itemx ctlecho
12216 @opindex echoctl
12217 @opindex ctlecho
12218 @cindex control characters, using @samp{^@var{c}}
12219 @cindex hat notation for control characters
12220 Echo control characters in hat notation (@samp{^@var{c}}) instead
12221 of literally.  Non-@acronym{POSIX}.  May be negated.
12223 @item echoke
12224 @itemx crtkill
12225 @opindex echoke
12226 @opindex crtkill
12227 Echo the @code{kill} special character by erasing each character on
12228 the line as indicated by the @code{echoprt} and @code{echoe} settings,
12229 instead of by the @code{echoctl} and @code{echok} settings.  Non-@acronym{POSIX}.
12230 May be negated.
12231 @end table
12234 @node Combination
12235 @subsection Combination settings
12237 @cindex combination settings
12238 Combination settings:
12240 @table @samp
12241 @item evenp
12242 @opindex evenp
12243 @itemx parity
12244 @opindex parity
12245 Same as @code{parenb -parodd cs7}.  May be negated.  If negated, same
12246 as @code{-parenb cs8}.
12248 @item oddp
12249 @opindex oddp
12250 Same as @code{parenb parodd cs7}.  May be negated.  If negated, same
12251 as @code{-parenb cs8}.
12253 @item nl
12254 @opindex nl
12255 Same as @code{-icrnl -onlcr}.  May be negated.  If negated, same as
12256 @code{icrnl -inlcr -igncr onlcr -ocrnl -onlret}.
12258 @item ek
12259 @opindex ek
12260 Reset the @code{erase} and @code{kill} special characters to their default
12261 values.
12263 @item sane
12264 @opindex sane
12265 Same as:
12267 @c This is too long to write inline.
12268 @example
12269 cread -ignbrk brkint -inlcr -igncr icrnl -ixoff
12270 -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr
12271 -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0
12272 ff0 isig icanon iexten echo echoe echok -echonl
12273 -noflsh -xcase -tostop -echoprt echoctl echoke
12274 @end example
12276 @noindent
12277 and also sets all special characters to their default values.
12279 @item cooked
12280 @opindex cooked
12281 Same as @code{brkint ignpar istrip icrnl ixon opost isig icanon}, plus
12282 sets the @code{eof} and @code{eol} characters to their default values
12283 if they are the same as the @code{min} and @code{time} characters.
12284 May be negated.  If negated, same as @code{raw}.
12286 @item raw
12287 @opindex raw
12288 Same as:
12290 @example
12291 -ignbrk -brkint -ignpar -parmrk -inpck -istrip
12292 -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany
12293 -imaxbel -opost -isig -icanon -xcase min 1 time 0
12294 @end example
12296 @noindent
12297 May be negated.  If negated, same as @code{cooked}.
12299 @item cbreak
12300 @opindex cbreak
12301 Same as @option{-icanon}.  May be negated.  If negated, same as
12302 @code{icanon}.
12304 @item pass8
12305 @opindex pass8
12306 @cindex eight-bit characters
12307 Same as @code{-parenb -istrip cs8}.  May be negated.  If negated,
12308 same as @code{parenb istrip cs7}.
12310 @item litout
12311 @opindex litout
12312 Same as @option{-parenb -istrip -opost cs8}.  May be negated.
12313 If negated, same as @code{parenb istrip opost cs7}.
12315 @item decctlq
12316 @opindex decctlq
12317 Same as @option{-ixany}.  Non-@acronym{POSIX}.  May be negated.
12319 @item tabs
12320 @opindex tabs
12321 Same as @code{tab0}.  Non-@acronym{POSIX}.  May be negated.  If negated, same
12322 as @code{tab3}.
12324 @item lcase
12325 @itemx LCASE
12326 @opindex lcase
12327 @opindex LCASE
12328 Same as @code{xcase iuclc olcuc}.  Non-@acronym{POSIX}.  May be negated.
12329 (Used for terminals with uppercase characters only.)
12331 @item crt
12332 @opindex crt
12333 Same as @code{echoe echoctl echoke}.
12335 @item dec
12336 @opindex dec
12337 Same as @code{echoe echoctl echoke -ixany intr ^C erase ^? kill C-u}.
12338 @end table
12341 @node Characters
12342 @subsection Special characters
12344 @cindex special characters
12345 @cindex characters, special
12347 The special characters' default values vary from system to system.
12348 They are set with the syntax @samp{name value}, where the names are
12349 listed below and the value can be given either literally, in hat
12350 notation (@samp{^@var{c}}), or as an integer which may start with
12351 @samp{0x} to indicate hexadecimal, @samp{0} to indicate octal, or
12352 any other digit to indicate decimal.
12354 @cindex disabling special characters
12355 @kindex u@r{, and disabling special characters}
12356 For GNU stty, giving a value of @code{^-} or @code{undef} disables that
12357 special character.  (This is incompatible with Ultrix @command{stty},
12358 which uses  a value of @samp{u} to disable a special character.  GNU
12359 @command{stty} treats a value @samp{u} like any other, namely to set that
12360 special character to @key{U}.)
12362 @table @samp
12364 @item intr
12365 @opindex intr
12366 Send an interrupt signal.
12368 @item quit
12369 @opindex quit
12370 Send a quit signal.
12372 @item erase
12373 @opindex erase
12374 Erase the last character typed.
12376 @item kill
12377 @opindex kill
12378 Erase the current line.
12380 @item eof
12381 @opindex eof
12382 Send an end of file (terminate the input).
12384 @item eol
12385 @opindex eol
12386 End the line.
12388 @item eol2
12389 @opindex eol2
12390 Alternate character to end the line.  Non-@acronym{POSIX}.
12392 @item swtch
12393 @opindex swtch
12394 Switch to a different shell layer.  Non-@acronym{POSIX}.
12396 @item start
12397 @opindex start
12398 Restart the output after stopping it.
12400 @item stop
12401 @opindex stop
12402 Stop the output.
12404 @item susp
12405 @opindex susp
12406 Send a terminal stop signal.
12408 @item dsusp
12409 @opindex dsusp
12410 Send a terminal stop signal after flushing the input.  Non-@acronym{POSIX}.
12412 @item rprnt
12413 @opindex rprnt
12414 Redraw the current line.  Non-@acronym{POSIX}.
12416 @item werase
12417 @opindex werase
12418 Erase the last word typed.  Non-@acronym{POSIX}.
12420 @item lnext
12421 @opindex lnext
12422 Enter the next character typed literally, even if it is a special
12423 character.  Non-@acronym{POSIX}.
12424 @end table
12427 @node Special
12428 @subsection Special settings
12430 @cindex special settings
12432 @table @samp
12433 @item min @var{n}
12434 @opindex min
12435 Set the minimum number of characters that will satisfy a read until
12436 the time value has expired, when @option{-icanon} is set.
12438 @item time @var{n}
12439 @opindex time
12440 Set the number of tenths of a second before reads time out if the minimum
12441 number of characters have not been read, when @option{-icanon} is set.
12443 @item ispeed @var{n}
12444 @opindex ispeed
12445 Set the input speed to @var{n}.
12447 @item ospeed @var{n}
12448 @opindex ospeed
12449 Set the output speed to @var{n}.
12451 @item rows @var{n}
12452 @opindex rows
12453 Tell the tty kernel driver that the terminal has @var{n} rows.  Non-@acronym{POSIX}.
12455 @item cols @var{n}
12456 @itemx columns @var{n}
12457 @opindex cols
12458 @opindex columns
12459 Tell the kernel that the terminal has @var{n} columns.  Non-@acronym{POSIX}.
12461 @item size
12462 @opindex size
12463 @vindex LINES
12464 @vindex COLUMNS
12465 Print the number of rows and columns that the kernel thinks the
12466 terminal has.  (Systems that don't support rows and columns in the kernel
12467 typically use the environment variables @env{LINES} and @env{COLUMNS}
12468 instead; however, GNU @command{stty} does not know anything about them.)
12469 Non-@acronym{POSIX}.
12471 @item line @var{n}
12472 @opindex line
12473 Use line discipline @var{n}.  Non-@acronym{POSIX}.
12475 @item speed
12476 @opindex speed
12477 Print the terminal speed.
12479 @item @var{n}
12480 @cindex baud rate, setting
12481 Set the input and output speeds to @var{n}.  @var{n} can be one of: 0
12482 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600 19200
12483 38400 @code{exta} @code{extb}.  @code{exta} is the same as 19200;
12484 @code{extb} is the same as 38400.  Many systems, including GNU/Linux,
12485 support higher speeds.  The @command{stty} command includes support
12486 for speeds of
12487 57600,
12488 115200,
12489 230400,
12490 460800,
12491 500000,
12492 576000,
12493 921600,
12494 1000000,
12495 1152000,
12496 1500000,
12497 2000000,
12498 2500000,
12499 3000000,
12500 3500000,
12502 4000000 where the system supports these.
12503 0 hangs up the line if @option{-clocal} is set.
12504 @end table
12507 @node printenv invocation
12508 @section @command{printenv}: Print all or some environment variables
12510 @pindex printenv
12511 @cindex printing all or some environment variables
12512 @cindex environment variables, printing
12514 @command{printenv} prints environment variable values.  Synopsis:
12516 @example
12517 printenv [@var{option}] [@var{variable}]@dots{}
12518 @end example
12520 If no @var{variable}s are specified, @command{printenv} prints the value of
12521 every environment variable.  Otherwise, it prints the value of each
12522 @var{variable} that is set, and nothing for those that are not set.
12524 The only options are a lone @option{--help} or @option{--version}.
12525 @xref{Common options}.
12527 @cindex exit status of @command{printenv}
12528 Exit status:
12530 @display
12531 0 if all variables specified were found
12532 1 if at least one specified variable was not found
12533 2 if a write error occurred
12534 @end display
12537 @node tty invocation
12538 @section @command{tty}: Print file name of terminal on standard input
12540 @pindex tty
12541 @cindex print terminal file name
12542 @cindex terminal file name, printing
12544 @command{tty} prints the file name of the terminal connected to its standard
12545 input.  It prints @samp{not a tty} if standard input is not a terminal.
12546 Synopsis:
12548 @example
12549 tty [@var{option}]@dots{}
12550 @end example
12552 The program accepts the following option.  Also see @ref{Common options}.
12554 @table @samp
12556 @item -s
12557 @itemx --silent
12558 @itemx --quiet
12559 @opindex -s
12560 @opindex --silent
12561 @opindex --quiet
12562 Print nothing; only return an exit status.
12564 @end table
12566 @cindex exit status of @command{tty}
12567 Exit status:
12569 @display
12570 0 if standard input is a terminal
12571 1 if standard input is not a terminal
12572 2 if given incorrect arguments
12573 3 if a write error occurs
12574 @end display
12577 @node User information
12578 @chapter User information
12580 @cindex user information, commands for
12581 @cindex commands for printing user information
12583 This section describes commands that print user-related information:
12584 logins, groups, and so forth.
12586 @menu
12587 * id invocation::               Print user identity.
12588 * logname invocation::          Print current login name.
12589 * whoami invocation::           Print effective user ID.
12590 * groups invocation::           Print group names a user is in.
12591 * users invocation::            Print login names of users currently logged in.
12592 * who invocation::              Print who is currently logged in.
12593 @end menu
12596 @node id invocation
12597 @section @command{id}: Print user identity
12599 @pindex id
12600 @cindex real user and group IDs, printing
12601 @cindex effective user and group IDs, printing
12602 @cindex printing real and effective user and group IDs
12604 @command{id} prints information about the given user, or the process
12605 running it if no user is specified.  Synopsis:
12607 @example
12608 id [@var{option}]@dots{} [@var{username}]
12609 @end example
12611 By default, it prints the real user ID, real group ID, effective user ID
12612 if different from the real user ID, effective group ID if different from
12613 the real group ID, and supplemental group IDs.
12615 Each of these numeric values is preceded by an identifying string and
12616 followed by the corresponding user or group name in parentheses.
12618 The options cause @command{id} to print only part of the above information.
12619 Also see @ref{Common options}.
12621 @table @samp
12622 @item -g
12623 @itemx --group
12624 @opindex -g
12625 @opindex --group
12626 Print only the group ID.
12628 @item -G
12629 @itemx --groups
12630 @opindex -G
12631 @opindex --groups
12632 Print only the group ID and the supplementary groups.
12634 @item -n
12635 @itemx --name
12636 @opindex -n
12637 @opindex --name
12638 Print the user or group name instead of the ID number.  Requires
12639 @option{-u}, @option{-g}, or @option{-G}.
12641 @item -r
12642 @itemx --real
12643 @opindex -r
12644 @opindex --real
12645 Print the real, instead of effective, user or group ID.  Requires
12646 @option{-u}, @option{-g}, or @option{-G}.
12648 @item -u
12649 @itemx --user
12650 @opindex -u
12651 @opindex --user
12652 Print only the user ID.
12654 @end table
12656 @exitstatus
12658 @macro primaryAndSupplementaryGroups{cmd,arg}
12659 Primary and supplementary groups for a process are normally inherited
12660 from its parent and are usually unchanged since login.  This means
12661 that if you change the group database after logging in, @command{\cmd\}
12662 will not reflect your changes within your existing login session.
12663 Running @command{\cmd\} with a \arg\ causes the user and group
12664 database to be consulted afresh, and so will give a different result.
12665 @end macro
12666 @primaryAndSupplementaryGroups{id,user argument}
12668 @node logname invocation
12669 @section @command{logname}: Print current login name
12671 @pindex logname
12672 @cindex printing user's login name
12673 @cindex login name, printing
12674 @cindex user name, printing
12676 @flindex utmp
12677 @command{logname} prints the calling user's name, as found in a
12678 system-maintained file (often @file{/var/run/utmp} or
12679 @file{/etc/utmp}), and exits with a status of 0.  If there is no entry
12680 for the calling process, @command{logname} prints
12681 an error message and exits with a status of 1.
12683 The only options are @option{--help} and @option{--version}.  @xref{Common
12684 options}.
12686 @exitstatus
12689 @node whoami invocation
12690 @section @command{whoami}: Print effective user ID
12692 @pindex whoami
12693 @cindex effective user ID, printing
12694 @cindex printing the effective user ID
12696 @command{whoami} prints the user name associated with the current
12697 effective user ID.  It is equivalent to the command @samp{id -un}.
12699 The only options are @option{--help} and @option{--version}.  @xref{Common
12700 options}.
12702 @exitstatus
12705 @node groups invocation
12706 @section @command{groups}: Print group names a user is in
12708 @pindex groups
12709 @cindex printing groups a user is in
12710 @cindex supplementary groups, printing
12712 @command{groups} prints the names of the primary and any supplementary
12713 groups for each given @var{username}, or the current process if no names
12714 are given.  If more than one name is given, the name of each user is
12715 printed before
12716 the list of that user's groups and the user name is separated from the
12717 group list by a colon.  Synopsis:
12719 @example
12720 groups [@var{username}]@dots{}
12721 @end example
12723 The group lists are equivalent to the output of the command @samp{id -Gn}.
12725 @primaryAndSupplementaryGroups{groups,list of users}
12727 The only options are @option{--help} and @option{--version}.  @xref{Common
12728 options}.
12730 @exitstatus
12733 @node users invocation
12734 @section @command{users}: Print login names of users currently logged in
12736 @pindex users
12737 @cindex printing current usernames
12738 @cindex usernames, printing current
12740 @cindex login sessions, printing users with
12741 @command{users} prints on a single line a blank-separated list of user
12742 names of users currently logged in to the current host.  Each user name
12743 corresponds to a login session, so if a user has more than one login
12744 session, that user's name will appear the same number of times in the
12745 output.  Synopsis:
12747 @example
12748 users [@var{file}]
12749 @end example
12751 @flindex utmp
12752 @flindex wtmp
12753 With no @var{file} argument, @command{users} extracts its information from
12754 a system-maintained file (often @file{/var/run/utmp} or
12755 @file{/etc/utmp}).  If a file argument is given, @command{users} uses
12756 that file instead.  A common choice is @file{/var/log/wtmp}.
12758 The only options are @option{--help} and @option{--version}.  @xref{Common
12759 options}.
12761 @exitstatus
12764 @node who invocation
12765 @section @command{who}: Print who is currently logged in
12767 @pindex who
12768 @cindex printing current user information
12769 @cindex information, about current users
12771 @command{who} prints information about users who are currently logged on.
12772 Synopsis:
12774 @example
12775 @command{who} [@var{option}] [@var{file}] [am i]
12776 @end example
12778 @cindex terminal lines, currently used
12779 @cindex login time
12780 @cindex remote hostname
12781 If given no non-option arguments, @command{who} prints the following
12782 information for each user currently logged on: login name, terminal
12783 line, login time, and remote hostname or X display.
12785 @flindex utmp
12786 @flindex wtmp
12787 If given one non-option argument, @command{who} uses that instead of
12788 a default system-maintained file (often @file{/var/run/utmp} or
12789 @file{/etc/utmp}) as the name of the file containing the record of
12790 users logged on.  @file{/var/log/wtmp} is commonly given as an argument
12791 to @command{who} to look at who has previously logged on.
12793 @opindex am i
12794 @opindex who am i
12795 If given two non-option arguments, @command{who} prints only the entry
12796 for the user running it (determined from its standard input), preceded
12797 by the hostname.  Traditionally, the two arguments given are @samp{am
12798 i}, as in @samp{who am i}.
12800 @vindex TZ
12801 Time stamps are listed according to the time zone rules specified by
12802 the @env{TZ} environment variable, or by the system default rules if
12803 @env{TZ} is not set.  @xref{TZ Variable,, Specifying the Time Zone
12804 with @env{TZ}, libc, The GNU C Library Reference Manual}.
12806 The program accepts the following options.  Also see @ref{Common options}.
12808 @table @samp
12810 @item -a
12811 @itemx --all
12812 @opindex -a
12813 @opindex --all
12814 Same as @samp{-b -d --login -p -r -t -T -u}.
12816 @item -b
12817 @itemx --boot
12818 @opindex -b
12819 @opindex --boot
12820 Print the date and time of last system boot.
12822 @item -d
12823 @itemx --dead
12824 @opindex -d
12825 @opindex --dead
12826 Print information corresponding to dead processes.
12828 @item -H
12829 @itemx --heading
12830 @opindex -H
12831 @opindex --heading
12832 Print a line of column headings.
12834 @item -l
12835 @itemx --login
12836 @opindex -l
12837 @opindex --login
12838 List only the entries that correspond to processes via which the
12839 system is waiting for a user to login.  The user name is always @samp{LOGIN}.
12841 @itemx --lookup
12842 @opindex --lookup
12843 Attempt to canonicalize hostnames found in utmp through a DNS lookup.  This
12844 is not the default because it can cause significant delays on systems with
12845 automatic dial-up internet access.
12847 @item -m
12848 @opindex -m
12849 Same as @samp{who am i}.
12851 @item -p
12852 @itemx --process
12853 @opindex -p
12854 @opindex --process
12855 List active processes spawned by init.
12857 @item -q
12858 @itemx --count
12859 @opindex -q
12860 @opindex --count
12861 Print only the login names and the number of users logged on.
12862 Overrides all other options.
12864 @item -r
12865 @itemx --runlevel
12866 @opindex -r
12867 @opindex --runlevel
12868 Print the current (and maybe previous) run-level of the init process.
12870 @item -s
12871 @opindex -s
12872 Ignored; for compatibility with other versions of @command{who}.
12874 @item -t
12875 @itemx --time
12876 @opindex -t
12877 @opindex --time
12878 Print last system clock change.
12880 @itemx -u
12881 @opindex -u
12882 @cindex idle time
12883 After the login time, print the number of hours and minutes that the
12884 user has been idle.  @samp{.} means the user was active in the last minute.
12885 @samp{old} means the user has been idle for more than 24 hours.
12887 @item -w
12888 @itemx -T
12889 @itemx --mesg
12890 @itemx --message
12891 @itemx --writable
12892 @opindex -w
12893 @opindex -T
12894 @opindex --mesg
12895 @opindex --message
12896 @opindex --writable
12897 @cindex message status
12898 @pindex write@r{, allowed}
12899 After each login name print a character indicating the user's message status:
12901 @display
12902 @samp{+} allowing @code{write} messages
12903 @samp{-} disallowing @code{write} messages
12904 @samp{?} cannot find terminal device
12905 @end display
12907 @end table
12909 @exitstatus
12912 @node System context
12913 @chapter System context
12915 @cindex system context
12916 @cindex context, system
12917 @cindex commands for system context
12919 This section describes commands that print or change system-wide
12920 information.
12922 @menu
12923 * arch invocation::             Print machine hardware name.
12924 * date invocation::             Print or set system date and time.
12925 * uname invocation::            Print system information.
12926 * hostname invocation::         Print or set system name.
12927 * hostid invocation::           Print numeric host identifier.
12928 * uptime invocation::           Print system uptime and load
12929 @end menu
12931 @node SELinux context
12932 @chapter SELinux context
12934 @cindex SELinux context
12935 @cindex SELinux, context
12936 @cindex commands for SELinux context
12938 This section describes commands for operations with SELinux
12939 contexts.
12941 @menu
12942 * chcon invocation::            Change SELinux context of file
12943 * runcon invocation::           Run a command in specified SELinux context
12944 @end menu
12946 @node chcon invocation
12947 @section @command{chcon}: Change SELinux context of file.
12949 @pindex chcon
12950 @cindex changing security context
12951 @cindex change SELinux context
12953 @command{chcon} changes the SELinux security context of the selected files.
12954 Synopses:
12956 @smallexample
12957 chcon [@var{option}]@dots{} @var{context} @var{file}@dots{}
12958 chcon [@var{option}]@dots{} [-u @var{user}] [-r @var{role}] [-l @var{range}] [-t @var{type}] @var{file}@dots{}
12959 chcon [@var{option}]@dots{} --reference=@var{rfile} @var{file}@dots{}
12960 @end smallexample
12962 Change the SELinux security context of each @var{file} to @var{context}.
12963 With @option{--reference}, change the security context of each @var{file}
12964 to that of @var{rfile}.
12966 The program accepts the following options.  Also see @ref{Common options}.
12968 @table @samp
12970 @item -h
12971 @itemx --no-dereference
12972 @opindex -h
12973 @opindex --no-dereference
12974 @cindex no dereference
12975 Affect symbolic links instead of any referenced file.
12977 @item --reference=@var{rfile}
12978 @opindex --reference
12979 @cindex reference file
12980 Use @var{rfile}'s security context rather than specifying a @var{context} value.
12982 @item -R
12983 @itemx --recursive
12984 @opindex -R
12985 @opindex --recursive
12986 Operate on files and directories recursively.
12988 @choptH
12989 @xref{Traversing symlinks}.
12991 @choptL
12992 @xref{Traversing symlinks}.
12994 @choptP
12995 @xref{Traversing symlinks}.
12997 @item -v
12998 @itemx --verbose
12999 @opindex -v
13000 @opindex --verbose
13001 @cindex diagnostic
13002 Output a diagnostic for every file processed.
13004 @item -u @var{user}
13005 @itemx --user=@var{user}
13006 @opindex -u
13007 @opindex --user
13008 Set user @var{user} in the target security context.
13010 @item -r @var{role}
13011 @itemx --role=@var{role}
13012 @opindex -r
13013 @opindex --role
13014 Set role @var{role} in the target security context.
13016 @item -t @var{type}
13017 @itemx --type=@var{type}
13018 @opindex -t
13019 @opindex --type
13020 Set type @var{type} in the target security context.
13022 @item -l @var{range}
13023 @itemx --range=@var{range}
13024 @opindex -l
13025 @opindex --range
13026 Set range @var{range} in the target security context.
13028 @end table
13030 @exitstatus
13032 @node runcon invocation
13033 @section @command{runcon}: Run a command in specified SELinux context
13035 @pindex runcon
13036 @cindex run with security context
13039 @command{runcon} runs file in specified SELinux security context.
13041 Synopses:
13042 @smallexample
13043 runcon @var{context} @var{command} [@var{args}]
13044 runcon [ -c ] [-u @var{user}] [-r @var{role}] [-t @var{type}] [-l @var{range}] @var{command} [@var{args}]
13045 @end smallexample
13047 Run @var{command} with completely-specified @var{context}, or with
13048 current or transitioned security context modified by one or more of @var{level},
13049 @var{role}, @var{type} and @var{user}.
13051 If none of @option{-c}, @option{-t}, @option{-u}, @option{-r}, or @option{-l}
13052 is specified, the first argument is used as the complete context.
13053 Any additional arguments after @var{command}
13054 are interpreted as arguments to the command.
13056 With neither @var{context} nor @var{command}, print the current security context.
13058 The program accepts the following options.  Also see @ref{Common options}.
13060 @table @samp
13062 @item -c
13063 @itemx --compute
13064 @opindex -c
13065 @opindex --compute
13066 Compute process transition context before modifying.
13068 @item -u @var{user}
13069 @itemx --user=@var{user}
13070 @opindex -u
13071 @opindex --user
13072 Set user @var{user} in the target security context.
13074 @item -r @var{role}
13075 @itemx --role=@var{role}
13076 @opindex -r
13077 @opindex --role
13078 Set role @var{role} in the target security context.
13080 @item -t @var{type}
13081 @itemx --type=@var{type}
13082 @opindex -t
13083 @opindex --type
13084 Set type @var{type} in the target security context.
13086 @item -l @var{range}
13087 @itemx --range=@var{range}
13088 @opindex -l
13089 @opindex --range
13090 Set range @var{range} in the target security context.
13092 @end table
13094 @cindex exit status of @command{runcon}
13095 Exit status:
13097 @display
13098 126 if @var{command} is found but cannot be invoked
13099 127 if @command{runcon} itself fails or if @var{command} cannot be found
13100 the exit status of @var{command} otherwise
13101 @end display
13103 @node date invocation
13104 @section @command{date}: Print or set system date and time
13106 @pindex date
13107 @cindex time, printing or setting
13108 @cindex printing the current time
13110 Synopses:
13112 @example
13113 date [@var{option}]@dots{} [+@var{format}]
13114 date [-u|--utc|--universal] @c this avoids a newline in the output
13115 [ MMDDhhmm[[CC]YY][.ss] ]
13116 @end example
13118 @vindex LC_TIME
13119 Invoking @command{date} with no @var{format} argument is equivalent to invoking
13120 it with a default format that depends on the @env{LC_TIME} locale category.
13121 In the default C locale, this format is @samp{'+%a %b %e %H:%M:%S %Z %Y'},
13122 so the output looks like @samp{Thu Mar @ 3 13:47:51 PST 2005}.
13124 @vindex TZ
13125 Normally, @command{date} uses the time zone rules indicated by the
13126 @env{TZ} environment variable, or the system default rules if @env{TZ}
13127 is not set.  @xref{TZ Variable,, Specifying the Time Zone with
13128 @env{TZ}, libc, The GNU C Library Reference Manual}.
13130 @findex strftime @r{and @command{date}}
13131 @cindex time formats
13132 @cindex formatting times
13133 If given an argument that starts with a @samp{+}, @command{date} prints the
13134 current date and time (or the date and time specified by the
13135 @option{--date} option, see below) in the format defined by that argument,
13136 which is similar to that of the @code{strftime} function.  Except for
13137 conversion specifiers, which start with @samp{%}, characters in the
13138 format string are printed unchanged.  The conversion specifiers are
13139 described below.
13141 @exitstatus
13143 @menu
13144 * Time conversion specifiers::     %[HIklMNpPrRsSTXzZ]
13145 * Date conversion specifiers::     %[aAbBcCdDeFgGhjmuUVwWxyY]
13146 * Literal conversion specifiers::  %[%nt]
13147 * Padding and other flags::        Pad with zeros, spaces, etc.
13148 * Setting the time::               Changing the system clock.
13149 * Options for date::               Instead of the current time.
13150 @detailmenu
13151 * Date input formats::             Specifying date strings.
13152 @end detailmenu
13153 * Examples of date::               Examples.
13154 @end menu
13156 @node Time conversion specifiers
13157 @subsection Time conversion specifiers
13159 @cindex time conversion specifiers
13160 @cindex conversion specifiers, time
13162 @command{date} conversion specifiers related to times.
13164 @table @samp
13165 @item %H
13166 hour (@samp{00}@dots{}@samp{23})
13167 @item %I
13168 hour (@samp{01}@dots{}@samp{12})
13169 @item %k
13170 hour (@samp{ 0}@dots{}@samp{23}).
13171 This is a @acronym{GNU} extension.
13172 @item %l
13173 hour (@samp{ 1}@dots{}@samp{12}).
13174 This is a @acronym{GNU} extension.
13175 @item %M
13176 minute (@samp{00}@dots{}@samp{59})
13177 @item %N
13178 nanoseconds (@samp{000000000}@dots{}@samp{999999999}).
13179 This is a @acronym{GNU} extension.
13180 @item %p
13181 locale's equivalent of either @samp{AM} or @samp{PM};
13182 blank in many locales.
13183 Noon is treated as @samp{PM} and midnight as @samp{AM}.
13184 @item %P
13185 like @samp{%p}, except lower case.
13186 This is a @acronym{GNU} extension.
13187 @item %r
13188 locale's 12-hour clock time (e.g., @samp{11:11:04 PM})
13189 @item %R
13190 24-hour hour and minute.  Same as @samp{%H:%M}.
13191 This is a @acronym{GNU} extension.
13192 @item %s
13193 @cindex epoch, seconds since
13194 @cindex seconds since the epoch
13195 @cindex beginning of time
13196 seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC.
13197 Leap seconds are not counted unless leap second support is available.
13198 @xref{%s-examples}, for examples.
13199 This is a @acronym{GNU} extension.
13200 @item %S
13201 second (@samp{00}@dots{}@samp{60}).
13202 This may be @samp{60} if leap seconds are supported.
13203 @item %T
13204 24-hour hour, minute, and second.  Same as @samp{%H:%M:%S}.
13205 @item %X
13206 locale's time representation (e.g., @samp{23:13:48})
13207 @item %z
13208 @w{@acronym{RFC} 2822/@acronym{ISO} 8601} style numeric time zone
13209 (e.g., @samp{-0600} or @samp{+0530}), or nothing if no
13210 time zone is determinable.  This value reflects the numeric time zone
13211 appropriate for the current time, using the time zone rules specified
13212 by the @env{TZ} environment variable.
13213 The time (and optionally, the time zone rules) can be overridden
13214 by the @option{--date} option.
13215 This is a @acronym{GNU} extension.
13216 @item %:z
13217 @w{@acronym{RFC} 3339/@acronym{ISO} 8601} style numeric time zone with
13218 @samp{:} (e.g., @samp{-06:00} or @samp{+05:30}), or nothing if no time
13219 zone is determinable.
13220 This is a @acronym{GNU} extension.
13221 @item %::z
13222 Numeric time zone to the nearest second with @samp{:} (e.g.,
13223 @samp{-06:00:00} or @samp{+05:30:00}), or nothing if no time zone is
13224 determinable.
13225 This is a @acronym{GNU} extension.
13226 @item %:::z
13227 Numeric time zone with @samp{:} using the minimum necessary precision
13228 (e.g., @samp{-06}, @samp{+05:30}, or @samp{-04:56:02}), or nothing if
13229 no time zone is determinable.
13230 This is a @acronym{GNU} extension.
13231 @item %Z
13232 alphabetic time zone abbreviation (e.g., @samp{EDT}), or nothing if no
13233 time zone is determinable.  See @samp{%z} for how it is determined.
13234 @end table
13237 @node Date conversion specifiers
13238 @subsection Date conversion specifiers
13240 @cindex date conversion specifiers
13241 @cindex conversion specifiers, date
13243 @command{date} conversion specifiers related to dates.
13245 @table @samp
13246 @item %a
13247 locale's abbreviated weekday name (e.g., @samp{Sun})
13248 @item %A
13249 locale's full weekday name, variable length (e.g., @samp{Sunday})
13250 @item %b
13251 locale's abbreviated month name (e.g., @samp{Jan})
13252 @item %B
13253 locale's full month name, variable length (e.g., @samp{January})
13254 @item %c
13255 locale's date and time (e.g., @samp{Thu Mar @ 3 23:05:25 2005})
13256 @item %C
13257 century.  This is like @samp{%Y}, except the last two digits are omitted.
13258 For example, it is @samp{20} if @samp{%Y} is @samp{2000},
13259 and is @samp{-0} if @samp{%Y} is @samp{-001}.
13260 It is normally at least two characters, but it may be more.
13261 @item %d
13262 day of month (e.g., @samp{01})
13263 @item %D
13264 date; same as @samp{%m/%d/%y}
13265 @item %e
13266 day of month, space padded; same as @samp{%_d}
13267 @item %F
13268 full date in @acronym{ISO} 8601 format; same as @samp{%Y-%m-%d}.
13269 This is a good choice for a date format, as it is standard and
13270 is easy to sort in the usual case where years are in the range
13271 0000@dots{}9999.
13272 This is a @acronym{GNU} extension.
13273 @item %g
13274 year corresponding to the @acronym{ISO} week number, but without the century
13275 (range @samp{00} through @samp{99}).  This has the same format and value
13276 as @samp{%y}, except that if the @acronym{ISO} week number (see
13277 @samp{%V}) belongs
13278 to the previous or next year, that year is used instead.
13279 This is a @acronym{GNU} extension.
13280 @item %G
13281 year corresponding to the @acronym{ISO} week number.  This has the
13282 same format and value as @samp{%Y}, except that if the @acronym{ISO}
13283 week number (see
13284 @samp{%V}) belongs to the previous or next year, that year is used
13285 instead.
13286 It is normally useful only if @samp{%V} is also used;
13287 for example, the format @samp{%G-%m-%d} is probably a mistake,
13288 since it combines the ISO week number year with the conventional month and day.
13289 This is a @acronym{GNU} extension.
13290 @item %h
13291 same as @samp{%b}
13292 @item %j
13293 day of year (@samp{001}@dots{}@samp{366})
13294 @item %m
13295 month (@samp{01}@dots{}@samp{12})
13296 @item %u
13297 day of week (@samp{1}@dots{}@samp{7}) with @samp{1} corresponding to Monday
13298 @item %U
13299 week number of year, with Sunday as the first day of the week
13300 (@samp{00}@dots{}@samp{53}).
13301 Days in a new year preceding the first Sunday are in week zero.
13302 @item %V
13303 @acronym{ISO} week number, that is, the
13304 week number of year, with Monday as the first day of the week
13305 (@samp{01}@dots{}@samp{53}).
13306 If the week containing January 1 has four or more days in
13307 the new year, then it is considered week 1; otherwise, it is week 53 of
13308 the previous year, and the next week is week 1.  (See the @acronym{ISO} 8601
13309 standard.)
13310 @item %w
13311 day of week (@samp{0}@dots{}@samp{6}) with 0 corresponding to Sunday
13312 @item %W
13313 week number of year, with Monday as first day of week
13314 (@samp{00}@dots{}@samp{53}).
13315 Days in a new year preceding the first Monday are in week zero.
13316 @item %x
13317 locale's date representation (e.g., @samp{12/31/99})
13318 @item %y
13319 last two digits of year (@samp{00}@dots{}@samp{99})
13320 @item %Y
13321 year.  This is normally at least four characters, but it may be more.
13322 Year @samp{0000} precedes year @samp{0001}, and year @samp{-001}
13323 precedes year @samp{0000}.
13324 @end table
13327 @node Literal conversion specifiers
13328 @subsection Literal conversion specifiers
13330 @cindex literal conversion specifiers
13331 @cindex conversion specifiers, literal
13333 @command{date} conversion specifiers that produce literal strings.
13335 @table @samp
13336 @item %%
13337 a literal %
13338 @item %n
13339 a newline
13340 @item %t
13341 a horizontal tab
13342 @end table
13345 @node Padding and other flags
13346 @subsection Padding and other flags
13348 @cindex numeric field padding
13349 @cindex padding of numeric fields
13350 @cindex fields, padding numeric
13352 Unless otherwise specified, @command{date} normally pads numeric fields
13353 with zeros, so that, for
13354 example, numeric months are always output as two digits.
13355 Seconds since the epoch are not padded, though,
13356 since there is no natural width for them.
13358 As a @acronym{GNU} extension, @command{date} recognizes any of the
13359 following optional flags after the @samp{%}:
13361 @table @samp
13362 @item -
13363 (hyphen) Do not pad the field; useful if the output is intended for
13364 human consumption.
13365 @item _
13366 (underscore) Pad with spaces; useful if you need a fixed
13367 number of characters in the output, but zeros are too distracting.
13368 @item 0
13369 (zero) Pad with zeros even if the conversion specifier
13370 would normally pad with spaces.
13371 @item ^
13372 Use upper case characters if possible.
13373 @item #
13374 Use opposite case characters if possible.
13375 A field that is normally upper case becomes lower case, and vice versa.
13376 @end table
13378 @noindent
13379 Here are some examples of padding:
13381 @example
13382 date +%d/%m -d "Feb 1"
13383 @result{} 01/02
13384 date +%-d/%-m -d "Feb 1"
13385 @result{} 1/2
13386 date +%_d/%_m -d "Feb 1"
13387 @result{}  1/ 2
13388 @end example
13390 As a @acronym{GNU} extension, you can specify the field width
13391 (after any flag, if present) as a decimal number.  If the natural size of the
13392 output of the field has less than the specified number of characters,
13393 the result is written right adjusted and padded to the given
13394 size.  For example, @samp{%9B} prints the right adjusted month name in
13395 a field of width 9.
13397 An optional modifier can follow the optional flag and width
13398 specification.  The modifiers are:
13400 @table @samp
13401 @item E
13402 Use the locale's alternate representation for date and time.  This
13403 modifier applies to the @samp{%c}, @samp{%C}, @samp{%x}, @samp{%X},
13404 @samp{%y} and @samp{%Y} conversion specifiers.  In a Japanese locale, for
13405 example, @samp{%Ex} might yield a date format based on the Japanese
13406 Emperors' reigns.
13408 @item O
13409 Use the locale's alternate numeric symbols for numbers.  This modifier
13410 applies only to numeric conversion specifiers.
13411 @end table
13413 If the format supports the modifier but no alternate representation
13414 is available, it is ignored.
13417 @node Setting the time
13418 @subsection Setting the time
13420 @cindex setting the time
13421 @cindex time setting
13422 @cindex appropriate privileges
13424 If given an argument that does not start with @samp{+}, @command{date} sets
13425 the system clock to the date and time specified by that argument (as
13426 described below).  You must have appropriate privileges to set the
13427 system clock.  The @option{--date} and @option{--set} options may not be
13428 used with such an argument.  The @option{--universal} option may be used
13429 with such an argument to indicate that the specified date and time are
13430 relative to Coordinated Universal Time rather than to the local time
13431 zone.
13433 The argument must consist entirely of digits, which have the following
13434 meaning:
13436 @table @samp
13437 @item MM
13438 month
13439 @item DD
13440 day within month
13441 @item hh
13442 hour
13443 @item mm
13444 minute
13445 @item CC
13446 first two digits of year (optional)
13447 @item YY
13448 last two digits of year (optional)
13449 @item ss
13450 second (optional)
13451 @end table
13453 The @option{--set} option also sets the system clock; see the next section.
13456 @node Options for date
13457 @subsection Options for @command{date}
13459 @cindex @command{date} options
13460 @cindex options for @command{date}
13462 The program accepts the following options.  Also see @ref{Common options}.
13464 @table @samp
13466 @item -d @var{datestr}
13467 @itemx --date=@var{datestr}
13468 @opindex -d
13469 @opindex --date
13470 @cindex parsing date strings
13471 @cindex date strings, parsing
13472 @cindex arbitrary date strings, parsing
13473 @opindex yesterday
13474 @opindex tomorrow
13475 @opindex next @var{day}
13476 @opindex last @var{day}
13477 Display the date and time specified in @var{datestr} instead of the
13478 current date and time.  @var{datestr} can be in almost any common
13479 format.  It can contain month names, time zones, @samp{am} and @samp{pm},
13480 @samp{yesterday}, etc.  For example, @option{--date="2004-02-27
13481 14:19:13.489392193 +0530"} specifies the instant of time that is
13482 489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a
13483 time zone that is 5 hours and 30 minutes east of @acronym{UTC}.@*
13484 @xref{Date input formats}.
13486 @item -f @var{datefile}
13487 @itemx --file=@var{datefile}
13488 @opindex -f
13489 @opindex --file
13490 Parse each line in @var{datefile} as with @option{-d} and display the
13491 resulting date and time.  If @var{datefile} is @samp{-}, use standard
13492 input.  This is useful when you have many dates to process, because the
13493 system overhead of starting up the @command{date} executable many times can
13494 be considerable.
13496 @item -r @var{file}
13497 @itemx --reference=@var{file}
13498 @opindex -r
13499 @opindex --reference
13500 Display the date and time of the last modification of @var{file},
13501 instead of the current date and time.
13503 @item -R
13504 @itemx --rfc-822
13505 @itemx --rfc-2822
13506 @opindex -R
13507 @opindex --rfc-822
13508 @opindex --rfc-2822
13509 Display the date and time using the format @samp{%a, %d %b %Y %H:%M:%S
13510 %z}, evaluated in the C locale so abbreviations are always in English.
13511 For example:
13513 @example
13514 Fri, 09 Sep 2005 13:51:39 -0700
13515 @end example
13517 This format conforms to
13518 @uref{ftp://ftp.rfc-editor.org/in-notes/rfc2822.txt, Internet
13519 @acronym{RFCs} 2822} and
13520 @uref{ftp://ftp.rfc-editor.org/in-notes/rfc822.txt, 822}, the
13521 current and previous standards for Internet email.
13523 @item --rfc-3339=@var{timespec}
13524 @opindex --rfc-3339=@var{timespec}
13525 Display the date using a format specified by
13526 @uref{ftp://ftp.rfc-editor.org/in-notes/rfc3339.txt, Internet
13527 @acronym{RFC} 3339}.  This is a subset of the @acronym{ISO} 8601
13528 format, except that it also permits applications to use a space rather
13529 than a @samp{T} to separate dates from times.  Unlike the other
13530 standard formats, @acronym{RFC} 3339 format is always suitable as
13531 input for the @option{--date} (@option{-d}) and @option{--file}
13532 (@option{-f}) options, regardless of the current locale.
13534 The argument @var{timespec} specifies how much of the time to include.
13535 It can be one of the following:
13537 @table @samp
13538 @item date
13539 Print just the full-date, e.g., @samp{2005-09-14}.
13540 This is equivalent to the format @samp{%Y-%m-%d}.
13542 @item seconds
13543 Print the full-date and full-time separated by a space, e.g.,
13544 @samp{2005-09-14 00:56:06+05:30}.  The output ends with a numeric
13545 time-offset; here the @samp{+05:30} means that local time is five
13546 hours and thirty minutes east of @acronym{UTC}.  This is equivalent to
13547 the format @samp{%Y-%m-%d %H:%M:%S%:z}.
13549 @item ns
13550 Like @samp{seconds}, but also print nanoseconds, e.g.,
13551 @samp{2005-09-14 00:56:06.998458565+05:30}.
13552 This is equivalent to the format @samp{%Y-%m-%d %H:%M:%S.%N%:z}.
13554 @end table
13556 @item -s @var{datestr}
13557 @itemx --set=@var{datestr}
13558 @opindex -s
13559 @opindex --set
13560 Set the date and time to @var{datestr}.  See @option{-d} above.
13562 @item -u
13563 @itemx --utc
13564 @itemx --universal
13565 @opindex -u
13566 @opindex --utc
13567 @opindex --universal
13568 @cindex Coordinated Universal Time
13569 @cindex UTC
13570 @cindex Greenwich Mean Time
13571 @cindex GMT
13572 @vindex TZ
13573 Use Coordinated Universal Time (@acronym{UTC}) by operating as if the
13574 @env{TZ} environment variable were set to the string @samp{UTC0}.
13575 Coordinated
13576 Universal Time is often called ``Greenwich Mean Time'' (@sc{gmt}) for
13577 historical reasons.
13578 @end table
13581 @node Examples of date
13582 @subsection Examples of @command{date}
13584 @cindex examples of @command{date}
13586 Here are a few examples.  Also see the documentation for the @option{-d}
13587 option in the previous section.
13589 @itemize @bullet
13591 @item
13592 To print the date of the day before yesterday:
13594 @example
13595 date --date='2 days ago'
13596 @end example
13598 @item
13599 To print the date of the day three months and one day hence:
13601 @example
13602 date --date='3 months 1 day'
13603 @end example
13605 @item
13606 To print the day of year of Christmas in the current year:
13608 @example
13609 date --date='25 Dec' +%j
13610 @end example
13612 @item
13613 To print the current full month name and the day of the month:
13615 @example
13616 date '+%B %d'
13617 @end example
13619 But this may not be what you want because for the first nine days of
13620 the month, the @samp{%d} expands to a zero-padded two-digit field,
13621 for example @samp{date -d 1may '+%B %d'} will print @samp{May 01}.
13623 @item
13624 To print a date without the leading zero for one-digit days
13625 of the month, you can use the (@acronym{GNU} extension)
13626 @samp{-} flag to suppress
13627 the padding altogether:
13629 @example
13630 date -d 1may '+%B %-d
13631 @end example
13633 @item
13634 To print the current date and time in the format required by many
13635 non-@acronym{GNU} versions of @command{date} when setting the system clock:
13637 @example
13638 date +%m%d%H%M%Y.%S
13639 @end example
13641 @item
13642 To set the system clock forward by two minutes:
13644 @example
13645 date --set='+2 minutes'
13646 @end example
13648 @item
13649 To print the date in @acronym{RFC} 2822 format,
13650 use @samp{date --rfc-2822}.  Here is some example output:
13652 @example
13653 Fri, 09 Sep 2005 13:51:39 -0700
13654 @end example
13656 @anchor{%s-examples}
13657 @item
13658 To convert a date string to the number of seconds since the epoch
13659 (which is 1970-01-01 00:00:00 UTC), use the @option{--date} option with
13660 the @samp{%s} format.  That can be useful in sorting and/or graphing
13661 and/or comparing data by date.  The following command outputs the
13662 number of the seconds since the epoch for the time two minutes after the
13663 epoch:
13665 @example
13666 date --date='1970-01-01 00:02:00 +0000' +%s
13668 @end example
13670 If you do not specify time zone information in the date string,
13671 @command{date} uses your computer's idea of the time zone when
13672 interpreting the string.  For example, if your computer's time zone is
13673 that of Cambridge, Massachusetts, which was then 5 hours (i.e., 18,000
13674 seconds) behind UTC:
13676 @example
13677 # local time zone used
13678 date --date='1970-01-01 00:02:00' +%s
13679 18120
13680 @end example
13682 @item
13683 If you're sorting or graphing dated data, your raw date values may be
13684 represented as seconds since the epoch.  But few people can look at
13685 the date @samp{946684800} and casually note ``Oh, that's the first second
13686 of the year 2000 in Greenwich, England.''
13688 @example
13689 date --date='2000-01-01 UTC' +%s
13690 946684800
13691 @end example
13693 An alternative is to use the @option{--utc} (@option{-u}) option.
13694 Then you may omit @samp{UTC} from the date string.  Although this
13695 produces the same result for @samp{%s} and many other format sequences,
13696 with a time zone offset different from zero, it would give a different
13697 result for zone-dependent formats like @samp{%z}.
13699 @example
13700 date -u --date=2000-01-01 +%s
13701 946684800
13702 @end example
13704 To convert such an unwieldy number of seconds back to
13705 a more readable form, use a command like this:
13707 @smallexample
13708 # local time zone used
13709 date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
13710 1999-12-31 19:00:00 -0500
13711 @end smallexample
13713 Or if you do not mind depending on the @samp{@@} feature present since
13714 coreutils 5.3.0, you could shorten this to:
13716 @smallexample
13717 date -d @@946684800 +"%F %T %z"
13718 1999-12-31 19:00:00 -0500
13719 @end smallexample
13721 Often it is better to output UTC-relative date and time:
13723 @smallexample
13724 date -u -d '1970-01-01 946684800 seconds' +"%Y-%m-%d %T %z"
13725 2000-01-01 00:00:00 +0000
13726 @end smallexample
13728 @end itemize
13731 @node arch invocation
13732 @section @command{arch}: Print machine hardware name
13734 @pindex arch
13735 @cindex print machine hardware name
13736 @cindex system information, printing
13738 @command{arch} prints the machine hardware name,
13739 and is equivalent to @samp{uname -m}.
13740 Synopsis:
13742 @example
13743 arch [@var{option}]
13744 @end example
13746 The program accepts the @ref{Common options} only.
13748 @exitstatus
13751 @node uname invocation
13752 @section @command{uname}: Print system information
13754 @pindex uname
13755 @cindex print system information
13756 @cindex system information, printing
13758 @command{uname} prints information about the machine and operating system
13759 it is run on.  If no options are given, @command{uname} acts as if the
13760 @option{-s} option were given.  Synopsis:
13762 @example
13763 uname [@var{option}]@dots{}
13764 @end example
13766 If multiple options or @option{-a} are given, the selected information is
13767 printed in this order:
13769 @example
13770 @var{kernel-name} @var{nodename} @var{kernel-release} @var{kernel-version}
13771 @var{machine} @var{processor} @var{hardware-platform} @var{operating-system}
13772 @end example
13774 The information may contain internal spaces, so such output cannot be
13775 parsed reliably.  In the following example, @var{release} is
13776 @samp{2.2.18ss.e820-bda652a #4 SMP Tue Jun 5 11:24:08 PDT 2001}:
13778 @smallexample
13779 uname -a
13780 @result{} Linux dum 2.2.18 #4 SMP Tue Jun 5 11:24:08 PDT 2001 i686 unknown unknown GNU/Linux
13781 @end smallexample
13784 The program accepts the following options.  Also see @ref{Common options}.
13786 @table @samp
13788 @item -a
13789 @itemx --all
13790 @opindex -a
13791 @opindex --all
13792 Print all of the below information, except omit the processor type
13793 and the hardware platform name if they are unknown.
13795 @item -i
13796 @itemx --hardware-platform
13797 @opindex -i
13798 @opindex --hardware-platform
13799 @cindex implementation, hardware
13800 @cindex hardware platform
13801 @cindex platform, hardware
13802 Print the hardware platform name
13803 (sometimes called the hardware implementation).
13804 Print @samp{unknown} if the kernel does not make this information
13805 easily available, as is the case with Linux kernels.
13807 @item -m
13808 @itemx --machine
13809 @opindex -m
13810 @opindex --machine
13811 @cindex machine type
13812 @cindex hardware class
13813 @cindex hardware type
13814 Print the machine hardware name (sometimes called the hardware class
13815 or hardware type).
13817 @item -n
13818 @itemx --nodename
13819 @opindex -n
13820 @opindex --nodename
13821 @cindex hostname
13822 @cindex node name
13823 @cindex network node name
13824 Print the network node hostname.
13826 @item -p
13827 @itemx --processor
13828 @opindex -p
13829 @opindex --processor
13830 @cindex host processor type
13831 Print the processor type (sometimes called the instruction set
13832 architecture or ISA).
13833 Print @samp{unknown} if the kernel does not make this information
13834 easily available, as is the case with Linux kernels.
13836 @item -o
13837 @itemx --operating-system
13838 @opindex -o
13839 @opindex --operating-system
13840 @cindex operating system name
13841 Print the name of the operating system.
13843 @item -r
13844 @itemx --kernel-release
13845 @opindex -r
13846 @opindex --kernel-release
13847 @cindex kernel release
13848 @cindex release of kernel
13849 Print the kernel release.
13851 @item -s
13852 @itemx --kernel-name
13853 @opindex -s
13854 @opindex --kernel-name
13855 @cindex kernel name
13856 @cindex name of kernel
13857 Print the kernel name.
13858 @acronym{POSIX} 1003.1-2001 (@pxref{Standards conformance}) calls this
13859 ``the implementation of the operating system'', because the
13860 @acronym{POSIX} specification itself has no notion of ``kernel''.
13861 The kernel name might be the same as the operating system name printed
13862 by the @option{-o} or @option{--operating-system} option, but it might
13863 differ.  Some operating systems (e.g., FreeBSD, HP-UX) have the same
13864 name as their underlying kernels; others (e.g., GNU/Linux, Solaris)
13865 do not.
13867 @item -v
13868 @itemx --kernel-version
13869 @opindex -v
13870 @opindex --kernel-version
13871 @cindex kernel version
13872 @cindex version of kernel
13873 Print the kernel version.
13875 @end table
13877 @exitstatus
13880 @node hostname invocation
13881 @section @command{hostname}: Print or set system name
13883 @pindex hostname
13884 @cindex setting the hostname
13885 @cindex printing the hostname
13886 @cindex system name, printing
13887 @cindex appropriate privileges
13889 With no arguments, @command{hostname} prints the name of the current host
13890 system.  With one argument, it sets the current host name to the
13891 specified string.  You must have appropriate privileges to set the host
13892 name.  Synopsis:
13894 @example
13895 hostname [@var{name}]
13896 @end example
13898 The only options are @option{--help} and @option{--version}.  @xref{Common
13899 options}.
13901 @exitstatus
13904 @node hostid invocation
13905 @section @command{hostid}: Print numeric host identifier.
13907 @pindex hostid
13908 @cindex printing the host identifier
13910 @command{hostid} prints the numeric identifier of the current host
13911 in hexadecimal.  This command accepts no arguments.
13912 The only options are @option{--help} and @option{--version}.
13913 @xref{Common options}.
13915 For example, here's what it prints on one system I use:
13917 @example
13918 $ hostid
13919 1bac013d
13920 @end example
13922 On that system, the 32-bit quantity happens to be closely
13923 related to the system's Internet address, but that isn't always
13924 the case.
13926 @exitstatus
13928 @node uptime invocation
13929 @section @command{uptime}: Print system uptime and load
13931 @pindex uptime
13932 @cindex printing the system uptime and load
13934 @command{uptime} prints the current time, the system's uptime, the
13935 number of logged-in users and the current load average.
13937 If an argument is specified, it is used as the file to be read
13938 to discover how many users are logged in.  If no argument is
13939 specified, a system default is used (@command{uptime --help} indicates
13940 the default setting).
13942 The only options are @option{--help} and @option{--version}.
13943 @xref{Common options}.
13945 For example, here's what it prints right now on one system I use:
13947 @example
13948 $ uptime
13949  14:07  up   3:35,  3 users,  load average: 1.39, 1.15, 1.04
13950 @end example
13952 The precise method of calculation of load average varies somewhat
13953 between systems.  Some systems calculate it as the average number of
13954 runnable processes over the last 1, 5 and 15 minutes, but some systems
13955 also include processes in the uninterruptible sleep state (that is,
13956 those processes which are waiting for disk I/O).  The Linux kernel
13957 includes uninterruptible processes.
13959 @node Modified command invocation
13960 @chapter Modified command invocation
13962 @cindex modified command invocation
13963 @cindex invocation of commands, modified
13964 @cindex commands for invoking other commands
13966 This section describes commands that run other commands in some context
13967 different than the current one: a modified environment, as a different
13968 user, etc.
13970 @menu
13971 * chroot invocation::           Modify the root directory.
13972 * env invocation::              Modify environment variables.
13973 * nice invocation::             Modify niceness.
13974 * nohup invocation::            Immunize to hangups.
13975 * su invocation::               Modify user and group ID.
13976 * timeout invocation::          Run with time limit.
13977 @end menu
13980 @node chroot invocation
13981 @section @command{chroot}: Run a command with a different root directory
13983 @pindex chroot
13984 @cindex running a program in a specified root directory
13985 @cindex root directory, running a program in a specified
13987 @command{chroot} runs a command with a specified root directory.
13988 On many systems, only the super-user can do this.@footnote{However,
13989 some systems (e.g., FreeBSD) can be configured to allow certain regular
13990 users to use the @code{chroot} system call, and hence to run this program.
13991 Also, on Cygwin, anyone can run the @command{chroot} command, because the
13992 underlying function is non-privileged due to lack of support in MS-Windows.}
13993 Synopses:
13995 @example
13996 chroot @var{newroot} [@var{command} [@var{args}]@dots{}]
13997 chroot @var{option}
13998 @end example
14000 Ordinarily, file names are looked up starting at the root of the
14001 directory structure, i.e., @file{/}.  @command{chroot} changes the root to
14002 the directory @var{newroot} (which must exist) and then runs
14003 @var{command} with optional @var{args}.  If @var{command} is not
14004 specified, the default is the value of the @env{SHELL} environment
14005 variable or @command{/bin/sh} if not set, invoked with the @option{-i} option.
14006 @var{command} must not be a special built-in utility
14007 (@pxref{Special built-in utilities}).
14009 The only options are @option{--help} and @option{--version}.  @xref{Common
14010 options}.  Options must precede operands.
14012 Here are a few tips to help avoid common problems in using chroot.
14013 To start with a simple example, make @var{command} refer to a statically
14014 linked binary.  If you were to use a dynamically linked executable, then
14015 you'd have to arrange to have the shared libraries in the right place under
14016 your new root directory.
14018 For example, if you create a statically linked @command{ls} executable,
14019 and put it in @file{/tmp/empty}, you can run this command as root:
14021 @example
14022 $ chroot /tmp/empty /ls -Rl /
14023 @end example
14025 Then you'll see output like this:
14027 @example
14029 total 1023
14030 -rwxr-xr-x 1 0 0 1041745 Aug 16 11:17 ls
14031 @end example
14033 If you want to use a dynamically linked executable, say @command{bash},
14034 then first run @samp{ldd bash} to see what shared objects it needs.
14035 Then, in addition to copying the actual binary, also copy the listed
14036 files to the required positions under your intended new root directory.
14037 Finally, if the executable requires any other files (e.g., data, state,
14038 device files), copy them into place, too.
14040 @cindex exit status of @command{chroot}
14041 Exit status:
14043 @display
14044 1   if @command{chroot} itself fails
14045 126 if @var{command} is found but cannot be invoked
14046 127 if @var{command} cannot be found
14047 the exit status of @var{command} otherwise
14048 @end display
14051 @node env invocation
14052 @section @command{env}: Run a command in a modified environment
14054 @pindex env
14055 @cindex environment, running a program in a modified
14056 @cindex modified environment, running a program in a
14057 @cindex running a program in a modified environment
14059 @command{env} runs a command with a modified environment.  Synopses:
14061 @example
14062 env [@var{option}]@dots{} [@var{name}=@var{value}]@dots{} @c
14063 [@var{command} [@var{args}]@dots{}]
14065 @end example
14067 Operands of the form @samp{@var{variable}=@var{value}} set
14068 the environment variable @var{variable} to value @var{value}.
14069 @var{value} may be empty (@samp{@var{variable}=}).  Setting a variable
14070 to an empty value is different from unsetting it.
14071 These operands are evaluated left-to-right, so if two operands
14072 mention the same variable the earlier is ignored.
14074 Environment variable names can be empty, and can contain any
14075 characters other than @samp{=} and @acronym{ASCII} @sc{nul}.
14076 However, it is wise to limit yourself to names that
14077 consist solely of underscores, digits, and @acronym{ASCII} letters,
14078 and that begin with a non-digit, as applications like the shell do not
14079 work well with other names.
14081 @vindex PATH
14082 The first operand that does not contain the character @samp{=}
14083 specifies the program to invoke; it is
14084 searched for according to the @env{PATH} environment variable.  Any
14085 remaining arguments are passed as arguments to that program.
14086 The program should not be a special built-in utility
14087 (@pxref{Special built-in utilities}).
14089 @cindex environment, printing
14091 If no command name is specified following the environment
14092 specifications, the resulting environment is printed.  This is like
14093 specifying the @command{printenv} program.
14095 The program accepts the following options.  Also see @ref{Common options}.
14096 Options must precede operands.
14098 @table @samp
14100 @item -u @var{name}
14101 @itemx --unset=@var{name}
14102 @opindex -u
14103 @opindex --unset
14104 Remove variable @var{name} from the environment, if it was in the
14105 environment.
14107 @item -
14108 @itemx -i
14109 @itemx --ignore-environment
14110 @opindex -
14111 @opindex -i
14112 @opindex --ignore-environment
14113 Start with an empty environment, ignoring the inherited environment.
14115 @end table
14117 @cindex exit status of @command{env}
14118 Exit status:
14120 @display
14121 0   if no @var{command} is specified and the environment is output
14122 1   if @command{env} itself fails
14123 126 if @var{command} is found but cannot be invoked
14124 127 if @var{command} cannot be found
14125 the exit status of @var{command} otherwise
14126 @end display
14129 @node nice invocation
14130 @section @command{nice}: Run a command with modified niceness
14132 @pindex nice
14133 @cindex niceness
14134 @cindex scheduling, affecting
14135 @cindex appropriate privileges
14137 @command{nice} prints or modifies a process's @dfn{niceness},
14138 a parameter that affects whether the process is scheduled favorably.
14139 Synopsis:
14141 @example
14142 nice [@var{option}]@dots{} [@var{command} [@var{arg}]@dots{}]
14143 @end example
14145 If no arguments are given, @command{nice} prints the current niceness.
14146 Otherwise, @command{nice} runs the given @var{command} with its
14147 niceness adjusted.  By default, its niceness is incremented by 10.
14149 Niceness values range at least from @minus{}20 (process has high priority
14150 and gets more resources, thus slowing down other processes) through 19
14151 (process has lower priority and runs slowly itself, but has less impact
14152 on the speed of other running processes).  Some systems
14153 may have a wider range of nicenesses; conversely, other systems may
14154 enforce more restrictive limits.  An attempt to set the niceness
14155 outside the supported range is treated as an attempt to use the
14156 minimum or maximum supported value.
14158 A niceness should not be confused with a scheduling priority, which
14159 lets applications determine the order in which threads are scheduled
14160 to run.  Unlike a priority, a niceness is merely advice to the
14161 scheduler, which the scheduler is free to ignore.  Also, as a point of
14162 terminology, @acronym{POSIX} defines the behavior of @command{nice} in
14163 terms of a @dfn{nice value}, which is the nonnegative difference
14164 between a niceness and the minimum niceness.  Though @command{nice}
14165 conforms to @acronym{POSIX}, its documentation and diagnostics use the
14166 term ``niceness'' for compatibility with historical practice.
14168 @var{command} must not be a special built-in utility (@pxref{Special
14169 built-in utilities}).
14171 @mayConflictWithShellBuiltIn{nice}
14173 The program accepts the following option.  Also see @ref{Common options}.
14174 Options must precede operands.
14176 @table @samp
14177 @item -n @var{adjustment}
14178 @itemx --adjustment=@var{adjustment}
14179 @opindex -n
14180 @opindex --adjustment
14181 Add @var{adjustment} instead of 10 to the command's niceness.  If
14182 @var{adjustment} is negative and you lack appropriate privileges,
14183 @command{nice} issues a warning but otherwise acts as if you specified
14184 a zero adjustment.
14186 For compatibility @command{nice} also supports an obsolete
14187 option syntax @option{-@var{adjustment}}.  New scripts should use
14188 @option{-n @var{adjustment}} instead.
14190 @end table
14192 @cindex exit status of @command{nice}
14193 Exit status:
14195 @display
14196 0   if no @var{command} is specified and the niceness is output
14197 1   if @command{nice} itself fails
14198 126 if @var{command} is found but cannot be invoked
14199 127 if @var{command} cannot be found
14200 the exit status of @var{command} otherwise
14201 @end display
14203 It is sometimes useful to run a non-interactive program with reduced niceness.
14205 @example
14206 $ nice factor 4611686018427387903
14207 @end example
14209 Since @command{nice} prints the current niceness,
14210 you can invoke it through itself to demonstrate how it works.
14212 The default behavior is to increase the niceness by @samp{10}:
14214 @example
14215 $ nice
14217 $ nice nice
14219 $ nice -n 10 nice
14221 @end example
14223 The @var{adjustment} is relative to the current niceness.  In the
14224 next example, the first @command{nice} invocation runs the second one
14225 with niceness 10, and it in turn runs the final one with a niceness
14226 that is 3 more:
14228 @example
14229 $ nice nice -n 3 nice
14231 @end example
14233 Specifying a niceness larger than the supported range
14234 is the same as specifying the maximum supported value:
14236 @example
14237 $ nice -n 10000000000 nice
14239 @end example
14241 Only a privileged user may run a process with lower niceness:
14243 @example
14244 $ nice -n -1 nice
14245 nice: cannot set niceness: Permission denied
14247 $ sudo nice -n -1 nice
14249 @end example
14252 @node nohup invocation
14253 @section @command{nohup}: Run a command immune to hangups
14255 @pindex nohup
14256 @cindex hangups, immunity to
14257 @cindex immunity to hangups
14258 @cindex logging out and continuing to run
14260 @flindex nohup.out
14261 @command{nohup} runs the given @var{command} with hangup signals ignored,
14262 so that the command can continue running in the background after you log
14263 out.  Synopsis:
14265 @example
14266 nohup @var{command} [@var{arg}]@dots{}
14267 @end example
14269 If standard input is a terminal, it is redirected from
14270 @file{/dev/null} so that terminal sessions do not mistakenly consider
14271 the terminal to be used by the command.  This is a @acronym{GNU}
14272 extension; programs intended to be portable to non-@acronym{GNU} hosts
14273 should use @samp{nohup @var{command} [@var{arg}]@dots{} </dev/null}
14274 instead.
14276 @flindex nohup.out
14277 If standard output is a terminal, the command's standard output is appended
14278 to the file @file{nohup.out}; if that cannot be written to, it is appended
14279 to the file @file{$HOME/nohup.out}; and if that cannot be written to, the
14280 command is not run.
14281 Any @file{nohup.out} or @file{$HOME/nohup.out} file created by
14282 @command{nohup} is made readable and writable only to the user,
14283 regardless of the current umask settings.
14285 If standard error is a terminal, it is normally redirected to the same file
14286 descriptor as the (possibly-redirected) standard output.
14287 However, if standard output is closed, standard error terminal output
14288 is instead appended to the file @file{nohup.out} or
14289 @file{$HOME/nohup.out} as above.
14291 To capture the command's output to a file other than @file{nohup.out}
14292 you can redirect it.  For example, to capture the output of
14293 @command{make}:
14295 @example
14296 nohup make > make.log
14297 @end example
14299 @command{nohup} does not automatically put the command it runs in the
14300 background; you must do that explicitly, by ending the command line
14301 with an @samp{&}.  Also, @command{nohup} does not alter the
14302 niceness of @var{command}; use @command{nice} for that,
14303 e.g., @samp{nohup nice @var{command}}.
14305 @var{command} must not be a special built-in utility (@pxref{Special
14306 built-in utilities}).
14308 The only options are @option{--help} and @option{--version}.  @xref{Common
14309 options}.  Options must precede operands.
14311 @cindex exit status of @command{nohup}
14312 Exit status:
14314 @display
14315 126 if @var{command} is found but cannot be invoked
14316 127 if @command{nohup} itself fails or if @var{command} cannot be found
14317 the exit status of @var{command} otherwise
14318 @end display
14321 @node su invocation
14322 @section @command{su}: Run a command with substitute user and group ID
14324 @pindex su
14325 @cindex substitute user and group IDs
14326 @cindex user ID, switching
14327 @cindex super-user, becoming
14328 @cindex root, becoming
14330 @command{su} allows one user to temporarily become another user.  It runs a
14331 command (often an interactive shell) with the real and effective user
14332 ID, group ID, and supplemental groups of a given @var{user}.  Synopsis:
14334 @example
14335 su [@var{option}]@dots{} [@var{user} [@var{arg}]@dots{}]
14336 @end example
14338 @cindex passwd entry, and @command{su} shell
14339 @flindex /bin/sh
14340 @flindex /etc/passwd
14341 If no @var{user} is given, the default is @code{root}, the super-user.
14342 The shell to use is taken from @var{user}'s @code{passwd} entry, or
14343 @file{/bin/sh} if none is specified there.  If @var{user} has a
14344 password, @command{su} prompts for the password unless run by a user with
14345 effective user ID of zero (the super-user).
14347 @vindex HOME
14348 @vindex SHELL
14349 @vindex USER
14350 @vindex LOGNAME
14351 @cindex login shell
14352 By default, @command{su} does not change the current directory.
14353 It sets the environment variables @env{HOME} and @env{SHELL}
14354 from the password entry for @var{user}, and if @var{user} is not
14355 the super-user, sets @env{USER} and @env{LOGNAME} to @var{user}.
14356 By default, the shell is not a login shell.
14358 Any additional @var{arg}s are passed as additional arguments to the
14359 shell.
14361 @cindex @option{-su}
14362 GNU @command{su} does not treat @file{/bin/sh} or any other shells specially
14363 (e.g., by setting @code{argv[0]} to @option{-su}, passing @option{-c} only
14364 to certain shells, etc.).
14366 @findex syslog
14367 @command{su} can optionally be compiled to use @code{syslog} to report
14368 failed, and optionally successful, @command{su} attempts.  (If the system
14369 supports @code{syslog}.)  However, GNU @command{su} does not check if the
14370 user is a member of the @code{wheel} group; see below.
14372 The program accepts the following options.  Also see @ref{Common options}.
14374 @table @samp
14375 @item -c @var{command}
14376 @itemx --command=@var{command}
14377 @opindex -c
14378 @opindex --command
14379 Pass @var{command}, a single command line to run, to the shell with
14380 a @option{-c} option instead of starting an interactive shell.
14382 @item -f
14383 @itemx --fast
14384 @opindex -f
14385 @opindex --fast
14386 @flindex .cshrc
14387 @cindex file name pattern expansion, disabled
14388 @cindex globbing, disabled
14389 Pass the @option{-f} option to the shell.  This probably only makes sense
14390 if the shell run is @command{csh} or @command{tcsh}, for which the @option{-f}
14391 option prevents reading the startup file (@file{.cshrc}).  With
14392 Bourne-like shells, the @option{-f} option disables file name pattern
14393 expansion (globbing), which is not likely to be useful.
14395 @item -
14396 @itemx -l
14397 @itemx --login
14398 @opindex -
14399 @opindex -l
14400 @opindex --login
14401 @c other variables already indexed above
14402 @vindex TERM
14403 @vindex PATH
14404 @cindex login shell, creating
14405 Make the shell a login shell.  This means the following.  Unset all
14406 environment variables except @env{TERM}, @env{HOME}, and @env{SHELL}
14407 (which are set as described above), and @env{USER} and @env{LOGNAME}
14408 (which are set, even for the super-user, as described above), and set
14409 @env{PATH} to a compiled-in default value.  Change to @var{user}'s home
14410 directory.  Prepend @samp{-} to the shell's name, intended to make it
14411 read its login startup file(s).
14413 @item -m
14414 @itemx -p
14415 @itemx --preserve-environment
14416 @opindex -m
14417 @opindex -p
14418 @opindex --preserve-environment
14419 @cindex environment, preserving
14420 @flindex /etc/shells
14421 @cindex restricted shell
14422 Do not change the environment variables @env{HOME}, @env{USER},
14423 @env{LOGNAME}, or @env{SHELL}.  Run the shell given in the environment
14424 variable @env{SHELL} instead of the shell from @var{user}'s passwd
14425 entry, unless the user running @command{su} is not the super-user and
14426 @var{user}'s shell is restricted.  A @dfn{restricted shell} is one that
14427 is not listed in the file @file{/etc/shells}, or in a compiled-in list
14428 if that file does not exist.  Parts of what this option does can be
14429 overridden by @option{--login} and @option{--shell}.
14431 @item -s @var{shell}
14432 @itemx --shell=@var{shell}
14433 @opindex -s
14434 @opindex --shell
14435 Run @var{shell} instead of the shell from @var{user}'s passwd entry,
14436 unless the user running @command{su} is not the super-user and @var{user}'s
14437 shell is restricted (see @option{-m} just above).
14439 @end table
14441 @cindex exit status of @command{su}
14442 Exit status:
14444 @display
14445 1   if @command{su} itself fails
14446 126 if subshell is found but cannot be invoked
14447 127 if subshell cannot be found
14448 the exit status of the subshell otherwise
14449 @end display
14451 @cindex wheel group, not supported
14452 @cindex group wheel, not supported
14453 @cindex fascism
14454 @subsection Why GNU @command{su} does not support the @samp{wheel} group
14456 (This section is by Richard Stallman.)
14458 @cindex Twenex
14459 @cindex MIT AI lab
14460 Sometimes a few of the users try to hold total power over all the
14461 rest.  For example, in 1984, a few users at the MIT AI lab decided to
14462 seize power by changing the operator password on the Twenex system and
14463 keeping it secret from everyone else.  (I was able to thwart this coup
14464 and give power back to the users by patching the kernel, but I
14465 wouldn't know how to do that in Unix.)
14467 However, occasionally the rulers do tell someone.  Under the usual
14468 @command{su} mechanism, once someone learns the root password who
14469 sympathizes with the ordinary users, he or she can tell the rest.  The
14470 ``wheel group'' feature would make this impossible, and thus cement the
14471 power of the rulers.
14473 I'm on the side of the masses, not that of the rulers.  If you are
14474 used to supporting the bosses and sysadmins in whatever they do, you
14475 might find this idea strange at first.
14478 @node timeout invocation
14479 @section @command{timeout}: Run a command with a time limit
14481 @pindex timeout
14482 @cindex time limit
14483 @cindex run commands with bounded time
14485 @command{timeout} runs the given @var{command} and kills it if it is
14486 still running after the specified time interval.  Synopsis:
14488 @example
14489 timeout [@var{option}] @var{number}[smhd] @var{command} [@var{arg}]@dots{}
14490 @end example
14492 @cindex time units
14493 @var{number} is an integer followed by an optional unit; the default
14494 is seconds.  The units are:
14496 @table @samp
14497 @item s
14498 seconds
14499 @item m
14500 minutes
14501 @item h
14502 hours
14503 @item d
14504 days
14505 @end table
14507 @var{command} must not be a special built-in utility (@pxref{Special
14508 built-in utilities}).
14510 The program accepts the following option.  Also see @ref{Common options}.
14511 Options must precede operands.
14513 @table @samp
14514 @item -s @var{signal}
14515 @itemx --signal=@var{signal}
14516 @opindex -s
14517 @opindex --signal
14518 Send this @var{signal} to @var{command} on timeout, rather than the
14519 default @samp{TERM} signal. @var{signal} may be a name like @samp{HUP}
14520 or a number. Also see @xref{Signal specifications}.
14522 @end table
14524 @cindex exit status of @command{timeout}
14525 Exit status:
14527 @display
14528 124 if @var{command} times out
14529 125 if @command{timeout} itself fails
14530 126 if @var{command} is found but cannot be invoked
14531 127 if @var{command} cannot be found
14532 the exit status of @var{command} otherwise
14533 @end display
14536 @node Process control
14537 @chapter Process control
14539 @cindex processes, commands for controlling
14540 @cindex commands for controlling processes
14542 @menu
14543 * kill invocation::             Sending a signal to processes.
14544 @end menu
14547 @node kill invocation
14548 @section @command{kill}: Send a signal to processes
14550 @pindex kill
14551 @cindex send a signal to processes
14553 The @command{kill} command sends a signal to processes, causing them
14554 to terminate or otherwise act upon receiving the signal in some way.
14555 Alternatively, it lists information about signals.  Synopses:
14557 @example
14558 kill [-s @var{signal} | --signal @var{signal} | -@var{signal}] @var{pid}@dots{}
14559 kill [-l | --list | -t | --table] [@var{signal}]@dots{}
14560 @end example
14562 @mayConflictWithShellBuiltIn{kill}
14564 The first form of the @command{kill} command sends a signal to all
14565 @var{pid} arguments.  The default signal to send if none is specified
14566 is @samp{TERM}.  The special signal number @samp{0} does not denote a
14567 valid signal, but can be used to test whether the @var{pid} arguments
14568 specify processes to which a signal could be sent.
14570 If @var{pid} is positive, the signal is sent to the process with the
14571 process ID @var{pid}.  If @var{pid} is zero, the signal is sent to all
14572 processes in the process group of the current process.  If @var{pid}
14573 is @minus{}1, the signal is sent to all processes for which the user has
14574 permission to send a signal.  If @var{pid} is less than @minus{}1, the signal
14575 is sent to all processes in the process group that equals the absolute
14576 value of @var{pid}.
14578 If @var{pid} is not positive, a system-dependent set of system
14579 processes is excluded from the list of processes to which the signal
14580 is sent.
14582 If a negative @var{pid} argument is desired as the first one, it
14583 should be preceded by @option{--}.  However, as a common extension to
14584 @acronym{POSIX}, @option{--} is not required with @samp{kill
14585 -@var{signal} -@var{pid}}.  The following commands are equivalent:
14587 @example
14588 kill -15 -1
14589 kill -TERM -1
14590 kill -s TERM -- -1
14591 kill -- -1
14592 @end example
14594 The first form of the @command{kill} command succeeds if every @var{pid}
14595 argument specifies at least one process that the signal was sent to.
14597 The second form of the @command{kill} command lists signal information.
14598 Either the @option{-l} or @option{--list} option, or the @option{-t}
14599 or @option{--table} option must be specified.  Without any
14600 @var{signal} argument, all supported signals are listed.  The output
14601 of @option{-l} or @option{--list} is a list of the signal names, one
14602 per line; if @var{signal} is already a name, the signal number is
14603 printed instead.  The output of @option{-t} or @option{--table} is a
14604 table of signal numbers, names, and descriptions.  This form of the
14605 @command{kill} command succeeds if all @var{signal} arguments are valid
14606 and if there is no output error.
14608 The @command{kill} command also supports the @option{--help} and
14609 @option{--version} options.  @xref{Common options}.
14611 A @var{signal} may be a signal name like @samp{HUP}, or a signal
14612 number like @samp{1}, or an exit status of a process terminated by the
14613 signal.  A signal name can be given in canonical form or prefixed by
14614 @samp{SIG}.  The case of the letters is ignored, except for the
14615 @option{-@var{signal}} option which must use upper case to avoid
14616 ambiguity with lower case option letters.  For a list of supported
14617 signal names and numbers see @xref{Signal specifications}.
14619 @node Delaying
14620 @chapter Delaying
14622 @cindex delaying commands
14623 @cindex commands for delaying
14625 @c Perhaps @command{wait} or other commands should be described here also?
14627 @menu
14628 * sleep invocation::            Delay for a specified time.
14629 @end menu
14632 @node sleep invocation
14633 @section @command{sleep}: Delay for a specified time
14635 @pindex sleep
14636 @cindex delay for a specified time
14638 @command{sleep} pauses for an amount of time specified by the sum of
14639 the values of the command line arguments.
14640 Synopsis:
14642 @example
14643 sleep @var{number}[smhd]@dots{}
14644 @end example
14646 @cindex time units
14647 Each argument is a number followed by an optional unit; the default
14648 is seconds.  The units are:
14650 @table @samp
14651 @item s
14652 seconds
14653 @item m
14654 minutes
14655 @item h
14656 hours
14657 @item d
14658 days
14659 @end table
14661 Historical implementations of @command{sleep} have required that
14662 @var{number} be an integer, and only accepted a single argument
14663 without a suffix.  However, GNU @command{sleep} accepts
14664 arbitrary floating point numbers (using a period before any fractional
14665 digits).
14667 The only options are @option{--help} and @option{--version}.  @xref{Common
14668 options}.
14670 @c sleep is a shell built-in at least with Solaris 11's /bin/sh
14671 @mayConflictWithShellBuiltIn{sleep}
14673 @exitstatus
14676 @node Numeric operations
14677 @chapter Numeric operations
14679 @cindex numeric operations
14680 These programs do numerically-related operations.
14682 @menu
14683 * factor invocation::              Show factors of numbers.
14684 * seq invocation::                 Print sequences of numbers.
14685 @end menu
14688 @node factor invocation
14689 @section @command{factor}: Print prime factors
14691 @pindex factor
14692 @cindex prime factors
14694 @command{factor} prints prime factors.  Synopses:
14696 @example
14697 factor [@var{number}]@dots{}
14698 factor @var{option}
14699 @end example
14701 If no @var{number} is specified on the command line, @command{factor} reads
14702 numbers from standard input, delimited by newlines, tabs, or spaces.
14704 The @command{factor} command supports only a small number of options:
14706 @table @samp
14707 @item --help
14708 Print a short help on standard output, then exit without further
14709 processing.
14711 @item --version
14712 Print the program version on standard output, then exit without further
14713 processing.
14714 @end table
14716 Factoring the product of the eighth and ninth Mersenne primes
14717 takes about 30 milliseconds of CPU time on a 2.2 GHz Athlon.
14719 @example
14720 M8=`echo 2^31-1|bc` ; M9=`echo 2^61-1|bc`
14721 /usr/bin/time -f '%U' factor $(echo "$M8 * $M9" | bc)
14722 4951760154835678088235319297: 2147483647 2305843009213693951
14723 0.03
14724 @end example
14726 Similarly, factoring the eighth Fermat number @math{2^{256}+1} takes
14727 about 20 seconds on the same machine.
14729 Factoring large prime numbers is, in general, hard.  The Pollard Rho
14730 algorithm used by @command{factor} is particularly effective for
14731 numbers with relatively small factors.  If you wish to factor large
14732 numbers which do not have small factors (for example, numbers which
14733 are the product of two large primes), other methods are far better.
14735 If @command{factor} is built without using GNU MP, only
14736 single-precision arithmetic is available, and so large numbers
14737 (typically @math{2^{64}} and above) will not be supported.  The single-precision
14738 code uses an algorithm which is designed for factoring smaller
14739 numbers.
14741 @exitstatus
14744 @node seq invocation
14745 @section @command{seq}: Print numeric sequences
14747 @pindex seq
14748 @cindex numeric sequences
14749 @cindex sequence of numbers
14751 @command{seq} prints a sequence of numbers to standard output.  Synopses:
14753 @example
14754 seq [@var{option}]@dots{} @var{last}
14755 seq [@var{option}]@dots{} @var{first} @var{last}
14756 seq [@var{option}]@dots{} @var{first} @var{increment} @var{last}
14757 @end example
14759 @command{seq} prints the numbers from @var{first} to @var{last} by
14760 @var{increment}.  By default, each number is printed on a separate line.
14761 When @var{increment} is not specified, it defaults to @samp{1},
14762 even when @var{first} is larger than @var{last}.
14763 @var{first} also defaults to @samp{1}.  So @code{seq 1} prints
14764 @samp{1}, but @code{seq 0} and @code{seq 10 5} produce no output.
14765 Floating-point numbers
14766 may be specified (using a period before any fractional digits).
14768 The program accepts the following options.  Also see @ref{Common options}.
14769 Options must precede operands.
14771 @table @samp
14772 @item -f @var{format}
14773 @itemx --format=@var{format}
14774 @opindex -f @var{format}
14775 @opindex --format=@var{format}
14776 @cindex formatting of numbers in @command{seq}
14777 Print all numbers using @var{format}.
14778 @var{format} must contain exactly one of the @samp{printf}-style
14779 floating point conversion specifications @samp{%a}, @samp{%e},
14780 @samp{%f}, @samp{%g}, @samp{%A}, @samp{%E}, @samp{%F}, @samp{%G}.
14781 The @samp{%} may be followed by zero or more flags taken from the set
14782 @samp{-+#0 '}, then an optional width containing one or more digits,
14783 then an optional precision consisting of a @samp{.} followed by zero
14784 or more digits.  @var{format} may also contain any number of @samp{%%}
14785 conversion specifications.  All conversion specifications have the
14786 same meaning as with @samp{printf}.
14788 The default format is derived from @var{first}, @var{step}, and
14789 @var{last}.  If these all use a fixed point decimal representation,
14790 the default format is @samp{%.@var{p}f}, where @var{p} is the minimum
14791 precision that can represent the output numbers exactly.  Otherwise,
14792 the default format is @samp{%g}.
14794 @item -s @var{string}
14795 @itemx --separator=@var{string}
14796 @cindex separator for numbers in @command{seq}
14797 Separate numbers with @var{string}; default is a newline.
14798 The output always terminates with a newline.
14800 @item -w
14801 @itemx --equal-width
14802 Print all numbers with the same width, by padding with leading zeros.
14803 @var{first}, @var{step}, and @var{last} should all use a fixed point
14804 decimal representation.
14805 (To have other kinds of padding, use @option{--format}).
14807 @end table
14809 You can get finer-grained control over output with @option{-f}:
14811 @example
14812 $ seq -f '(%9.2E)' -9e5 1.1e6 1.3e6
14813 (-9.00E+05)
14814 ( 2.00E+05)
14815 ( 1.30E+06)
14816 @end example
14818 If you want hexadecimal integer output, you can use @command{printf}
14819 to perform the conversion:
14821 @example
14822 $ printf '%x\n' `seq 1048575 1024 1050623`
14823 fffff
14824 1003ff
14825 1007ff
14826 @end example
14828 For very long lists of numbers, use xargs to avoid
14829 system limitations on the length of an argument list:
14831 @example
14832 $ seq 1000000 | xargs printf '%x\n' | tail -n 3
14833 f423e
14834 f423f
14835 f4240
14836 @end example
14838 To generate octal output, use the printf @code{%o} format instead
14839 of @code{%x}.
14841 On most systems, seq can produce whole-number output for values up to
14842 at least @math{2^{53}}.  Larger integers are approximated.  The details
14843 differ depending on your floating-point implementation, but a common
14844 case is that @command{seq} works with integers through @math{2^{64}},
14845 and larger integers may not be numerically correct:
14847 @example
14848 $ seq 18446744073709551616 1 18446744073709551618
14849 18446744073709551616
14850 18446744073709551616
14851 18446744073709551618
14852 @end example
14854 Be careful when using @command{seq} with outlandish values: otherwise
14855 you may see surprising results, as @command{seq} uses floating point
14856 internally.  For example, on the x86 platform, where the internal
14857 representation uses a 64-bit fraction, the command:
14859 @example
14860 seq 1 0.0000000000000000001 1.0000000000000000009
14861 @end example
14863 outputs 1.0000000000000000007 twice and skips 1.0000000000000000008.
14865 @exitstatus
14868 @node File permissions
14869 @chapter File permissions
14870 @include perm.texi
14872 @include getdate.texi
14874 @c              What's GNU?
14875 @c              Arnold Robbins
14876 @node Opening the software toolbox
14877 @chapter Opening the Software Toolbox
14879 An earlier version of this chapter appeared in
14880 @uref{http://www.linuxjournal.com/article.php?sid=2762, the
14881 @cite{What's GNU?} column of @cite{Linux Journal}, 2 (June, 1994)}.
14882 It was written by Arnold Robbins.
14884 @menu
14885 * Toolbox introduction::        Toolbox introduction
14886 * I/O redirection::             I/O redirection
14887 * The who command::             The @command{who} command
14888 * The cut command::             The @command{cut} command
14889 * The sort command::            The @command{sort} command
14890 * The uniq command::            The @command{uniq} command
14891 * Putting the tools together::  Putting the tools together
14892 @end menu
14895 @node Toolbox introduction
14896 @unnumberedsec Toolbox Introduction
14898 This month's column is only peripherally related to the GNU Project, in
14899 that it describes a number of the GNU tools on your GNU/Linux system and how they
14900 might be used.  What it's really about is the ``Software Tools'' philosophy
14901 of program development and usage.
14903 The software tools philosophy was an important and integral concept
14904 in the initial design and development of Unix (of which Linux and GNU are
14905 essentially clones).  Unfortunately, in the modern day press of
14906 Internetworking and flashy GUIs, it seems to have fallen by the
14907 wayside.  This is a shame, since it provides a powerful mental model
14908 for solving many kinds of problems.
14910 Many people carry a Swiss Army knife around in their pants pockets (or
14911 purse).  A Swiss Army knife is a handy tool to have: it has several knife
14912 blades, a screwdriver, tweezers, toothpick, nail file, corkscrew, and perhaps
14913 a number of other things on it.  For the everyday, small miscellaneous jobs
14914 where you need a simple, general purpose tool, it's just the thing.
14916 On the other hand, an experienced carpenter doesn't build a house using
14917 a Swiss Army knife.  Instead, he has a toolbox chock full of specialized
14918 tools---a saw, a hammer, a screwdriver, a plane, and so on.  And he knows
14919 exactly when and where to use each tool; you won't catch him hammering nails
14920 with the handle of his screwdriver.
14922 The Unix developers at Bell Labs were all professional programmers and trained
14923 computer scientists.  They had found that while a one-size-fits-all program
14924 might appeal to a user because there's only one program to use, in practice
14925 such programs are
14927 @enumerate a
14928 @item
14929 difficult to write,
14931 @item
14932 difficult to maintain and
14933 debug, and
14935 @item
14936 difficult to extend to meet new situations.
14937 @end enumerate
14939 Instead, they felt that programs should be specialized tools.  In short, each
14940 program ``should do one thing well.''  No more and no less.  Such programs are
14941 simpler to design, write, and get right---they only do one thing.
14943 Furthermore, they found that with the right machinery for hooking programs
14944 together, that the whole was greater than the sum of the parts.  By combining
14945 several special purpose programs, you could accomplish a specific task
14946 that none of the programs was designed for, and accomplish it much more
14947 quickly and easily than if you had to write a special purpose program.
14948 We will see some (classic) examples of this further on in the column.
14949 (An important additional point was that, if necessary, take a detour
14950 and build any software tools you may need first, if you don't already
14951 have something appropriate in the toolbox.)
14953 @node I/O redirection
14954 @unnumberedsec I/O Redirection
14956 Hopefully, you are familiar with the basics of I/O redirection in the
14957 shell, in particular the concepts of ``standard input,'' ``standard output,''
14958 and ``standard error''.  Briefly, ``standard input'' is a data source, where
14959 data comes from.  A program should not need to either know or care if the
14960 data source is a disk file, a keyboard, a magnetic tape, or even a punched
14961 card reader.  Similarly, ``standard output'' is a data sink, where data goes
14962 to.  The program should neither know nor care where this might be.
14963 Programs that only read their standard input, do something to the data,
14964 and then send it on, are called @dfn{filters}, by analogy to filters in a
14965 water pipeline.
14967 With the Unix shell, it's very easy to set up data pipelines:
14969 @smallexample
14970 program_to_create_data | filter1 | ... | filterN > final.pretty.data
14971 @end smallexample
14973 We start out by creating the raw data; each filter applies some successive
14974 transformation to the data, until by the time it comes out of the pipeline,
14975 it is in the desired form.
14977 This is fine and good for standard input and standard output.  Where does the
14978 standard error come in to play?  Well, think about @command{filter1} in
14979 the pipeline above.  What happens if it encounters an error in the data it
14980 sees?  If it writes an error message to standard output, it will just
14981 disappear down the pipeline into @command{filter2}'s input, and the
14982 user will probably never see it.  So programs need a place where they can send
14983 error messages so that the user will notice them.  This is standard error,
14984 and it is usually connected to your console or window, even if you have
14985 redirected standard output of your program away from your screen.
14987 For filter programs to work together, the format of the data has to be
14988 agreed upon.  The most straightforward and easiest format to use is simply
14989 lines of text.  Unix data files are generally just streams of bytes, with
14990 lines delimited by the @acronym{ASCII} @sc{lf} (Line Feed) character,
14991 conventionally called a ``newline'' in the Unix literature.  (This is
14992 @code{'\n'} if you're a C programmer.)  This is the format used by all
14993 the traditional filtering programs.  (Many earlier operating systems
14994 had elaborate facilities and special purpose programs for managing
14995 binary data.  Unix has always shied away from such things, under the
14996 philosophy that it's easiest to simply be able to view and edit your
14997 data with a text editor.)
14999 OK, enough introduction.  Let's take a look at some of the tools, and then
15000 we'll see how to hook them together in interesting ways.   In the following
15001 discussion, we will only present those command line options that interest
15002 us.  As you should always do, double check your system documentation
15003 for the full story.
15005 @node The who command
15006 @unnumberedsec The @command{who} Command
15008 The first program is the @command{who} command.  By itself, it generates a
15009 list of the users who are currently logged in.  Although I'm writing
15010 this on a single-user system, we'll pretend that several people are
15011 logged in:
15013 @example
15014 $ who
15015 @print{} arnold   console Jan 22 19:57
15016 @print{} miriam   ttyp0   Jan 23 14:19(:0.0)
15017 @print{} bill     ttyp1   Jan 21 09:32(:0.0)
15018 @print{} arnold   ttyp2   Jan 23 20:48(:0.0)
15019 @end example
15021 Here, the @samp{$} is the usual shell prompt, at which I typed @samp{who}.
15022 There are three people logged in, and I am logged in twice.  On traditional
15023 Unix systems, user names are never more than eight characters long.  This
15024 little bit of trivia will be useful later.  The output of @command{who} is nice,
15025 but the data is not all that exciting.
15027 @node The cut command
15028 @unnumberedsec The @command{cut} Command
15030 The next program we'll look at is the @command{cut} command.  This program
15031 cuts out columns or fields of input data.  For example, we can tell it
15032 to print just the login name and full name from the @file{/etc/passwd}
15033 file.  The @file{/etc/passwd} file has seven fields, separated by
15034 colons:
15036 @example
15037 arnold:xyzzy:2076:10:Arnold D. Robbins:/home/arnold:/bin/bash
15038 @end example
15040 To get the first and fifth fields, we would use @command{cut} like this:
15042 @example
15043 $ cut -d: -f1,5 /etc/passwd
15044 @print{} root:Operator
15045 @dots{}
15046 @print{} arnold:Arnold D. Robbins
15047 @print{} miriam:Miriam A. Robbins
15048 @dots{}
15049 @end example
15051 With the @option{-c} option, @command{cut} will cut out specific characters
15052 (i.e., columns) in the input lines.  This is useful for input data
15053 that has fixed width fields, and does not have a field separator.  For
15054 example, list the Monday dates for the current month:
15056 @c Is using cal ok?  Looked at gcal, but I don't like it.
15057 @example
15058 $ cal | cut -c 3-5
15059 @print{}Mo
15060 @print{}
15061 @print{}  6
15062 @print{} 13
15063 @print{} 20
15064 @print{} 27
15065 @end example
15067 @node The sort command
15068 @unnumberedsec The @command{sort} Command
15070 Next we'll look at the @command{sort} command.  This is one of the most
15071 powerful commands on a Unix-style system; one that you will often find
15072 yourself using when setting up fancy data plumbing.
15074 The @command{sort}
15075 command reads and sorts each file named on the command line.  It then
15076 merges the sorted data and writes it to standard output.  It will read
15077 standard input if no files are given on the command line (thus
15078 making it into a filter).  The sort is based on the character collating
15079 sequence or based on user-supplied ordering criteria.
15082 @node The uniq command
15083 @unnumberedsec The @command{uniq} Command
15085 Finally (at least for now), we'll look at the @command{uniq} program.  When
15086 sorting data, you will often end up with duplicate lines, lines that
15087 are identical.  Usually, all you need is one instance of each line.
15088 This is where @command{uniq} comes in.  The @command{uniq} program reads its
15089 standard input.  It prints only one
15090 copy of each repeated line.  It does have several options.  Later on,
15091 we'll use the @option{-c} option, which prints each unique line, preceded
15092 by a count of the number of times that line occurred in the input.
15095 @node Putting the tools together
15096 @unnumberedsec Putting the Tools Together
15098 Now, let's suppose this is a large ISP server system with dozens of users
15099 logged in.  The management wants the system administrator to write a program that will
15100 generate a sorted list of logged in users.  Furthermore, even if a user
15101 is logged in multiple times, his or her name should only show up in the
15102 output once.
15104 The administrator could sit down with the system documentation and write a C
15105 program that did this.  It would take perhaps a couple of hundred lines
15106 of code and about two hours to write it, test it, and debug it.
15107 However, knowing the software toolbox, the administrator can instead start out
15108 by generating just a list of logged on users:
15110 @example
15111 $ who | cut -c1-8
15112 @print{} arnold
15113 @print{} miriam
15114 @print{} bill
15115 @print{} arnold
15116 @end example
15118 Next, sort the list:
15120 @example
15121 $ who | cut -c1-8 | sort
15122 @print{} arnold
15123 @print{} arnold
15124 @print{} bill
15125 @print{} miriam
15126 @end example
15128 Finally, run the sorted list through @command{uniq}, to weed out duplicates:
15130 @example
15131 $ who | cut -c1-8 | sort | uniq
15132 @print{} arnold
15133 @print{} bill
15134 @print{} miriam
15135 @end example
15137 The @command{sort} command actually has a @option{-u} option that does what
15138 @command{uniq} does.  However, @command{uniq} has other uses for which one
15139 cannot substitute @samp{sort -u}.
15141 The administrator puts this pipeline into a shell script, and makes it available for
15142 all the users on the system (@samp{#} is the system administrator,
15143 or @code{root}, prompt):
15145 @example
15146 # cat > /usr/local/bin/listusers
15147 who | cut -c1-8 | sort | uniq
15149 # chmod +x /usr/local/bin/listusers
15150 @end example
15152 There are four major points to note here.  First, with just four
15153 programs, on one command line, the administrator was able to save about two
15154 hours worth of work.  Furthermore, the shell pipeline is just about as
15155 efficient as the C program would be, and it is much more efficient in
15156 terms of programmer time.  People time is much more expensive than
15157 computer time, and in our modern ``there's never enough time to do
15158 everything'' society, saving two hours of programmer time is no mean
15159 feat.
15161 Second, it is also important to emphasize that with the
15162 @emph{combination} of the tools, it is possible to do a special
15163 purpose job never imagined by the authors of the individual programs.
15165 Third, it is also valuable to build up your pipeline in stages, as we did here.
15166 This allows you to view the data at each stage in the pipeline, which helps
15167 you acquire the confidence that you are indeed using these tools correctly.
15169 Finally, by bundling the pipeline in a shell script, other users can use
15170 your command, without having to remember the fancy plumbing you set up for
15171 them.  In terms of how you run them, shell scripts and compiled programs are
15172 indistinguishable.
15174 After the previous warm-up exercise, we'll look at two additional, more
15175 complicated pipelines.  For them, we need to introduce two more tools.
15177 The first is the @command{tr} command, which stands for ``transliterate.''
15178 The @command{tr} command works on a character-by-character basis, changing
15179 characters.  Normally it is used for things like mapping upper case to
15180 lower case:
15182 @example
15183 $ echo ThIs ExAmPlE HaS MIXED case! | tr '[:upper:]' '[:lower:]'
15184 @print{} this example has mixed case!
15185 @end example
15187 There are several options of interest:
15189 @table @code
15190 @item -c
15191 work on the complement of the listed characters, i.e.,
15192 operations apply to characters not in the given set
15194 @item -d
15195 delete characters in the first set from the output
15197 @item -s
15198 squeeze repeated characters in the output into just one character.
15199 @end table
15201 We will be using all three options in a moment.
15203 The other command we'll look at is @command{comm}.  The @command{comm}
15204 command takes two sorted input files as input data, and prints out the
15205 files' lines in three columns.  The output columns are the data lines
15206 unique to the first file, the data lines unique to the second file, and
15207 the data lines that are common to both.  The @option{-1}, @option{-2}, and
15208 @option{-3} command line options @emph{omit} the respective columns.  (This is
15209 non-intuitive and takes a little getting used to.)  For example:
15211 @example
15212 $ cat f1
15213 @print{} 11111
15214 @print{} 22222
15215 @print{} 33333
15216 @print{} 44444
15217 $ cat f2
15218 @print{} 00000
15219 @print{} 22222
15220 @print{} 33333
15221 @print{} 55555
15222 $ comm f1 f2
15223 @print{}         00000
15224 @print{} 11111
15225 @print{}                 22222
15226 @print{}                 33333
15227 @print{} 44444
15228 @print{}         55555
15229 @end example
15231 The file name @file{-} tells @command{comm} to read standard input
15232 instead of a regular file.
15234 Now we're ready to build a fancy pipeline.  The first application is a word
15235 frequency counter.  This helps an author determine if he or she is over-using
15236 certain words.
15238 The first step is to change the case of all the letters in our input file
15239 to one case.  ``The'' and ``the'' are the same word when doing counting.
15241 @example
15242 $ tr '[:upper:]' '[:lower:]' < whats.gnu | ...
15243 @end example
15245 The next step is to get rid of punctuation.  Quoted words and unquoted words
15246 should be treated identically; it's easiest to just get the punctuation out of
15247 the way.
15249 @smallexample
15250 $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' | ...
15251 @end smallexample
15253 The second @command{tr} command operates on the complement of the listed
15254 characters, which are all the letters, the digits, the underscore, and
15255 the blank.  The @samp{\n} represents the newline character; it has to
15256 be left alone.  (The @acronym{ASCII} tab character should also be included for
15257 good measure in a production script.)
15259 At this point, we have data consisting of words separated by blank space.
15260 The words only contain alphanumeric characters (and the underscore).  The
15261 next step is break the data apart so that we have one word per line.  This
15262 makes the counting operation much easier, as we will see shortly.
15264 @smallexample
15265 $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' |
15266 > tr -s ' ' '\n' | ...
15267 @end smallexample
15269 This command turns blanks into newlines.  The @option{-s} option squeezes
15270 multiple newline characters in the output into just one.  This helps us
15271 avoid blank lines.  (The @samp{>} is the shell's ``secondary prompt.''
15272 This is what the shell prints when it notices you haven't finished
15273 typing in all of a command.)
15275 We now have data consisting of one word per line, no punctuation, all one
15276 case.  We're ready to count each word:
15278 @smallexample
15279 $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' |
15280 > tr -s ' ' '\n' | sort | uniq -c | ...
15281 @end smallexample
15283 At this point, the data might look something like this:
15285 @example
15286      60 a
15287       2 able
15288       6 about
15289       1 above
15290       2 accomplish
15291       1 acquire
15292       1 actually
15293       2 additional
15294 @end example
15296 The output is sorted by word, not by count!  What we want is the most
15297 frequently used words first.  Fortunately, this is easy to accomplish,
15298 with the help of two more @command{sort} options:
15300 @table @code
15301 @item -n
15302 do a numeric sort, not a textual one
15304 @item -r
15305 reverse the order of the sort
15306 @end table
15308 The final pipeline looks like this:
15310 @smallexample
15311 $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' |
15312 > tr -s ' ' '\n' | sort | uniq -c | sort -n -r
15313 @print{}    156 the
15314 @print{}     60 a
15315 @print{}     58 to
15316 @print{}     51 of
15317 @print{}     51 and
15318 @dots{}
15319 @end smallexample
15321 Whew!  That's a lot to digest.  Yet, the same principles apply.  With six
15322 commands, on two lines (really one long one split for convenience), we've
15323 created a program that does something interesting and useful, in much
15324 less time than we could have written a C program to do the same thing.
15326 A minor modification to the above pipeline can give us a simple spelling
15327 checker!  To determine if you've spelled a word correctly, all you have to
15328 do is look it up in a dictionary.  If it is not there, then chances are
15329 that your spelling is incorrect.  So, we need a dictionary.
15330 The conventional location for a dictionary is @file{/usr/dict/words}.
15331 On my GNU/Linux system,@footnote{Redhat Linux 6.1, for the November 2000
15332 revision of this article.}
15333 this is a is a sorted, 45,402 word dictionary.
15335 Now, how to compare our file with the dictionary?  As before, we generate
15336 a sorted list of words, one per line:
15338 @smallexample
15339 $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' |
15340 > tr -s ' ' '\n' | sort -u | ...
15341 @end smallexample
15343 Now, all we need is a list of words that are @emph{not} in the
15344 dictionary.  Here is where the @command{comm} command comes in.
15346 @smallexample
15347 $ tr '[:upper:]' '[:lower:]' < whats.gnu | tr -cd '[:alnum:]_ \n' |
15348 > tr -s ' ' '\n' | sort -u |
15349 > comm -23 - /usr/dict/words
15350 @end smallexample
15352 The @option{-2} and @option{-3} options eliminate lines that are only in the
15353 dictionary (the second file), and lines that are in both files.  Lines
15354 only in the first file (standard input, our stream of words), are
15355 words that are not in the dictionary.  These are likely candidates for
15356 spelling errors.  This pipeline was the first cut at a production
15357 spelling checker on Unix.
15359 There are some other tools that deserve brief mention.
15361 @table @command
15362 @item grep
15363 search files for text that matches a regular expression
15365 @item wc
15366 count lines, words, characters
15368 @item tee
15369 a T-fitting for data pipes, copies data to files and to standard output
15371 @item sed
15372 the stream editor, an advanced tool
15374 @item awk
15375 a data manipulation language, another advanced tool
15376 @end table
15378 The software tools philosophy also espoused the following bit of
15379 advice: ``Let someone else do the hard part.''  This means, take
15380 something that gives you most of what you need, and then massage it the
15381 rest of the way until it's in the form that you want.
15383 To summarize:
15385 @enumerate 1
15386 @item
15387 Each program should do one thing well.  No more, no less.
15389 @item
15390 Combining programs with appropriate plumbing leads to results where
15391 the whole is greater than the sum of the parts.  It also leads to novel
15392 uses of programs that the authors might never have imagined.
15394 @item
15395 Programs should never print extraneous header or trailer data, since these
15396 could get sent on down a pipeline.  (A point we didn't mention earlier.)
15398 @item
15399 Let someone else do the hard part.
15401 @item
15402 Know your toolbox!  Use each program appropriately.  If you don't have an
15403 appropriate tool, build one.
15404 @end enumerate
15406 As of this writing, all the programs we've discussed are available via
15407 anonymous @command{ftp} from: @*
15408 @uref{ftp://gnudist.gnu.org/textutils/textutils-1.22.tar.gz}.  (There may
15409 be more recent versions available now.)
15411 None of what I have presented in this column is new.  The Software Tools
15412 philosophy was first introduced in the book @cite{Software Tools}, by
15413 Brian Kernighan and P.J. Plauger (Addison-Wesley, ISBN 0-201-03669-X).
15414 This book showed how to write and use software tools.  It was written in
15415 1976, using a preprocessor for FORTRAN named @command{ratfor} (RATional
15416 FORtran).  At the time, C was not as ubiquitous as it is now; FORTRAN
15417 was.  The last chapter presented a @command{ratfor} to FORTRAN
15418 processor, written in @command{ratfor}.  @command{ratfor} looks an awful
15419 lot like C; if you know C, you won't have any problem following the
15420 code.
15422 In 1981, the book was updated and made available as @cite{Software Tools
15423 in Pascal} (Addison-Wesley, ISBN 0-201-10342-7).  Both books are
15424 still in print and are well worth
15425 reading if you're a programmer.  They certainly made a major change in
15426 how I view programming.
15428 The programs in both books are available from
15429 @uref{http://cm.bell-labs.com/who/bwk, Brian Kernighan's home page}.
15430 For a number of years, there was an active
15431 Software Tools Users Group, whose members had ported the original
15432 @command{ratfor} programs to essentially every computer system with a
15433 FORTRAN compiler.  The popularity of the group waned in the middle 1980s
15434 as Unix began to spread beyond universities.
15436 With the current proliferation of GNU code and other clones of Unix programs,
15437 these programs now receive little attention; modern C versions are
15438 much more efficient and do more than these programs do.  Nevertheless, as
15439 exposition of good programming style, and evangelism for a still-valuable
15440 philosophy, these books are unparalleled, and I recommend them highly.
15442 Acknowledgment: I would like to express my gratitude to Brian Kernighan
15443 of Bell Labs, the original Software Toolsmith, for reviewing this column.
15445 @node GNU Free Documentation License
15446 @appendix GNU Free Documentation License
15448 @include fdl.texi
15450 @node Concept index
15451 @unnumbered Index
15453 @printindex cp
15455 @bye
15457 @c Local variables:
15458 @c texinfo-column-for-description: 32
15459 @c End: