How To Use cat Command In Linux / UNIX

The cat command in Linux/UNIX is used to concatenate and display files, as well as to create and edit files. Here are some basic examples of how to use the cat command:

  1. Display the contents of a file:

To display the contents of a file, simply use the cat command followed by the file name. For example:

cat filename.txt

This will display the contents of the file “filename.txt” in the terminal.

  1. Display the contents of multiple files:

To display the contents of multiple files, use the cat command followed by the file names, separated by spaces. For example:

cat file1.txt file2.txt file3.txt

This will display the contents of all three files in the terminal.

  1. Concatenate files:

To concatenate files (i.e., join them together into a single file), use the cat command followed by the input file names, and redirect the output to a new file using the “>” operator. For example:

cat file1.txt file2.txt > combined.txt

This will concatenate the contents of “file1.txt” and “file2.txt” and save the result in a new file called “combined.txt”.

  1. Create a new file:

To create a new file, use the cat command followed by the “>” operator and the name of the new file. For example:

cat > newfile.txt

This will create a new file called “newfile.txt” and allow you to enter text into it. To save the file, press Ctrl + D.

By using the cat command, you can view, concatenate, and create files in Linux/UNIX.

Leave a Comment