Sortix cross-nightly manual
This manual documents Sortix cross-nightly. You can instead view this document in the latest official manual.
NAME
rw — blockwise input/outputSYNOPSIS
rw | [-afhPstvx] [-b block-size] [-c count] [-I input-offset] [-i input-file] [-O output-offset] [-o output-file] [-p period] [-r input-block-size] [-w output-block-size] |
DESCRIPTION
rw reads blocks from the standard input and copies them to the standard output until the end of the standard input. The input and output block sizes default to appropriate values for efficiently reading from the input and writing to the output. Input and output will be done as aligned as possible on the block size boundaries. The final input block can be partial. Output blocks are written whenever enough input blocks have been read, or partially written whenever the end of the input is reached. The output file is not truncated after the copy is done.- B
- Magnitude of a byte (1 byte).
- K, KiB
- Magnitude of kibibytes (1,024 bytes).
- M, MiB
- Magnitude of mebibytes (1,048,576 bytes).
- G, GiB
- Magnitude of gibibytes (1,073,741,824 bytes).
- T, TiB
- Magnitude of tebibytes (1,099,511,627,776 bytes).
- P, PiB
- Magnitude of pebibytes (1,125,899,906,842,624 bytes).
- E, EiB
- Magnitude of exbibytes (1,152,921,504,606,846,976 bytes).
- r
- Magnitude of input blocks (the default input block size when setting block sizes).
- w
- Magnitude of output blocks (the default output block size when setting block sizes
- x
- Magnitude of input and output blocks (if they have the same size) (the default block size when setting block sizes).
- -a
- In combination with -o, open the output file in append mode. This option must be used with -o and is incompatible with -t. The output offset is set to the size of the output file.
- -b block-size
- Set both the input and output block sizes to the byte quantity specified by block-size.
- -c count
- Stop after copying the byte quantity specified by count, in addition to stopping when the end of the input is reached. If the count starts with a leading ‘-’, stop that many bytes before the end of the input (only works if the input size is known).
- -f
- Continue as much as possible in the event of I/O errors and exit unsuccessfully afterwards. For each input failure, skip forward to the next input block or the next native-size input block or the end of the file (whichever comes first), write an error to the standard error, and replace the failed input with NUL bytes when writing it to the output. For each output failure, skip forward to the next output block or the next native-size output block (whichever comes first) and write an error to the standard error. The native-size input and output blocks are those defined by the preferred input/output size for the input and output. This option only works for the input if it is seekable and the input size is known. This option only works for the output if it is seekable (and -a is not set). Beware that the default preferred input/output sizes may be larger than the underlying storage sector sizes: If this option is used, the -r and -w options should be set to the appropriate input/output sector sizes, or more than just the bad sector may be skipped.
- -h
- Write statistics in the human readable format where byte amounts and time amounts are formatted according to their magnitude as described in the DIAGNOSTICS section.
- -I offset
- Skip past the first offset bytes in the input before the copying begins. If the offset starts with a leading ‘-’ it is interpreted as that many bytes before the end of the input (if the size is known), and if it starts with a leading ‘+’ it is interpreted as that many bytes after the end of the input (if the size is known). If the input is not seekable, the first offset bytes are read and discarded before the copying begins. If the offset is not a multiple of the input block size, the first input block is reduced in size such that it ends at an input-block-size-aligned position in the input.
- -i input-file
- Read the input from input-file instead of the standard input.
- -O offset
- Seek past the first offset bytes in the output before the copying begins. If the offset starts with a leading ‘-’ it is interpreted as that many bytes before the end of the output (if the size is known), and if it starts with a leading ‘+’ it is interpreted as that many bytes after the end of the output (if the size is known). If the output is not seekable, the number of NUL bytes specified in offset are written to the output before the copying begins. This option cannot be set to a non-zero value if -a is set. If the offset is not a multiple of the output block size, the first output block is reduced in size such that it ends at a output block size aligned position in the output.
- -o output-file
- Write the output to output-file instead of the standard output, creating the file if it doesn't exist. If output-file already exists, the existing data is not discarded. Use -t if you want to truncate the output afterwards.
- -P
- Pad the final output block with NUL bytes, such that the final output offset (counting the initial offset with -O) is a multiple of the output block size.
- -p period
- Write occasional statistics to the standard error during the transfer and on completion, or when being terminated by SIGINT. period specifies the period in whole seconds at which statistics are written out. Statistics are written for every read and write if the period is zero. The format is described in the DIAGNOSTICS section.
- -r input-block-size
- Set the input block size to the byte quantity specified by input-block-size.
- -s
- Sync the output on successful completion.
- -t
- Truncate the output to the final output position after the copy has completed. This option requires the output to be truncatable. This option is incompatible with -a.
- -v
- Write statistics to the standard error upon completion, or when being terminated by SIGINT. The format is described in the DIAGNOSTICS section.
- -w output-block-size
- Set the output block size to the byte quantity specified by output-block-size.
- -x
- In combination with -o, fail if the output file already exists.
ASYNCHRONOUS EVENTS
- SIGINT
- If -v or -p is set, abort the copy, write statistics to the standard error, and then exit as if killed by SIGINT.
- SIGUSR1
- Write statistics to the standard error and continue the copy. If SIGUSR1 is not ignored, this handler is installed and this signal is unblocked. To use this signal without a race condition before the signal handler is installed (as SIGUSR1 is deadly by default), block the signal before loading this program. To disable the handling of this signal, ignore the signal before loading this program.
EXIT STATUS
rw will exit 0 on success and non-zero otherwise.EXAMPLES
Copy from the standard input to the standard output:rw
rw -c 256
rw -i foo -o bar
rw -i foo -o bar -t
rw -i foo -o /dev/bar -p 10 -h -s
rw -I 512 -c 1024 -o bar -a
rw -c 2K -i foo -I 768 -o bar -O 256M
rw -r 512 -i /dev/foo -I 32r -c 4r -o bar
rw -b 4096 -c 64x -I 32x -O 65536x
rw -f -i /dev/foo -r 512 -o bar -t -p 10 -h
rw -r 512 -w 8192 -c 16384r -I 65536r -O 1048576w
rw -c 512 -I -1024 -o bar -O +2048
rw -i foo -I 100 -c -200
DIAGNOSTICS
Statistics about the copy are written to the standard error upon completion if either -v or -p are set; occasionally if -p is set; upon SIGINT (if not ignored when the program was loaded) if -v is set; and upon SIGUSR1 (if not ignored when the program was loaded).<time-elapsed> s <done> B / <total> B <percent>% <speed> B/s <time-left> s
7 s 714682368 B / 1238364160 B 57% 102097481 B/s 5 s
7 s 714.4 MiB / 1.1 GiB 60% 102.0 MiB/s 4 s
HISTORY
rw originally appeared in Sortix 1.1.- The command line options use the conventional option format.
- The output file is not truncated by default. One has to use -t.
-
The input and output block sizes default to the preferred I/O block sizes instead of 512 bytes.
- Statistics are not written by default. One has to use -v or -p. The statistics contain more useful information and is machine readable as it contains no localized information. A human readable statistics format is available using -h. Statistics can occasionally be written out using -p.
- There is no support for converting ASCII to EBCDIC, converting ASCII to a different EBCDIC, EBCDIC to ASCII, swapping pairs of bytes, converting the bytes to lower-case or upper-case, converting line-delimited data into fixed-size blocks, or converting fixed-sized blocks into line-delimited data.
- Offsets can be specified relative to the end of the input/output.
- Input errors stop the copying immediately rather than writing out a partial output block.