"Linux Command detailed" 12, text content display-[Cat, TAC]

Source: Internet
Author: User
Tags gopher

12, this section is mainly to learn in the Linux system text file content display related commands, these commands have cat, TAC and so on.

12.1 Cat

You can use the Cat command to display the contents of a text file, or to attach several file contents to another file.

12.1.1 Command syntax:

cat[options [File]

12.1.2 option Parameters:

Cat command option meaning

Option option meaning

-N to the output of all line numbering

-B number of non-null output lines

-S When you encounter a row that has more than two consecutive lines, it is replaced with a blank line of one row

-e displays $ at the end of each line

12.1.3 instances:

Example 1: Displaying the contents of a/etc/grub.conf file

[Email protected] ~]# cat/etc/grub.conf
# grub.conf generated by Anaconda
# Note that you don't have the to rerun grub after making changes to the This file
# notice:you has a/boot partition. This means
# all kernel and INITRD paths is relative to/boot/, eg.
# root (hd0,0)
# kernel/vmlinuz-version RO Root=/dev/vda3
# initrd/initrd-[generic-]version.img
#boot =/dev/vda
Splashimage= (hd0,0)/grub/splash.xpm.gz
Title CentOS (2.6.32-431.el6.x86_64)
Root (hd0,0)
kernel/vmlinuz-2.6.32-431.el6.x86_64 ro root=uuid=3acde1c8-9946-441b-a5e6-2e53b6530f87 Rd_NO_LUKS rd_NO_LVM LANG=en _us. UTF-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto keyboardtype=pc keytable=us Rd_NO_DM rhgb quiet

Example 2: Enter the file contents of the file Textfile1 into the Textfile2 file after adding the line number

[email protected] ~]# cat Textfile1
[Email protected] ~]# cat-n textfile1 > Textfile2
[email protected] ~]# cat Textfile2
1 A
2 b
3 C

Example 3: Append the contents of the file Textfile1 and textfile2 to the file textfile3 after adding the line number (blank line not added)

[[email protected] ~]# cat textfile1  
[[email protected] ~]# cat textfile2    
      1  a    
     2  b    
   & nbsp 3  c    
[[email protected] ~]# cat-b textfile1 textfile2 >> textfile3    
[[Em Ail protected] ~]# cat textfile3    
     1  a    
      2  b    
     3  c    
     4& nbsp;      1  a    
     5        2  b    
     6       3  C

Example 4: Append $ symbol at the end of each line to display the/etc/passwd file

[Email protected] ~]# CAT-E/etc/passwd
Ftp:x:14:50:ftp user:/var/ftp:/sbin/nologin$
Vcsa:x:69:69:virtual Console Memory owner:/dev:/sbin/nologin$
saslauth:x:499:76: "SASLAUTHD user":/var/empty/saslauth:/sbin/nologin$
Sshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologin$

[[email protected] ~]# cat >mm.txt<<eof  
> hello                        // Enter character here Hello    
> linux                        //Enter the characters in this Linux    
> eof                          //Enter the character EOF here, it will automatically go back to the shell prompt interface    
[[email protected] ~]# cat mm.txt    
Hello & nbsp  

View Mm.txt File contents

12.2 TAC

Using the TAC command, you can display the file contents from the last line, and you can see that the TAC is the reverse display of cat.

12.2.1 command syntax:

tac[options [File]

12.2.2 option Parameters:

TAC command option parameter meaning

Option option meaning

-B Add Separator flag before line end

-R interprets the delimited flag as a regular expression

-s< character > use specified string instead of line break as delimited flag

12.2.3 instances:

Example 1: Displays the contents of the/root/pu file starting from the last line.

[Email protected] ~]# Cat/root/pu
Hello Linux
Hello Centos
[Email protected] ~]# Tac/root/pu
Hello Centos
Hello Linux

Example 2: Use the character s instead of newline to display the contents of the/root/pu file as a delimited flag.

[Email protected] ~]# tac-s R/root/pu
Hello Linux
Hello Centos

"Linux Command detailed" 12, text content display-[Cat, TAC]

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.