cat Command in Linux: Display, Concatenate & Create Files
The cat command in Linux concatenates files, prints their content to the screen, and can also receive text typed from the keyboard to a file.
The most common options for cat are:
- -b Numbers the lines that are not blank
- -E Shows $ at the end of each line
- -n Numbers all lines, including blank ones
- -s Eliminates repeated blank lines
- -T Replaces the TAB key code with ^I
Let's see how to create a file with just a few lines of text:
$ cat > teste.txt
Now you can type any text. When you're done, press Ctrl d on an empty line to finish data entry and save the file teste.txt.
To see the content of the freshly created file:
$ cat teste.txt
Cat can also be used to concatenate files.
$ cat texto1.txt > texto.txt
Note that in this example the content of the file texto.txt is replaced by texto1.txt.
To append the content of texto1.txt at the end of the file texto.txt the correct command would be:
$ cat texto1.txt >> texto.txt
Displays the content of a source code file with numbered lines:
$ cat -n teste.c 1 #include <stdio.h> 2 int main() 3 { 4 printf("Certificação Linux!\n"); 5 };
If you are an IT professional, support technician, or developer, have you thought about learning Linux for real?
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Liked it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.