Cat command in Linux with examples
Cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives their content as output. It helps us to create, view, concatenate files. So let us see some frequently used cat commands.
1) To view a single file
Command:
$cat filename
Output
It will show content of given filename
2) To view multiple files
Command:
$cat file1 file2
Output
This will show the content of file1 and file2.
3) To view contents of a file preceding with line numbers.
Command:
$cat -n filename
Output
It will show content with line number example:-cat-n geeks.txt 1)This is geeks 2)A unique array
4) Create a file
Command:
$ cat >newfile
Output
Will create and a file named newfile
5) Copy the contents of one file to another file.
Command:
$cat [filename-whose-contents-is-to-be-copied] > [destination-filename]
Output
The content will be copied in destination file
6) Cat command can suppress repeated empty lines in output
Command:
$cat -s geeks.txt
Output
Will suppress repeated empty lines in output
7) Cat command can append the contents of one file to the end of another file.
Command:
$cat file1 >> file2
Output
Will append the contents of one file to the end of another file
8) Cat command can display content in reverse order using tac command.
Command:
$tac filename
Output
Will display content in reverse order
9) Cat command can highlight the end of line.
Command:
$cat -E "filename"
Output
Will highlight the end of line
10) If you want to use the -v, -E and -T option together, then instead of writing -vET in the command, you can just use the -A command line option.
Command
$cat -A "filename"
This article is contributed by Pranav. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- more command in Linux with Examples
- atd command in Linux with examples
- df Command in Linux with examples
- which command in Linux with examples
- scp command in Linux with Examples
- ssh command in Linux with Examples
- bg command in Linux with Examples
- fg command in Linux with examples
- rev command in Linux with Examples
- tee command in Linux with examples
- rcp Command in Linux with examples
- col command in Linux with Examples
- fc Command in Linux with Examples
- gcc command in Linux with examples
- apt-get command in Linux with Examples



