cat command in Linux / Unix with Examples

cat command in Linux / Unix with Examples

The cat command is a utility in Linux and Unix systems that allows you to concatenate and display files. It is commonly used to view the contents of a file or to create a new file by combining multiple files.

Here are some examples of how you can use the cat command:

  • To view the contents of a file:
refer to:‮al‬utturi.com
cat file.txt

This command will display the contents of the file file.txt.

  • To create a new file by combining multiple files:
cat file1.txt file2.txt file3.txt > combined.txt

This command will create a new file called combined.txt by concatenating the contents of file1.txt, file2.txt, and file3.txt.

  • To view the contents of multiple files at once:
cat file1.txt file2.txt file3.txt

This command will display the contents of file1.txt, file2.txt, and file3.txt one after the other.

  • To view the contents of a file with line numbers:
cat -n file.txt

This command will display the contents of file.txt with line numbers.

  • To view the contents of a file and pause after each screenful of output:
cat -s file.txt | less

This command will display the contents of file.txt and pause after each screenful of output. You can use the Space key to display the next screenful of output and the q key to exit.

  • To view the contents of a file and highlight certain patterns:
cat -E file.txt

This command will display the contents of file.txt and highlight the ends of lines with a $ symbol.

There are many other options and arguments that you can use with the cat command. For a complete list of options and more detailed information about how to use the cat command, you can consult the cat man page by running the man cat command.

Created Time:2017-10-27 14:56:38  Author:lautturi