GO KALI FREE
File Management

cat Linux Command

Displays the entire contents of a file on the terminal.

What does cat do?

Displays the entire contents of a file on the terminal.

Syntax

cat [options] filename

Practical example

cat /etc/hostname

Questions about cat

How do I display a file with cat?

Use `cat filename` to print the entire file contents to the terminal. For large files, use `less` or `more` instead.

How do I concatenate two files with cat?

Use `cat file1 file2 > combined.txt` to merge two files into one. The `>` operator redirects output to a file.

How do I show line numbers with cat?

Use `cat -n filename` to display line numbers on the left side of each line. This is useful for referencing specific lines.

How do I show non-printing characters with cat?

Use `cat -v filename` to show non-printing characters (like tabs as ^I). Add `-e` to show line ends as `$`.

How do I display a file in reverse order?

Use `tac filename` (cat spelled backwards) to display lines in reverse order from last to first.

How do I display special characters with cat?

Use `cat -A filename` to show all special characters including tabs (^I) and line endings ($).

When should I use less instead of cat?

Use `less` for large files because it loads content page by page. `cat` dumps the entire file to the terminal at once, which can be overwhelming for large files.

Related File Management

rmdir

Removes an empty directory. Safer than rm -r for removing directories.

less

Views file contents page by page with forward and backward navigation.

rm

Removes (deletes) files or directories. Use -rf for recursive force delete.

more

Views file contents one screen at a time (forward-only navigation).

mv

Moves or renames files and directories.

head

Displays the first 10 lines of a file by default. Use -n to specify count.