1.8 File Viewing Commands
cat — Concatenate and Display File Content Utility
Format:
cat [options] file
Common Options:
-
-n: Number all output lines (including blank lines).
-
-b: Number non-empty output lines.
-
-s: Suppress repeated consecutive empty output lines into a single blank line.
-
-E: Display a $ at the end of each line.
-
-T: Display tab characters as ^I.
-
-A: Equivalent to -vET (shows all non-printing and formatting characters).
-
-v: Use ^ and M- notation to display non-printing characters, except for tabs and line breaks.
Examples:
$ cat file
$ cat -n file
more — File Pager Utility
Format:
more [options] file
Common Options:
-
-d: Display user prompts instead of ringing the system bell (e.g., [Press space to continue, 'q' to quit.]).
-
-c: Draw new pages from the top down instead of scrolling the terminal interface.
-
-f: Count logical lines rather than screen lines (avoids wrapping artifacts in long line counts).
-
-l: Do not pause after processing a form-feed character (^L).
-
-s: Squeeze multiple consecutive blank lines into a single empty line.
-
-u: Suppress underline formatting codes.
-
+n: Begin displaying file contents starting at line number n.
Interactive Controls:
-
Space: Advance down by one full page.
-
Enter: Advance down by one line.
-
b: Move backward by one full page.
-
/pattern: Search downward for the specified regular expression string.
-
n: Repeat the previous search.
-
q: Exit the pager utility.
-
=: Display the current line number.
-
f: Advance down by one full screen (on supported implementations).
-
Ctrl+D: Scroll down half a screen width.
-
Ctrl+B: Scroll backward one full screen.
Examples:
more file1
less — Advanced File Pager Utility (Recommended)
Format:
less [options] [file...]
Common Options:
-
-N: Display explicit line numbers.
-
-S: Disable line-wrapping (causes long lines to scroll horizontally).
-
-X: Prevent clearing the terminal screen upon exiting less.
-
-i: Ignore case patterns during searches.
-
-I: Enforce case sensitivity during searches (unless the search pattern contains uppercase characters).
-
-r: Output raw control characters directly (such as color codes).
-
-R: Render ANSI color escape sequences cleanly (highly recommended).
-
+F: Monitor active file expansion in real-time (similar to executing tail -f).
-
+G: Open the target file directly at the end of its contents.
Interactive Controls:
-
Space: Page downward by one full screen.
-
Enter: Scroll downward by one line.
-
b: Page upward by one full screen.
-
y: Scroll upward by one line.
-
G: Jump directly to the end of the file.
-
1G or g: Jump directly to the beginning of the file.
-
/pattern: Search downward for the string pattern.
-
?pattern: Search upward for the string pattern.
-
n: Repeat the previous search in the forward direction.
-
N: Repeat the previous search in the reverse direction.
-
q: Exit the pager utility.
Examples:
$ less -N file1
head — Output Beginning of File Utility
Format:
head [options] file...
Common Options:
-
-n NUM: Print the first NUM lines of the file.
-
-c NUM: Print the first NUM bytes of the file.
-
-q: Suppress file headers when tracking multiple files.
-
-v: Always print headers containing file names.
Examples:
$ head -n 10 file
tail — Output End of File Utility
Format:
tail [options] file...
Common Options:
-
-n NUM: Print the trailing NUM lines of the file.
-
-c NUM: Print the trailing NUM bytes of the file.
-
-f: Continuously output appended data as the file grows (ideal for log monitoring).
-
-F: Similar to -f, but tracks the file descriptor by name, surviving log rotations safely.
-
-q: Suppress file name header markers across multiple targets.
-
-v: Always display file name header markers across multiple targets.
Examples:
$ tail -n 20 file
$ tail -f logfile