Commands

Commands

cat

[OPTION] [FILE]

Copies the specified file (or standard input) to standard output.

Example: To display the contents of the file /etc/passwd to standard output, use

cat /etc/passwd

graphics/tip.gif

To send the contents of a file to some other program as input, cat is frequently used on the left side of a pipe:

 

cat database.dat | sort -rn

-A, --show-all

This option is equivalent to "-vET".

-b, --number-nonblank

Use this option to include line numbers for output (nonblank lines only) and to number all nonblank output lines, starting with 1.

-e

This option is equivalent to "-vE".

-E, --show-ends

Use this option to display a "$" after the end of each line.

-n, --number

Use this option to include line numbers in output.

-s, --squeeze-blank

Use this option to condense any sequence of two or more blank lines into a single blank line.

-t

This option is equivalent to "-vT".

-T, --show-tabs

Use this option to output <TAB> characters as "^I".

-u

This option has no effect; it is included for UNIX compatibility.

-v, --show-nonprinting

Use this option to output control characters in "^whatever" format, excepting only line feed and tab.

head

[OPTION] [FILE]

head

-NUMBER [OPTION] [FILE]

This command displays the first part of the specified file(s) to standard output.

Example: To print the first 300 bytes (-c option) of textfile.txt to standard output, use

head -c 300 textfile.txt

-cBYTES, --bytes=BYTES

Output the specified number of bytes, rather than initial lines. Byte count may be specified in blocks (b), kilobytes (k), and megabytes (m).

-n N, --lines=N

Output the specified number of lines (default is 10).

-q, --quiet, --silent

Do not include file names in output.

-v, --verbose

Include file names in output.

less

-?

less

--help

less

-V

less

--version

less

[-[+]aBcCdeEfgGiImMnNqQrsSuUVwX]

[-b bufs] [-h lines] [-j line] [-k keyfile]

[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]

[-T tagsfile] [-x tab] [-y lines] [-[z] lines]

[+[+]cmd] [--] [filename]

less is the preferred method for displaying text files. This program's name is an illustration of one of the big truisms in computer science: When you've been programming for 20 hours, almost anything is funny. The gag is that the program is an improvement on a program called "more", which also displayed stuff to standard output. "less" is "more". Get it? The big improvement over "more" is that you can scroll backward as well as forward within the file.

Example: To paginate a lengthy display, pipe it to less:

grep -n [AaEeIiOoUu] | less

less is interactive; once invoked, there are a variety of ways to specify how far and in what direction you wish to scroll. The following may be preceded by an integer, hereafter N, which specifies some number of lines:

h or H Help:

Display a summary of the interactive commands.

SPACE, ^V, f, ^F

Scroll forward N lines (one window by default).

z

Scroll forward N lines. (This command is similar to space, but with the option to specify a new window size.)

ESC-SPACE

Scroll forward a full screen, ignoring possible end of file.

RETURN, ^N, e, ^E, j, ^J

Scroll forward N lines.

d, ^D

Scroll forward N lines, default .5 screen.

b, ^B or ESC-v

Scroll backward N lines, default 1 window.

w

Like ESC-f, but with N specified, it becomes the new window size.

y, ^Y, ^P, k, ^K

Scroll backward N lines, default 1.

u, ^U

Scroll backward N lines, default .5 screen.

ESC-) or RIGHTARROW

Scroll horizontally right N characters, default 8.

ESC-( or LEFTARROW

Scroll horizontally left N characters, default 8.

r or ^R or ^L

Redraw the screen.

R

Repaint the screen, discarding any buffered input.

F

Scroll forward and keep trying to read when the end of file is reached.

G, <, ESC-<

Go to line N in the file, default 1.

G or > or ESC->

Go to line N in the file, default the end of the file.

P or %

Go to a position N percent into the file.

{

If a left curly bracket appears in the top line displayed on the screen, the { command will trace through the file to the matching right curly bracket.

}

If a right curly bracket appears in the bottom line displayed on the screen, the } command will trace through the file to the matching left curly bracket.

(

Like {, but applies to parentheses, rather than curly brackets.

)

Like }, but applies to parentheses, rather than curly brackets.

[

Like {, but applies to square brackets rather than curly brackets.

]

Like }, but applies to square brackets rather than curly brackets.

ESC-^F

Followed by two characters, acts like {, but uses the two characters as open and close brackets.

ESC-^B

Followed by two characters, acts like }, but uses the two characters as open and close brackets.

m

Followed by any lowercase letter, mark the current position with that letter.

', X^X

Followed by any lowercase letter, return to the position that was previously marked with that letter.

/pattern, ESC-/ pattern

Search forward in the file for the Nth line containing the pattern.

^N or !

Search for lines that do NOT match the pattern.

^E or *

If the specified pattern is not found in the current file, continue looking in the next file listed.

^F or @

Begin searching for pattern in the first line of the first file listed (regardless of which file is currently displayed).

^K

Keep current position, but highlight any text matching pattern.

^R

Don't interpret regular expression metacharacters.

?pattern,ESC-?pattern

Search backward in the file for pattern.

n

Continue previous search.

N

Continue previous search, but in reverse direction.

ESC-n

Continue search, but crossing file boundaries.

ESC-N

Repeat previous search, but in the reverse direction and crossing file boundaries.

ESC-u

Undo search highlighting.

:e [filename]

Look at a new file.

^X^V, E

Same as :e.

:n

Switch to the next file in the command line list.

:p

Switch to the previous file in the command line list.

:x

Switch to the first file in the command line list.

=, ^G, :f

Display information about the current file (name, line num ).

-[option]

While the program is running, set the specified option.

-+[option]

Reset the specified option to its default setting.

--[option]

Reset the specified option to the opposite of its default setting.

_[option]

Display the current value of the specified option.

+cmd

Run specified command each time a new file is examined.

V

Display the version number.

Command Line Options

-?, --help

Display an online summary of commands.

-a

Start search after last line displayed on screen.

-bn

Use only the specified number of buffers on each file.

-B

Force less to limit use of buffers to number specified by -bn.

-c

Redraw from top line down (as opposed to bottom up).

-C

Same as -c, but clear the screen first.

-d

Suppress the dumb terminal error message.

-e

Automatically exit upon reaching end of file for second time.

-E

Automatically exit upon reaching end of file for first time.

-f

Force less to open directories, device special, and other nontext files.

-g

Highlight only the particular string found by the last search command.

-G

Do not highlight strings found by search commands.

-hn

Scroll backward to upper limit of n lines.

-i

Treat uppercase and lowercase letters as identical in searches.

-I

Like -i, but searches ignore case even if the pattern contains uppercase letters.

-jn

If found, position search target at screen line n.

-kfilename

Use specified file as a lesskey file.

-m

Prompt verbosely.

-M

Prompt extremely verbosely.

-n

Do not print line numbers.

-N

Number the displayed lines.

-ofilename

Copy input to the specified file while outputting to display.

-Ofilename

Copy input to the specified file while outputting to display; if necessary, overwrite existing file.

-ppattern

Same as /pattern.

-P

Prompt.

-q

Be somewhat quieter than the default.

-Q

Run in total silence; never ring the terminal bell.

-r

Include raw control characters in output.

-s

Squeeze. Condense 2 or more blank lines into a single blank line.

-S

Truncate long lines, rather than folding to next line.

-ttag

Edit the file containing tag.

-Ttagsfile

Use the specified file instead of "tags".

-u

Output backspace and carriage returns, as printable characters.

-U

Output backspace, carriage returns, and tabs as printable characters.

-V, --version

Output version number.

-w

Use blank lines to represent lines past end of file (as opposed to ~).

-xn

Set tab stop every nth position.

-X

Do not send termcap initialization strings to the terminal.

-yn

Scroll forward to a maximum of n lines.

[z]n

Set the default scrolling window size to be n lines.

-"

Set the filename quoting character.

--

Delimiter only; used to mark the end of options.

+

Delimiter; anything that follows is taken as an initial argument to less.

look

[-dfa] [-t termchar] string [file]

This command displays any lines in the specified file that contain a prefix of string.

Example: To display all lines that start with the string "Example", use

look Example disp.txt

-d

Use alphanumeric characters only in comparisons.

-f

Tread upper- and lowercase letters as equivalent.

-a

Specify use of the alternate dictionary /usr/dict/web2.

-tchar

Specify that an occurrence of character char terminates any comparisons.

rev

[file]

Copies the lines of file to standard output in reverse order.

Example: This command has no options. If your input file was

abcd
efgh
ijkl

then

rev infile

would yield

dcba
hgfe
lkji

tac

[OPTION] FILE

Copies lines to standard output in reverse order. Typically used to reverse files containing records separated by some separator (new line by default). Opposite of "cat".

Example: If your input file was

abcd
efgh
ijkl

then

tac infile

would yield

ijkl
efgh
abcd

-b, --before

Attach the separator to the beginning of the record that it precedes in the file.

-r, --regex

Treat the separator string as a regular expression.

-s SEPARATOR, --separator=SEPARATOR

Use the specified characters as the record separator (instead of newline).

tail

[OPTION] [FILE]

tail

-NUMBER [OPTION] [FILE]

tail

+NUMBER [OPTION] [FILE]

Prints the last portion of a file for standard output.

Example: To print the last 20 lines of textfile.txt, use

tail -n 20 textfile.txt

-cBYTES, --bytes=BYTES

Output the specified number of bytes, rather than lines. Bytes may be specified in blocks (b), kilobytes (k), or megabytes (m).

-f, --follow

Keep looking for additional characters at the end of a (presumably growing) file.

-n N, --lines=N'

Output the last N lines (default 10).

-q, -quiet, --silent

Do not include file name headers in output.

-v, --verbose

Include file names in output.

 



Linux Desk Reference
Linux Desk Reference (2nd Edition)
ISBN: 0130619892
EAN: 2147483647
Year: 2000
Pages: 174
Authors: Scott Hawkins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net