Linux cat command - Display text files

Linux cat command: Display text files

Linux cat command Function Description

Use the cat command to display the contents of a text file, or to append the contents of several files to another file.

Linux cat command Syntax

cat [Option] [File]

The meaning of each option in the command is shown in the table:

Option Description
-n Numbering all rows of the output
-b Numbering non-empty output lines
-s When more than two consecutive blank lines are encountered, replace them with one blank line
-E Show $ at the end of each line

Linux cat command Demo

Displays the contents of the /etc/grub.conf file:

[root@rhel ~]# cat /etc/grub.conf
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
#NOTICE: You have a/boot partition. This means that
#        all kernel and initrd paths are relative to/boot/, eg.
#        root(hd0,0)
#        kernel/vmlinuz-version ro root=/dev/sda2
#        initrd/initrd-[generic-]version.img
password --encrypted
            61aFd0Gw3uB0r/oQE$y80vx6.tXQQdJTr457ORMUaqOuouP1wajM15vHjzvo4oI6sc P8HZfUwhrpKEAbOwDb4oUxmdwFDMcoJ59LMxH0
title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
      root (hd0,0)
      kernel/vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=2ac36994-5a18-4741-8118-96fe2c57a6c6 r
d_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
      initrd /initramfs-2.6.32-358.el6.x86_64.img

Enter the contents of textfile1 with line numbers into textfile2

[root@rhel ~]# cat -n textfile1 > textfile2

Append the contents of textfile1 and textfile2 with line numbers (blank lines are not added) to the file textfile3

[root@rhel ~]# cat -b textfile1 textfile2 >> textfile3

Display the /etc/passwd file with the $ symbol at the end of each line

[root@rhel ~]# cat -E /etc/passwd
gopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologin

Use the cat command to create the mm.txt file

[root@rhel ~]# cat >mm.txt<<EOF
>Hello                    //Enter the character Hello here
>Linux                   //Enter the character Linux here
>EOF                    //Enter the character EOF here and it will automatically return to the Shell prompt screen


Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?