Linux command: cat

A quick guide to the cat command to add content to files

astailSomehow we havecat. apart fromcatYou can also add content to the file, which makes it super powerful.

In the simplest usage,catPrint the contents of the file to standard output:

cat file

You can print the contents of multiple files:

cat file1 file2

And use the output redirection operator>You can concatenate the contents of multiple files into a new file:

cat file1 file2 > file3

use>>You can append the contents of multiple files to a new file, or create a new file if it does not exist:

cat file1 file2 >> file3

When viewing the source code file, it’s nice to see the line number, and you cancatuse-nOptions:

cat -n file1

You can only use to add numbers to non-blank lines-b, Or you can use to delete all multiple blank lines-s.

catUsually used in conjunction with pipeline operators|Use the contents of the file as input for another command:cat file1 | anothercommand.

This command can be used in Linux, macOS, WSL and wherever you have a UNIX environment

Download mine for freeLinux Command Manual


More cli tutorials: