[Top] [Contents] [Index] [ ? ]

GNU Core-utils

@insertcopying

1. Introduction  Caveats, overview, and authors.
2. Common options  
3. Output of entire files  cat tac nl od
4. Formatting file contents  fmt pr fold
5. Output of parts of files  head tail split csplit
6. Summarizing files  wc sum cksum md5sum
7. Operating on sorted files  sort uniq comm ptx tsort
8. Operating on fields within a line  cut paste join
9. Operating on characters  tr expand unexpand
10. Directory listing  ls dir vdir d v dircolors
11. Basic operations  cp dd install mv rm shred
12. Special file types  ln mkdir rmdir mkfifo mknod
13. Changing file attributes  chgrp chmod chown touch
14. Disk usage  df du stat sync
15. Printing text  echo printf yes
16. Conditions  false true test expr
17. Redirection  tee
18. File name manipulation  dirname basename pathchk
19. Working context  pwd stty printenv tty
20. User information  id logname whoami groups users who
21. System context  date uname hostname
22. Modified command invocation  chroot env nice nohup su
23. Process control  kill
24. Delaying  sleep
25. Numeric operations  factor seq
26. File permissions  Access modes.
27. Date input formats  Specifying date strings.
28. Opening the Software Toolbox  The software tools philosophy.
A. GNU Free Documentation License  The license for this documentation.
Index  General index.

 -- The Detailed Node Listing ---

Common Options

2.1 Backup options  
2.2 Block size  
2.3 Target directory  
2.4 Trailing slashes  
2.5 Standards conformance  

Output of entire files

3.1 cat: Concatenate and write files  Concatenate and write files.
3.2 tac: Concatenate and write files in reverse  Concatenate and write files in reverse.
3.3 nl: Number lines and write files  Number lines and write files.
3.4 od: Write files in octal or other formats  Write files in octal or other formats.

Formatting file contents

4.1 fmt: Reformat paragraph text  Reformat paragraph text.
4.2 pr: Paginate or columnate files for printing  Paginate or columnate files for printing.
4.3 fold: Wrap input lines to fit in specified width  Wrap input lines to fit in specified width.

Output of parts of files

5.1 head: Output the first part of files  Output the first part of files.
5.2 tail: Output the last part of files  Output the last part of files.
5.3 split: Split a file into fixed-size pieces  Split a file into fixed-size pieces.
5.4 csplit: Split a file into context-determined pieces  Split a file into context-determined pieces.

Summarizing files

6.1 wc: Print byte, word, and line counts  Print byte, word, and line counts.
6.2 sum: Print checksum and block counts  Print checksum and block counts.
6.3 cksum: Print CRC checksum and byte counts  Print CRC checksum and byte counts.
6.4 md5sum: Print or check message-digests  Print or check message-digests.

Operating on sorted files

7.1 sort: Sort text files  Sort text files.
7.2 uniq: Uniquify files  Uniquify files.
7.3 comm: Compare two sorted files line by line  Compare two sorted files line by line.
7.6 ptx: Produce permuted indexes  Produce a permuted index of file contents.
7.4 tsort: Topological sort  Topological sort.

ptx: Produce permuted indexes

7.6.1 General options  Options which affect general program behavior.
7.6.2 Charset selection  Underlying character set considerations.
7.6.3 Word selection and input processing  Input fields, contexts, and keyword selection.
7.6.4 Output formatting  Types of output format, and sizing the fields.
7.6.5 The GNU extensions to ptx  

Operating on fields within a line

8.1 cut: Print selected parts of lines  Print selected parts of lines.
8.2 paste: Merge lines of files  Merge lines of files.
8.3 join: Join lines on a common field  Join lines on a common field.

Operating on characters

9.1 tr: Translate, squeeze, and/or delete characters  Translate, squeeze, and/or delete characters.
9.2 expand: Convert tabs to spaces  Convert tabs to spaces.
9.3 unexpand: Convert spaces to tabs  Convert spaces to tabs.

tr: Translate, squeeze, and/or delete characters

9.1.1 Specifying sets of characters  
9.1.2 Translating  Changing one characters to another.
9.1.3 Squeezing repeats and deleting  
9.1.4 Warning messages  

Directory listing

10.1 ls: List directory contents  List directory contents
10.2 dir: Briefly list directory contents  Briefly list directory contents
10.3 vdir: Verbosely list directory contents  Verbosely list directory contents
10.4 dircolors: Color setup for ls  Color setup for ls

ls:  List directory contents

10.1.1 Which files are listed  
10.1.2 What information is listed  
10.1.3 Sorting the output  
10.1.4 More details about version sort  
10.1.5 General output formatting  
10.1.7 Formatting the file names  

Basic operations

11.1 cp: Copy files and directories  Copy files and directories
11.2 dd: Convert and copy a file  Convert and copy a file
11.3 install: Copy files and set attributes  Copy files and set attributes
11.4 mv: Move (rename) files  Move (rename) files
11.5 rm: Remove files or directories  Remove files or directories
11.6 shred: Remove files more securely  Remove files more securely

Special file types

12.1 link: Make a hard link via the link syscall  Make a hard link via the link syscall
12.2 ln: Make links between files  Make links between files
12.3 mkdir: Make directories  Make directories
12.4 mkfifo: Make FIFOs (named pipes)  Make FIFOs (named pipes)
12.5 mknod: Make block or character special files  Make block or character special files
12.6 rmdir: Remove empty directories  Remove empty directories
12.7 unlink: Remove files via the unlink syscall  Remove files via unlink syscall

Changing file attributes

13.1 chown: Change file owner and group  Change file owner and group
13.2 chgrp: Change group ownership  Change group ownership
13.3 chmod: Change access permissions  Change access permissions
13.4 touch: Change file timestamps  Change file timestamps

Disk usage

14.1 df: Report filesystem disk space usage  Report filesystem disk space usage
14.2 du: Estimate file space usage  Estimate file space usage
14.3 stat: Report file or filesystem status  Report file or filesystem status
14.4 sync: Synchronize data on disk with memory  Synchronize data on disk with memory

Printing text

15.1 echo: Print a line of text  Print a line of text
15.2 printf: Format and print data  Format and print data
15.3 yes: Print a string until interrupted  Print a string until interrupted

Conditions

16.1 false: Do nothing, unsuccessfully  Do nothing, unsuccessfully
16.2 true: Do nothing, successfully  Do nothing, successfully
16.3 test: Check file types and compare values  Check file types and compare values
16.4 expr: Evaluate expressions  Evaluate expressions

test: Check file types and compare values

16.3.1 File type tests  
16.3.2 Access permission tests  
16.3.3 File characteristic tests  
16.3.4 String tests  
16.3.5 Numeric tests  

expr: Evaluate expression

16.4.1 String expressions  + : match substr index length
16.4.2 Numeric expressions  + - * / %
16.4.3 Relations for expr  | & < <= = == != >= >
16.4.4 Examples of using expr  

Redirection

17.1 tee: Redirect output to multiple files  Redirect output to multiple files

File name manipulation

18.1 basename: Strip directory and suffix from a file name  Strip directory and suffix from a file name
18.2 dirname: Strip non-directory suffix from a file name  Strip non-directory suffix from a file name
18.3 pathchk: Check file name portability  Check file name portability

Working context

19.1 pwd: Print working directory  Print working directory
19.2 stty: Print or change terminal characteristics  Print or change terminal characteristics
19.3 printenv: Print all or some environment variables  Print all or some environment variables
19.4 tty: Print file name of terminal on standard input  Print file name of terminal on standard input

stty: Print or change terminal characteristics

19.2.1 Control settings  
19.2.2 Input settings  
19.2.3 Output settings  
19.2.4 Local settings  
19.2.5 Combination settings  
19.2.6 Special characters  
19.2.7 Special settings  

User information

20.1 id: Print real and effective uid and gid  Print real and effective uid and gid
20.2 logname: Print current login name  Print current login name
20.3 whoami: Print effective user id  Print effective user id
20.4 groups: Print group names a user is in  Print group names a user is in
20.5 users: Print login names of users currently logged in  Print login names of users currently logged in
20.6 who: Print who is currently logged in  Print who is currently logged in

System context

21.1 date: Print or set system date and time  Print or set system date and time
21.2 uname: Print system information  Print system information
21.3 hostname: Print or set system name  Print or set system name
21.4 hostid: Print numeric host identifier.  Print numeric host identifier.

date: Print or set system date and time

21.1.1 Time directives  
21.1.2 Date directives  
21.1.3 Literal directives  
21.1.4 Padding  
21.1.5 Setting the time  
21.1.6 Options for date  
21.1.7 Examples of date  

Modified command invocation

22.1 chroot: Run a command with a different root directory  Run a command with a different root directory
22.2 env: Run a command in a modified environment  Run a command in a modified environment
22.3 nice: Run a command with modified scheduling priority  Run a command with modified scheduling priority
22.4 nohup: Run a command immune to hangups  Run a command immune to hangups
22.5 su: Run a command with substitute user and group id  Run a command with substitute user and group id

Process control

23.1 kill: Send a signal to processes  Sending a signal to processes.

Delaying

24.1 sleep: Delay for a specified time  Delay for a specified time

Numeric operations

25.1 factor: Print prime factors  Print prime factors
25.2 seq: Print numeric sequences  Print numeric sequences

File permissions

26.1 Structure of File Permissions  
26.2 Symbolic Modes  Mnemonic permissions representation
26.3 Numeric Modes  Permissions as octal numbers

Date input formats

27.1 General date syntax  
27.2 Calendar date items  
27.3 Time of day items  
27.4 Time zone items  
27.5 Day of week items  
27.6 Relative items in date strings  
27.7 Pure numbers in date strings  
27.8 Authors of getdate  

Opening the software toolbox

Toolbox Introduction  Toolbox introduction
I/O Redirection  I/O redirection
The who Command  The who command
The cut Command  The cut command
The sort Command  The sort command
The uniq Command  The uniq command
Putting the Tools Together  Putting the tools together

GNU Free Documentation License

ADDENDUM: How to use this License for your documents  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Introduction

This manual is a work in progress: many sections make no attempt to explain basic concepts in a way suitable for novices. Thus, if you are interested, please get involved in improving this manual. The entire GNU community will benefit.

The GNU utilities documented here are mostly compatible with the POSIX standard. Please report bugs to bug-coreutils@gnu.org. Remember to include the version number, machine architecture, input files, and any other information needed to reproduce the bug: your input, what you expected, what you got, and why it is wrong. Diffs are welcome, but please include a description of the problem as well, since this is sometimes difficult to infer. See section `Bugs' in Using and Porting GNU CC.

This manual was originally derived from the Unix man pages in the distributions, which were written by David MacKenzie and updated by Jim Meyering. What you are reading now is the authoritative documentation for these utilities; the man pages are no longer being maintained. The original fmt man page was written by Ross Paterson. François Pinard did the initial conversion to Texinfo format. Karl Berry did the indexing, some reorganization, and editing of the results. Brian Youmans of the Free Software Foundation office staff combined the manuals for textutils, fileutils, and sh-utils to produce the present omnibus manual. Richard Stallman contributed his usual invaluable insights to the overall process.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. Common options

Certain options are available in all of these programs. Rather than writing identical descriptions for each of the programs, they are described here. (In fact, every GNU program accepts (or should accept) these options.)

Normally options and operands can appear in any order, and programs act as if all the options appear before any operands. For example, `sort -r passwd -t :' acts like `sort -r -t : passwd', since `:' is an option-argument of `-t'. However, if the POSIXLY_CORRECT environment variable is set, options must appear before operands, unless otherwise specified for a particular command.

Some of these programs recognize the `--help' and `--version' options only when one of them is the sole command line argument.

`--help'
Print a usage message listing all available options, then exit successfully.

`--version'
Print the version number, then exit successfully.

`--'
Delimit the option list. Later arguments, if any, are treated as operands even if they begin with `-'. For example, `sort -- -r' reads from the file named `-r'.

A single `-' is not really an option, though it looks like one. It stands for standard input, or for standard output if that is clear from the context, and it can be used either as an operand or as an option-argument. For example, `sort -o - -' outputs to standard output and reads from standard input, and is equivalent to plain `sort'. Unless otherwise specified, `-' can appear in any context that requires a file name.

2.1 Backup options  -b -S -V, in some programs.
2.2 Block size  BLOCK_SIZE and --block-size, in some programs.
2.3 Target directory  --target-directory, in some programs.
2.4 Trailing slashes  --strip-trailing-slashes, in some programs.
2.5 Standards conformance  Conformance to the POSIX standard.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 Backup options

Some GNU programs (at least cp, install, ln, and mv) optionally make backups of files before writing new versions. These options control the details of these backups. The options are also briefly mentioned in the descriptions of the particular programs.

`-b'
`--backup[=method]'
Make a backup of each file that would otherwise be overwritten or removed. Without this option, the original versions are destroyed. Use method to determine the type of backups to make. When this option is used but method is not specified, then the value of the VERSION_CONTROL environment variable is used. And if VERSION_CONTROL is not set, the default backup type is `existing'.

Note that the short form of this option, `-b' does not accept any argument. Using `-b' is equivalent to using `--backup=existing'.

This option corresponds to the Emacs variable `version-control'; the values for method are the same as those used in Emacs. This option also accepts more descriptive names. The valid methods are (unique abbreviations are accepted):

`none'
`off'
Never make backups.

`numbered'
`t'
Always make numbered backups.

`existing'
`nil'
Make numbered backups of files that already have them, simple backups of the others.

`simple'
`never'
Always make simple backups. Please note `never' is not to be confused with `none'.

`-S suffix'
`--suffix=suffix'
Append suffix to each backup file made with `-b'. If this option is not specified, the value of the SIMPLE_BACKUP_SUFFIX environment variable is used. And if SIMPLE_BACKUP_SUFFIX is not set, the default is `~', just as in Emacs.

`--version-control=method'
This option is obsolete and will be removed in a future release. It has been replaced with --backup.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 Block size

Some GNU programs (at least df, du, and ls) display sizes in "blocks". You can adjust the block size and method of display to make sizes easier to read. The block size used for display is independent of any filesystem block size. Fractional block counts are rounded up to the nearest integer.

The default block size is chosen by examining the following environment variables in turn; the first one that is set determines the block size.

DF_BLOCK_SIZE
This specifies the default block size for the df command. Similarly, DU_BLOCK_SIZE specifies the default for du and LS_BLOCK_SIZE for ls.

BLOCK_SIZE
This specifies the default block size for all three commands, if the above command-specific environment variables are not set.

POSIXLY_CORRECT
If neither the command_BLOCK_SIZE nor the BLOCK_SIZE variables are set, but this variable is set, the block size defaults to 512.

If none of the above environment variables are set, the block size currently defaults to 1024 bytes in most contexts, but this number may change in the future. For ls file sizes, the block size defaults to 1 byte.

A block size specification can be a positive integer specifying the number of bytes per block, or it can be human-readable or si to select a human-readable format. Integers may be followed by suffixes that are upward compatible with the SI prefixes for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.

With human-readable formats, output sizes are followed by a size letter such as `M' for megabytes. BLOCK_SIZE=human-readable uses powers of 1024; `M' stands for 1,048,576 bytes. BLOCK_SIZE=si is similar, but uses powers of 1000 and appends `B'; `MB' stands for 1,000,000 bytes.

A block size specification preceded by `'' causes output sizes to be displayed with thousands separators. The LC_NUMERIC locale specifies the thousands separator and grouping. For example, in an American English locale, `--block-size="'1kB"' would cause a size of 1234000 bytes to be displayed as `1,234'. In the default C locale, there is no thousands separator so a leading `'' has no effect.

An integer block size can be followed by a suffix to specify a multiple of that size. A bare size letter, or one followed by `iB', specifies a multiple using powers of 1024. A size letter followed by `B' specifies powers of 1000 instead. For example, `1M' and `1MiB' are equivalent to `1048576', whereas `1MB' is equivalent to `1000000'.

A plain suffix without a preceding integer acts as if `1' were prepended, except that it causes a size indication to be appended to the output. For example, `--block-size="kB"' displays 3000 as `3kB'.

The following suffixes are defined. Large sizes like 1Y may be rejected by your computer due to limitations of its arithmetic.

`kB'
kilobyte: 10^3 = 1000.
`k'
`K'
`KiB'
kibibyte: 2^10 = 1024. `K' is special: the SI prefix is `k' and the IEC 60027-2 prefix is `Ki', but tradition and POSIX use `k' to mean `KiB'.
`MB'
megabyte: 10^6 = 1,000,000.
`M'
`MiB'
mebibyte: 2^20 = 1,048,576.
`GB'
gigabyte: 10^9 = 1,000,000,000.
`G'
`GiB'
gibibyte: 2^30 = 1,073,741,824.
`TB'
terabyte: 10^12 = 1,000,000,000,000.
`T'
`TiB'
tebibyte: 2^40 = 1,099,511,627,776.
`PB'
petabyte: 10^15 = 1,000,000,000,000,000.
`P'
`PiB'
pebibyte: 2^50 = 1,125,899,906,842,624.
`EB'
exabyte: 10^18 = 1,000,000,000,000,000,000.
`E'
`EiB'
exbibyte: 2^60 = 1,152,921,504,606,846,976.
`ZB'
zettabyte: 10^21 = 1,000,000,000,000,000,000,000
`Z'
`ZiB'
2^70 = 1,180,591,620,717,411,303,424. (`Zi' is a GNU extension to IEC 60027-2.)
`YB'
yottabyte: 10^24 = 1,000,000,000,000,000,000,000,000.
`Y'
`YiB'
2^80 = 1,208,925,819,614,629,174,706,176. (`Yi' is a GNU extension to IEC 60027-2.)

Block size defaults can be overridden by an explicit `--block-size=size' option. The `-k' option is equivalent to `--block-size=1K', which is the default unless the POSIXLY_CORRECT environment variable is set. The `-h' or `--human-readable' option is equivalent to `--block-size=human-readable'. The `--si' option is equivalent to `--block-size=si'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3 Target directory

Some GNU programs (at least cp, install, ln, and mv) allow you to specify the target directory via this option:

`--target-directory=directory'
Specify the destination directory.

The interface for most programs is that after processing options and a finite (possibly zero) number of fixed-position arguments, the remaining argument list is either expected to be empty, or is a list of items (usually files) that will all be handled identically. The xargs program is designed to work well with this convention.

The commands in the mv-family are unusual in that they take a variable number of arguments with a special case at the end (namely, the target directory). This makes it nontrivial to perform some operations, e.g., "move all files from here to ../d/", because mv * ../d/ might exhaust the argument space, and ls | xargs ... doesn't have a clean way to specify an extra final argument for each invocation of the subject command. (It can be done by going through a shell command, but that requires more human labor and brain power than it should.)

The --target-directory option allows the cp, install, ln, and mv programs to be used conveniently with xargs. For example, you can move the files from the current directory to a sibling directory, d like this: (However, this doesn't move files whose names begin with `.'.)

 
ls |xargs mv --target-directory=../d

If you use the GNU find program, you can move all files with this command:
 
find . -mindepth 1 -maxdepth 1 \
  | xargs mv --target-directory=../d

But that will fail if there are no files in the current directory or if any file has a name containing a newline character. The following example removes those limitations and requires both GNU find and GNU xargs:
 
find . -mindepth 1 -maxdepth 1 -print0 \
  | xargs --null --no-run-if-empty \
      mv --target-directory=../d


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4 Trailing slashes

Some GNU programs (at least cp and mv) allow you to remove any trailing slashes from each source argument before operating on it. The --strip-trailing-slashes option enables this behavior.

This is useful when a source argument may have a trailing slash and specify a symbolic link to a directory. This scenario is in fact rather common because some shells can automatically append a trailing slash when performing file name completion on such symbolic links. Without this option, mv, for example, (via the system's rename function) must interpret a trailing slash as a request to dereference the symbolic link and so must rename the indirectly referenced directory and not the symbolic link. Although it may seem surprising that such behavior be the default, it is required by POSIX and is consistent with other parts of that standard.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.5 Standards conformance

In a few cases, the GNU utilities' default behavior is incompatible with the POSIX standard. To suppress these incompatibilities, define the POSIXLY_CORRECT environment variable. Unless you are checking for POSIX conformance, you probably do not need to define POSIXLY_CORRECT.

Newer versions of POSIX are occasionally incompatible with older versions. For example, older versions of POSIX required the command `sort +1' to sort based on the second and succeeding fields in each input line, but starting with POSIX 1003.1-2001 the same command is required to sort the file named `+1', and you must instead use the command `sort -k 2' to get the field-based sort.

The GNU utilities normally conform to the version of POSIX that is standard for your system. To cause them to conform to a different version of POSIX, define the _POSIX2_VERSION environment variable to a value of the form yyyymm specifying the year and month the standard was adopted. Two values are currently supported for _POSIX2_VERSION: `199209' stands for POSIX 1003.2-1992, and `200112' stands for POSIX 1003.1-2001. For example, if you are running older software that assumes an older version of POSIX and uses `sort +1', you can work around the compatibility problems by setting `_POSIX2_VERSION=199209' in your environment.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Output of entire files

These commands read and write entire files, possibly transforming them in some way.

3.1 cat: Concatenate and write files  Concatenate and write files.
3.2 tac: Concatenate and write files in reverse  Concatenate and write files in reverse.
3.3 nl: Number lines and write files  Number lines and write files.
3.4 od: Write files in octal or other formats  Write files in octal or other formats.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 cat: Concatenate and write files

cat copies each file (`-' means standard input), or standard input if none are given, to standard output. Synopsis:

 
cat [option] [file]...

The program accepts the following options. Also see 2. Common options.

`-A'
`--show-all'
Equivalent to `-vET'.

`-B'
`--binary'
On MS-DOS and MS-Windows only, read and write the files in binary mode. By default, cat on MS-DOS/MS-Windows uses binary mode only when standard output is redirected to a file or a pipe; this option overrides that. Binary file I/O is used so that the files retain their format (Unix text as opposed to DOS text and binary), because cat is frequently used as a file-copying program. Some options (see below) cause cat to read and write files in text mode because in those cases the original file contents aren't important (e.g., when lines are numbered by cat, or when line endings should be marked). This is so these options work as DOS/Windows users would expect; for example, DOS-style text files have their lines end with the CR-LF pair of characters, which won't be processed as an empty line by `-b' unless the file is read in text mode.

`-b'
`--number-nonblank'
Number all nonblank output lines, starting with 1. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-e'
Equivalent to `-vE'.

`-E'
`--show-ends'
Display a `$' after the end of each line. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-n'
`--number'
Number all output lines, starting with 1. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-s'
`--squeeze-blank'
Replace multiple adjacent blank lines with a single blank line. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-t'
Equivalent to `-vT'.

`-T'
`--show-tabs'
Display TAB characters as `^I'.

`-u'
Ignored; for Unix compatibility.

`-v'
`--show-nonprinting'
Display control characters except for LFD and TAB using `^' notation and precede characters that have the high bit set with `M-'. On MS-DOS and MS-Windows, this option causes cat to read files and standard input in DOS binary mode, so the CR characters at the end of each line are also visible.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 tac: Concatenate and write files in reverse

tac copies each file (`-' means standard input), or standard input if none are given, to standard output, reversing the records (lines by default) in each separately. Synopsis:

 
tac [option]... [file]...

Records are separated by instances of a string (newline by default). By default, this separator string is attached to the end of the record that it follows in the file.

The program accepts the following options. Also see 2. Common options.

`-b'
`--before'
The separator is attached to the beginning of the record that it precedes in the file.

`-r'
`--regex'
Treat the separator string as a regular expression. Users of tac on MS-DOS/MS-Windows should note that, since tac reads files in binary mode, each line of a text file might end with a CR/LF pair instead of the Unix-style LF.

`-s separator'
`--separator=separator'
Use separator as the record separator, instead of newline.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 nl: Number lines and write files

nl writes each file (`-' means standard input), or standard input if none are given, to standard output, with line numbers added to some or all of the lines. Synopsis:

 
nl [option]... [file]...

nl decomposes its input into (logical) pages; by default, the line number is reset to 1 at the top of each logical page. nl treats all of the input files as a single document; it does not reset line numbers or logical pages between files.

A logical page consists of three sections: header, body, and footer. Any of the sections can be empty. Each can be numbered in a different style from the others.

The beginnings of the sections of logical pages are indicated in the input file by a line containing exactly one of these delimiter strings:

`\:\:\:'
start of header;
`\:\:'
start of body;
`\:'
start of footer.

The two characters from which these strings are made can be changed from `\' and `:' via options (see below), but the pattern and length of each string cannot be changed.

A section delimiter is replaced by an empty line on output. Any text that comes before the first section delimiter string in the input file is considered to be part of a body section, so nl treats a file that contains no section delimiters as a single body section.

The program accepts the following options. Also see 2. Common options.

`-b style'
`--body-numbering=style'
Select the numbering style for lines in the body section of each logical page. When a line is not numbered, the current line number is not incremented, but the line number separator character is still prepended to the line. The styles are:

`a'
number all lines,
`t'
number only nonempty lines (default for body),
`n'
do not number lines (default for header and footer),
`pregexp'
number only lines that contain a match for regexp.

`-d cd'
`--section-delimiter=cd'
Set the section delimiter characters to cd; default is `\:'. If only c is given, the second remains `:'. (Remember to protect `\' or other metacharacters from shell expansion with quotes or extra backslashes.)

`-f style'
`--footer-numbering=style'
Analogous to `--body-numbering'.

`-h style'
`--header-numbering=style'
Analogous to `--body-numbering'.

`-i number'
`--page-increment=number'
Increment line numbers by number (default 1).

`-l number'
`--join-blank-lines=number'
Consider number (default 1) consecutive empty lines to be one logical line for numbering, and only number the last one. Where fewer than number consecutive empty lines occur, do not number them. An empty line is one that contains no characters, not even spaces or tabs.

`-n format'
`--number-format=format'
Select the line numbering format (default is rn):

`ln'
left justified, no leading zeros;
`rn'
right justified, no leading zeros;
`rz'
right justified, leading zeros.

`-p'
`--no-renumber'
Do not reset the line number at the start of a logical page.

`-s string'
`--number-separator=string'
Separate the line number from the text line in the output with string (default is the TAB character).

`-v number'
`--starting-line-number=number'
Set the initial line number on each logical page to number (default 1).

`-w number'
`--number-width=number'
Use number characters for line numbers (default 6).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 od: Write files in octal or other formats

od writes an unambiguous representation of each file (`-' means standard input), or standard input if none are given. Synopses:

 
od [option]... [file]...
od --traditional [file] [[+]offset [[+]label]]

Each line of output consists of the offset in the input, followed by groups of data from the file. By default, od prints the offset in octal, and each group of file data is two bytes of input printed as a single octal number.

The program accepts the following options. Also see 2. Common options.

`-A radix'
`--address-radix=radix'
Select the base in which file offsets are printed. radix can be one of the following:

`d'
decimal;
`o'
octal;
`x'
hexadecimal;
`n'
none (do not print offsets).

The default is octal.

`-j bytes'
`--skip-bytes=bytes'
Skip bytes input bytes before formatting and writing. If bytes begins with `0x' or `0X', it is interpreted in hexadecimal; otherwise, if it begins with `0', in octal; otherwise, in decimal. Appending `b' multiplies bytes by 512, `k' by 1024, and `m' by 1048576.

`-N bytes'
`--read-bytes=bytes'
Output at most bytes bytes of the input. Prefixes and suffixes on bytes are interpreted as for the `-j' option.

`-s n'
`--strings[=n]'
Instead of the normal output, output only string constants: at least n consecutive ASCII graphic characters, followed by a null (zero) byte.

If n is omitted with `--strings', the default is 3. On older systems, GNU od instead supports an obsolete option `-s[n]', where n also defaults to 3. POSIX 1003.1-2001 (see section 2.5 Standards conformance) does not allow `-s' without an argument; use `--strings' instead.

`-t type'
`--format=type'
Select the format in which to output the file data. type is a string of one or more of the below type indicator characters. If you include more than one type indicator character in a single type string, or use this option more than once, od writes one copy of each output line using each of the data types that you specified, in the order that you specified.

Adding a trailing "z" to any type specification appends a display of the ASCII character representation of the printable characters to the output line generated by the type specification.

`a'
named character
`c'
ASCII character or backslash escape,
`d'
signed decimal
`f'
floating point
`o'
octal
`u'
unsigned decimal
`x'
hexadecimal

The type a outputs things like `sp' for space, `nl' for newline, and `nul' for a null (zero) byte. Type c outputs ` ', `\n', and \0, respectively.

Except for types `a' and `c', you can specify the number of bytes to use in interpreting each number in the given data type by following the type indicator character with a decimal integer. Alternately, you can specify the size of one of the C compiler's built-in data types by following the type indicator character with one of the following characters. For integers (`d', `o', `u', `x'):

`C'
char
`S'
short
`I'
int
`L'
long

For floating point (f):

F
float
D
double
L
long double

`-v'
`--output-duplicates'
Output consecutive lines that are identical. By default, when two or more consecutive output lines would be identical, od outputs only the first line, and puts just an asterisk on the following line to indicate the elision.

`-w n'
`--width[=n]'
Dump n input bytes per output line. This must be a multiple of the least common multiple of the sizes associated with the specified output types.

If this option is not given at all, the default is 16. If n is omitted with `--width', the default is 32. On older systems, GNU od instead supports an obsolete option `-w[n]', where n also defaults to 32. POSIX 1003.1-2001 (see section 2.5 Standards conformance) does not allow `-w' without an argument; use `--width' instead.

The next several options are shorthands for format specifications. GNU od accepts any combination of shorthands and format specification options. These options accumulate.

`-a'
Output as named characters. Equivalent to `-ta'.

`-b'
Output as octal bytes. Equivalent to `-toC'.

`-c'
Output as ASCII characters or backslash escapes. Equivalent to `-tc'.

`-d'
Output as unsigned decimal shorts. Equivalent to `-tu2'.

`-f'
Output as floats. Equivalent to `-tfF'.

`-h'
Output as hexadecimal shorts. Equivalent to `-tx2'.

`-i'
Output as decimal shorts. Equivalent to `-td2'.

`-l'
Output as decimal longs. Equivalent to `-td4'.

`-o'
Output as octal shorts. Equivalent to `-to2'.

`-x'
Output as hexadecimal shorts. Equivalent to `-tx2'.

`--traditional'
Recognize the non-option arguments that traditional od accepted. The following syntax:

 
od --traditional [file] [[+]offset[.][b] [[+]label[.][b]]]

can be used to specify at most one file and optional arguments specifying an offset and a pseudo-start address, label. By default, offset is interpreted as an octal number specifying how many input bytes to skip before formatting and writing. The optional trailing decimal point forces the interpretation of offset as a decimal number. If no decimal is specified and the offset begins with `0x' or `0X' it is interpreted as a hexadecimal number. If there is a trailing `b', the number of bytes skipped will be offset multiplied by 512. The label argument is interpreted just like offset, but it specifies an initial pseudo-address. The pseudo-addresses are displayed in parentheses following any normal address.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Formatting file contents

These commands reformat the contents of files.

4.1 fmt: Reformat paragraph text  Reformat paragraph text.
4.2 pr: Paginate or columnate files for printing  Paginate or columnate files for printing.
4.3 fold: Wrap input lines to fit in specified width  Wrap input lines to fit in specified width.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 fmt: Reformat paragraph text

fmt fills and joins lines to produce output lines of (at most) a given number of characters (75 by default). Synopsis:

 
fmt [option]... [file]...

fmt reads from the specified file arguments (or standard input if none are given), and writes to standard output.

By default, blank lines, spaces between words, and indentation are preserved in the output; successive input lines with different indentation are not joined; tabs are expanded on input and introduced on output.

fmt prefers breaking lines at the end of a sentence, and tries to avoid line breaks after the first word of a sentence or before the last word of a sentence. A sentence break is defined as either the end of a paragraph or a word ending in any of `.?!', followed by two spaces or end of line, ignoring any intervening parentheses or quotes. Like TeX, fmt reads entire "paragraphs" before choosing line breaks; the algorithm is a variant of that in "Breaking Paragraphs Into Lines" (Donald E. Knuth and Michael F. Plass, Software--Practice and Experience, 11 (1981), 1119--1184).

The program accepts the following options. Also see 2. Common options.

`-c'
`--crown-margin'
Crown margin mode: preserve the indentation of the first two lines within a paragraph, and align the left margin of each subsequent line with that of the second line.

`-t'
`--tagged-paragraph'
Tagged paragraph mode: like crown margin mode, except that if indentation of the first line of a paragraph is the same as the indentation of the second, the first line is treated as a one-line paragraph.

`-s'
`--split-only'
Split lines only. Do not join short lines to form longer ones. This prevents sample lines of code, and other such "formatted" text from being unduly combined.

`-u'
`--uniform-spacing'
Uniform spacing. Reduce spacing between words to one space, and spacing between sentences to two spaces.

`-width'
`-w width'
`--width=width'
Fill output lines up to width characters (default 75). fmt initially tries to make lines about 7% shorter than this, to give it room to balance line lengths.

`-p prefix'
`--prefix=prefix'
Only lines beginning with prefix (possibly preceded by whitespace) are subject to formatting. The prefix and any preceding whitespace are stripped for the formatting and then re-attached to each formatted output line. One use is to format certain kinds of program comments, while leaving the code unchanged.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 pr: Paginate or columnate files for printing

pr writes each file (`-' means standard input), or standard input if none are given, to standard output, paginating and optionally outputting in multicolumn format; optionally merges all files, printing all in parallel, one per column. Synopsis:

 
pr [option]... [file]...

By default, a 5-line header is printed at each page: two blank lines; a line with the date, the filename, and the page count; and two more blank lines. A footer of five blank lines is also printed. With the `-F' option, a 3-line header is printed: the leading two blank lines are omitted; no footer is used. The default page_length in both cases is 66 lines. The default number of text lines changes from 56 (without `-F') to 63 (with `-F'). The text line of the header takes the form `date string page', with spaces inserted around string so that the line takes up the full page_width. Here, date is the date (see the `-D' or `--date-format' option for details), string is the centered header string, and page identifies the page number. The LC_MESSAGES locale category affects the spelling of page; in the default C locale, it is `Page number' where number is the decimal page number.

Form feeds in the input cause page breaks in the output. Multiple form feeds produce empty pages.

Columns are of equal width, separated by an optional string (default is `space'). For multicolumn output, lines will always be truncated to page_width (default 72), unless you use the `-J' option. For single column output no line truncation occurs by default. Use `-W' option to truncate lines in that case.

The following changes were made in version 1.22i and apply to later versions of pr:  - Brian

The program accepts the following options. Also see 2. Common options.

`+first_page[:last_page]'
`--pages=first_page[:last_page]'
Begin printing with page first_page and stop with last_page. Missing `:last_page' implies end of file. While estimating the number of skipped pages each form feed in the input file results in a new page. Page counting with and without `+first_page' is identical. By default, counting starts with the first page of input file (not first page printed). Line numbering may be altered by `-N' option.

`-column'
`--columns=column'
With each single file, produce column columns of output (default is 1) and print columns down, unless `-a' is used. The column width is automatically decreased as column increases; unless you use the `-W/-w' option to increase page_width as well. This option might well cause some lines to be truncated. The number of lines in the columns on each page are balanced. The options `-e' and `-i' are on for multiple text-column output. Together with `-J' option column alignment and line truncation is turned off. Lines of full length are joined in a free field format and `-S' option may set field separators. `-column' may not be used with `-m' option.

`-a'
`--across'
With each single file, print columns across rather than down. The `-column' option must be given with column greater than one. If a line is too long to fit in a column, it is truncated.

`-c'
`--show-control-chars'
Print control characters using hat notation (e.g., `^G'); print other nonprinting characters in octal backslash notation. By default, nonprinting characters are not changed.

`-d'
`--double-space'
Double space the output.

`-D format'
`--date-format=format'
Format header dates using format, using the same conventions as for the the command `date +format'; See section 21.1 date: Print or set system date and time. Except for directives, which start with `%', characters in format are printed unchanged. You can use this option to specify an arbitrary string in place of the header date, e.g., `--date-format="Monday morning"'.

If the POSIXLY_CORRECT environment variable is not set, the date format defaults to `%Y-%m-%d %H:%M' (for example, `2001-12-04 23:59'); otherwise, the format depends on the LC_TIME locale category, with the default being `%b %e %H:%M %Y' (for example, `Dec  4 23:59 2001'.

`-e[in-tabchar[in-tabwidth]]'
`--expand-tabs[=in-tabchar[in-tabwidth]]'
Expand tabs to spaces on input. Optional argument in-tabchar is the input tab character (default is the TAB character). Second optional argument in-tabwidth is the input tab character's width (default is 8).

`-f'
`-F'
`--form-feed'
Use a form feed instead of newlines to separate output pages. The default page length of 66 lines is not altered. But the number of lines of text per page changes from default 56 to 63 lines.

`-h HEADER'
`--header=HEADER'
Replace the filename in the header with the centered string header. When using the shell, header should be quoted and should be separated from `-h' by a space.

`-i[out-tabchar[out-tabwidth]]'
`--output-tabs[=out-tabchar[out-tabwidth]]'
Replace spaces with tabs on output. Optional argument out-tabchar is the output tab character (default is the TAB character). Second optional argument out-tabwidth is the output tab character's width (default is 8).

`-J'
`--join-lines'
Merge lines of full length. Used together with the column options `-column', `-a -column' or `-m'. Turns off `-W/-w' line truncation; no column alignment used; may be used with `--sep-string[=string]'. `-J' has been introduced (together with `-W' and `--sep-string') to disentangle the old (POSIX-compliant) options `-w' and `-s' along with the three column options.

`-l page_length'
`--length=page_length'
Set the page length to page_length (default 66) lines, including the lines of the header [and the footer]. If page_length is less than or equal to 10 (or <= 3 with `-F'), the header and footer are omitted, and all form feeds set in input files are eliminated, as if the `-T' option had been given.

`-m'
`--merge'
Merge and print all files in parallel, one in each column. If a line is too long to fit in a column, it is truncated, unless the `-J' option is used. `--sep-string[=string]' may be used. Empty pages in some files (form feeds set) produce empty columns, still marked by string. The result is a continuous line numbering and column marking throughout the whole merged file. Completely empty merged pages show no separators or line numbers. The default header becomes `date page' with spaces inserted in the middle; this may be used with the `-h' or `--header' option to fill up the middle blank part.

`-n[number-separator[digits]]'
`--number-lines[=number-separator[digits]]'
Provide digits digit line numbering (default for digits is 5). With multicolumn output the number occupies the first digits column positions of each text column or only each line of `-m' output. With single column output the number precedes each line just as `-m' does. Default counting of the line numbers starts with the first line of the input file (not the first line printed, compare the `--page' option and `-N' option). Optional argument number-separator is the character appended to the line number to separate it from the text followed. The default separator is the TAB character. In a strict sense a TAB is always printed with single column output only. The TAB-width varies with the TAB-position, e.g. with the left margin specified by `-o' option. With multicolumn output priority is given to `equal width of output columns' (a POSIX specification). The TAB-width is fixed to the value of the first column and does not change with different values of left margin. That means a fixed number of spaces is always printed in the place of the number-separator tab. The tabification depends upon the output position.

`-N line_number'
`--first-line-number=line_number'
Start line counting with the number line_number at first line of first page printed (in most cases not the first line of the input file).

`-o margin'
`--indent=margin'
Indent each line with a margin margin spaces wide (default is zero). The total page width is the size of the margin plus the page_width set with the `-W/-w' option. A limited overflow may occur with numbered single column output (compare `-n' option).

`-r'
`--no-file-warnings'
Do not print a warning message when an argument file cannot be opened. (The exit status will still be nonzero, however.)

`-s[char]'
`--separator[=char]'
Separate columns by a single character char. The default for char is the TAB character without `-w' and `no character' with `-w'. Without `-s' the default separator `space' is set. `-s[char]' turns off line truncation of all three column options (`-COLUMN'|`-a -COLUMN'|`-m') unless `-w' is set. This is a POSIX-compliant formulation.

`-S string'
`--sep-string[=string]'
Use string to separate output columns. The `-S' option doesn't affect the `-W/-w' option, unlike the `-s' option which does. It does not affect line truncation or column alignment. Without `-S', and with `-J', pr uses the default output separator, TAB. Without `-S' or `-J', pr uses a `space' (same as `-S" "'). With `-Sstring', string must be nonempty; `--sep-string' with no string is equivalent to `--sep-string=""'.

On older systems, pr instead supports an obsolete option `-S[string]', where string is optional. POSIX 1003.1-2001 (see section 2.5 Standards conformance) does not allow this older usage. To specify an empty string portably, use `--sep-string'.

`-t'
`--omit-header'
Do not print the usual header [and footer] on each page, and do not fill out the bottom of pages (with blank lines or a form feed). No page structure is produced, but form feeds set in the input files are retained. The predefined pagination is not changed. `-t' or `-T' may be useful together with other options; e.g.: `-t -e4', expand TAB characters in the input file to 4 spaces but don't make any other changes. Use of `-t' overrides `-h'.

`-T'
`--omit-pagination'
Do not print header [and footer]. In addition eliminate all form feeds set in the input files.

`-v'
`--show-nonprinting'
Print nonprinting characters in octal backslash notation.

`-w page_width'
`--width=page_width'
Set page width to page_width characters for multiple text-column output only (default for page_width is 72). `-s[CHAR]' turns off the default page width and any line truncation and column alignment. Lines of full length are merged, regardless of the column options set. No page_width setting is possible with single column output. A POSIX-compliant formulation.

`-W page_width'
`--page_width=page_width'
Set the page width to page_width characters. That's valid with and without a column option. Text lines are truncated, unless `-J' is used. Together with one of the three column options (`-column', `-a -column' or `-m') column alignment is always used. The separator options `-S' or `-s' don't affect the `-W' option. Default is 72 characters. Without `-W page_width' and without any of the column options NO line truncation is used (defined to keep downward compatibility and to meet most frequent tasks). That's equivalent to `-W 72 -J'. The header line is never truncated.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 fold: Wrap input lines to fit in specified width

fold writes each file (`-' means standard input), or standard input if none are given, to standard output, breaking long lines. Synopsis:

 
fold [option]... [file]...

By default, fold breaks lines wider than 80 columns. The output is split into as many lines as necessary.

fold counts screen columns by default; thus, a tab may count more than one column, backspace decreases the column count, and carriage return sets the column to zero.

The program accepts the following options. Also see 2. Common options.

`-b'
`--bytes'
Count bytes rather than columns, so that tabs, backspaces, and carriage returns are each counted as taking up one column, just like other characters.

`-s'
`--spaces'
Break at word boundaries: the line is broken after the last blank before the maximum line length. If the line contains no such blanks, the line is broken at the maximum line length as usual.

`-w width'
`--width=width'
Use a maximum line length of width columns instead of 80.

On older systems, fold supports an obsolete option `-width'. POSIX 1003.1-2001 (see section 2.5 Standards conformance) does not allow this; use `-w width' instead.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5. Output of parts of files

These commands output pieces of the input.

5.1 head: Output the first part of files  Output the first part of files.
5.2 tail: Output the last part of files  Output the last part of files.
5.3 split: Split a file into fixed-size pieces  Split a file into fixed-size pieces.
5.4 csplit: Split a file into context-determined pieces  Split a file into context-determined pieces.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1 head: Output the first part of files

head prints the first part (10 lines by default) of each file; it reads from standard input if no files are given or when given a file of `-'. Synopsis:

 
head [option]... [file]...

If more than one file is specified, head prints a one-line header consisting of
 
==> file name <==
before the output for each file.

The program accepts the following options. Also see 2. Common options.

`-c bytes'
`--bytes=bytes'
Print the first bytes bytes, instead of initial lines. Appending `b' multiplies bytes by 512, `k' by 1024, and `m' by 1048576.

`-n n'
`--lines=n'
Output the first n lines.

`-q'
`--quiet'
`--silent'
Never print file name headers.

`-v'
`--verbose'
Always print file name headers.

On older systems, head supports an obsolete option `-countoptions', which is recognized only if it is specified first. count is a decimal number optionally followed by a size letter (`b', `k', `m') as in -c, or `l' to mean count by lines, or other option letters (`cqv'). POSIX 1003.1-2001 (see section 2.5 Standards conformance) does not allow this; use `-c count' or `-n count' instead.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.2 tail: Output the last part of files

tail prints the last part (10 lines by default) of each file; it reads from standard input if no files are given or when given a file of `-'. Synopsis:

 
tail [option]... [file]...

If more than one file is specified, tail prints a one-line header consisting of
 
==> file name <==
before the output for each file.

GNU tail can output any amount of data (some other versions of tail cannot). It also has no `-r' option (print in reverse), since reversing a file is really a different job from printing the end of a file; BSD tail (which is the one with -r) can only reverse files that are at most as large as its buffer, which is typically 32 KiB. A more reliable and versatile way to reverse files is the GNU tac command.

If any option-argument is a number n starting with a `+', tail begins printing with the nth item from the start of each file, instead of from the end.

The program accepts the following options. Also see 2. Common options.

`-c bytes'
`--bytes=bytes'
Output the last bytes bytes, instead of final lines. Appending `b<