Cat Command - Display File Content | Online Free DevTools by Hexmos

Display file content with the Cat command. Learn how to show file contents, with line numbers, and exclude blank lines using the cat command.

Cat Command

Display File Content with Cat

The cat command, short for concatenate, is a fundamental utility in Unix-like operating systems used primarily to display the contents of files on the standard output. It's incredibly versatile and can be used for simple file viewing, concatenating multiple files, or even creating new files.

Basic File Display

The most common use of the cat command is to display the entire content of a single file. Simply type cat followed by the filename.

cat <file>

Display File Content with Line Numbers

To make it easier to reference specific lines within a file, you can use the -n option with the cat command. This will prepend each line of the output with its corresponding line number.

cat -n <file>

Display File Content Excluding Blank Lines

Sometimes, you might want to display file content while ignoring any blank lines. The -b option achieves this by numbering only non-empty output lines.

cat -b <file>

Understanding Cat Command Options

The cat command offers several other useful options, such as:

  • -s: Squeeze multiple adjacent blank lines into a single blank line.
  • -E: Display a '$' at the end of each line.
  • -T: Display TAB characters as '^I'.

By mastering these options, you can efficiently view and manipulate text files directly from your terminal.

External Resources