fbpx cat Command in Linux: Display & Concatenate Files | Certificação Linux

cat Command in Linux: Display, Concatenate & Create Files

📅 01/01/2019 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
cat Command in Linux: Display, Concatenate & Create Files
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp