nl [options] [files]
nl copies its files to standard output, prepending line numbers. It’s more flexible than cat with its -n and -b options, providing an almost bizarre amount of control over the numbering. nl can be used in two ways: on ordinary text files, and on specially marked up text files with predefined headers and footers.
Useful options
-v N: Begin numbering with integer N. (Default=1)
-i N: Increment the number by N for each line, so for example, you could use odd numbers only (-i2) or even numbers only (-v2 -i2). (Default=1)
-n [ln|rn|rz]: Format numbers as left-justified (ln), right-justified (rn), or right-justified with leading zeroes (rz). (Default=ln).
-w N: Force the width of the number to be N columns (Default=6)
-s N: Insert string S between the line number and the text. (Default=TAB).
Additionally, nl has the wacky ability to divide text files into virtual pages, each with a header, body, and footer with different numbering schemes. For this to work, however, you must insert nl-specific delimiter strings into the file: \:\:\: (start of header), \:\: (start of body), and \: (start of footer). Each must appear on a line by itself. Then you can use additional options (see the manpage) to affect line-numbering headers and footers of your decorated file.
nl is part of coreutils and lives in /usr/bin.
od [options] [files]
When you want to view a binary file, consider od (Octal Dump) for the job. It copies one or more files to standard output, displaying their data in ASCII, octal, decimal, hexadecimal, or floating point, in various sizes (byte, short, long). For example, this command:
$ od -w8 /usr/bin/who
0000000 042577 043114 000401 000001
0000010 000000 000000 000000 000000
0000020 000002 000003 000001 000000
0000030 106240 004004 000064 000000
...displays the bytes in binary file /usr/bin/who in octal, eight bytes per line. The column on the left contains the file offset of each row, again in octal.
Useful options
-j B: Begin the output at byte B+1 of each file; acceptable formats are the same as in the -N option. (Default=0)
-w [B]: Display B bytes per line; acceptable formats are the same as in the -N option. Using -w by itself is equivalent to -w32 (Default=16)
-s []: Group each row of bytes into sequences of B bytes, separated by whitespace; acceptable formats are the same as in the -N option. Using -s by itself is equivalent to -s3. (Default=2)
-A (d|o|x|n): Display file offsets in the leftmost column, in decimal (d), octal (o), hexadecimal (h), or not at all (n). (Default=o)
-t (a|c)[z]: Display output in a character format, with non alphanumeric characters printed as escape sequences (a) or by name (c). For z, see below.
-t (d|o|u|x)[SIZE[z]]: Display output in floating point. SIZE represents the number of bytes per integer; it can be a positive integer or any of the values F, D, or L, which stand for the size of a float, double, or long double datatype, respectively. For z, see below. If -t is omitted, the default is -to2. Appending z to the -t parameter prints a new column on the right-hand side of the output, displaying the printable characters on each line, much like the default output of xxd.
od is part of coreutils and lives in /usr/bin
xxd [options] [files]
Similar to od, xxd produces a hexadecimal or binary dump of a file in several different formats. It can also do the reverse, converting from its hex dump format back into the original data. For example, the command:
$ xxd /usr/bin/who
0000000: 7f45 4c46 0101 0100 0000 0000 0000 0000 .ELF............
0000010: 0200 0300 0100 0000 a08c 0408 3400 0000 ............4...
0000020: 6824 0000 0000 0000 3400 2000 0600 2800 h$......4....(.
0000030: 1900 1800 0600 0000 3400 0000 3480 0408 .........4...4..
...
displays a hex dump of binary file /usr/bin/who, 16 bytes per row. The left column indicates the file offset of the row, the next eight columns contain the data, and the final column displays the printable characters in the row, if any.
xxd produces three-column output by default: file offsets, the data in the hex, and the data as text (printable characters only).
Useful options
-s N, -s -N: Begin at a position other than the first byte of the file. The first form skips the first N bytes. The second (-N) begins N bytes from the end of the file. (There is also a +N syntax for more advanced skipping through standard input; see the manpage.)
-c N: Display N bytes per row. (Default=16)
-g N: Group each row of bytes into sequences of N bytes, separated by whitespace, like od -s. (Default=2)
-b: Display the output in binary instead of hexadecimal.
-u: Display the output in uppercase hexadecimal instead of lowercase.
-p: Display the output as a plain hexdump, 60 contiguous bytes per line.
-i: Display the output as a C programming language data structure. When reading from a file, it produced an array of unsigned chars containing the data, and an unsigned int containing the array length. When reading from standard input, it produces only a comma-separated list of hex bytes.
-r: The reverse operation: convert from an xxd hex dump back into the original file format. Works with the default hexdump format and, if you add the -p option, the plain hexdump format. If you’re bored, try either of these commands to convert and unconvert a file in a pipeline, reproducing the original file on standard output:
$ xxd myfile | xxd -r
$ xxd -p myfile | xxd -r -pxxd is part of vim-common and lives in /usr/bin.
gv [options] file
GhostView displays an Adobe Postscript or PDF file in an X window. You can invoke it as gv or ghostview. The basic operation of the program is simple: click the desired page number to jump that page, and so forth. A few minutes of playing time and you’ll have the hand of it.
GhostView is the definitive Linux Postscript viewer, but other free PDF viewers include acroread and xpdf.
Useful options
-monochrome, -grayscale, -color: Use the given display mode.
-portrait, -landscape, -seascape, -upsidedown: Choose the page orientation, which gv normally determines automatically.
-scale N: Set the scaling factor (i.e., the zoom) for the display. The integer N may be positive (make the image larger) or negative (smaller).
-watch, -nowatch: Automatically reload the Postscript file (or don’t) when it changes.
xdvi [options] file
The document processing system TeX produces binary output files in a format called DVI, with suffix .dvi. The viewer xdvi displays a DVI file in an X window. If you prefer, convert a DVI file to Postscript via the dvips command and then use GhostView (gv) to display it:
$ dvips -o myfile.ps myfile.dvi
$ gv myfile.ps
While displaying a file, xdvi has a column of buttons down the right-hand side with obvious uses, such as Next to move to the next page. (You can hide the buttons by invoking xdvi with the -expert option.) You can also navigate the file by keystroke.
n, spacebar, enter, pagedown: Jump to next page. Precede it with number N to jump by N pages.
p, backspace, delete, pageup: Jump to previous page. Precede it with number N to jump by N pages.
<: Jump to first page.
>: Jump to last page.
^L: Redisplay the page.
R: Reread the DVI file, say, after you’ve modified it.
Press Mouse Buttons: Magnify a rectangular region under the mouse cursor.
xdvi has dozens of command-line options for tailoring its colors, geometry, zoom, and overall behavior.
That covers it for the file viewing commands. Next time, I’ll cover different commands to create files, including MS Office files.
Related posts:




