"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
Default=0
Timeout=5
Splashimage= (hd0,0)/grub/splash.xpm.gz
Hiddenmenu
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
Initrd/initramfs-2.6.32-431.el6.x86_64.img

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

[email protected] ~]# cat Textfile1
A
B
C
[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  
A    
b    
C    
[[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
root:x:0:0:root:/root:/bin/bash$
bin:x:1:1:bin:/bin:/sbin/nologin$
daemon:x:2:2:daemon:/sbin:/sbin/nologin$
adm:x:3:4:adm:/var/adm:/sbin/nologin$
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin$
sync:x:5:0:sync:/sbin:/bin/sync$
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown$
halt:x:7:0:halt:/sbin:/sbin/halt$
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin$
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin$
operator:x:11:0:operator:/root:/sbin/nologin$
games:x:12:100:games:/usr/games:/sbin/nologin$
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin$
Ftp:x:14:50:ftp user:/var/ftp:/sbin/nologin$
nobody:x:99:99:nobody:/:/sbin/nologin$
Vcsa:x:69:69:virtual Console Memory owner:/dev:/sbin/nologin$
saslauth:x:499:76: "SASLAUTHD user":/var/empty/saslauth:/sbin/nologin$
postfix:x:89:89::/var/spool/postfix:/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  
Linux

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]

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.