Linux cat Command with 12 Practical Examples

Linux cat command is an awesome command to see the content of a file. This command is mainly used to display the content of one or multiple files. Click here If you are interested in learning the Top 25 Linux commands. In this article, we will discuss Linux cat Command with 12 Practical Examples.

(1) Basic Usage: display content of a file

This is the most basic example of using the cat command. Just type cat with the file name and you can see all content of the file on the terminal screen.

cat <path-of-file>

(2) Display multiple files in a single terminal

If you don't have time, you can see multiple files at once. Just type cat command with different files and all the files will be open on the terminal screen. This example makes this command unique as it is a little difficult to do the same tasks with other commands.

cat <file1> <file2>

(3) Display usage of cat command

You can see different options available with commands by using the --help option. This displays all available options on the terminal screen.

cat --help

(4) Mention line number in each line of file

Sometimes you want to mention the line number in front of each line. If you use the -n option, you can display the content of the file with the line number.

cat -n <path-of-file>

(5) Create a file using cat command

If you want to create a quick file and enter some content, use greater than operator following by file name.

cat > <file-name>

You can use (Ctrl + d) or (Ctrl + c) to exit and save files.

(6) Enter $ in each line of the file

cat -e <path-of-file>

(7) Creating one file by combining two or more files

By using this example, you can combine multiple files into one file.

cat <file1> <file2> <file3> <file4> > <file>

(8) Appending content of the file in existing file

cat <file1> >> <file2>

(9) Identify the version of the cat command

This example just displays the version of cat command.

cat --version

(10) Enter line numbers in each line leaving a blank line

This command gives line numbers only to that line where content is available.

cat -b <path-of-file>

(11) Display lines of a file in reverse order

This is a fun example where the user reverses the line order by using tac command.

tac <path-of-file>

(12) Display content of all files in the current directory

By using the * with cat command, you can display all content of files of the current directory on the terminal screen.

cat *

Conclusion

Linux cat command is a useful command and should be known by every Linux user. In this article, we have covered the Linux cat command with 12 examples that will help you understand this command's usage.

Subscribe us to receive more such articles updates in your email.

If you have any questions, feel free to ask in the comments section below. Nothing gives me greater joy than helping my readers!

Disclaimer: This tutorial is for educational purpose only. Individual is solely responsible for any illegal act.

You may also like...

Leave a Reply

Your email address will not be published.