Detailed cat command

Linux -- cat to view file contents

 

CAT(1)                      User Commands                      CAT(1)

 

NAME

    cat - concatenate files and print on the standard output

          concatenates files and displays the contents of the file on standard output

 

SYNOPSIS syntax

    cat [OPTION]... [FILE]...

 

DESCRIPTION

    Concatenate FILE(s), or standard input, to standard output.

    The connection file, or standard input, is displayed on standard output.

 

    -A, --show-all

        equivalent to -vET

        Equivalent to -vET.

 

    -b, --number-nonblank

        number nonempty output lines, overrides -n

        Number non-blank lines. When used with -n, -n has no effect.

 

    -e  equivalent to -vE

        Equivalent to -vE.

 

   -E, --show-ends

        display $ at end of each line

        Display a $ sign at the end of each line.

 

   -n, --number

        number all output lines

        Number each line, including blank lines.

 

    -s, --squeeze-blank

        suppress repeated empty output lines

        When two or more blank lines are encountered, only one line is displayed.

 

    -t  equivalent to -vT

        Equivalent to -vT.

 

    -T, --show-tabs

        display TAB characters as ^I

        Display the TAB character with ^I.

 

    -u  (ignored)

        neglect.

 

    -v, --show-nonprinting

        use ^ and M- notation, except for LFD and TAB

        In addition to LFD and TAB, use the ^ and M- characters to display non-ASCII characters.

 

    --help display this help and exit

        Display help information and exit.

 

    --version

        output version information and exit

        Display version information and exit.

 

    With no FILE, or when FILE is -, read standard input.

    When no file is specified or the file placeholder is replaced with '-', the standard input is read.

 

EXAMPLES

    cat f - g

        Output f's contents, then standard input, then g's contents.

        Output the contents of f, then the contents read from the standard input device, and finally the contents of g.

 

    cat    Copy standard input to standard output.

        Output what is read from the standard input device to standard output.

 

    GNU coreutils online help: <http://www.gnu.org/software/coreutils/>

    Report cat translation bugs to <http://translationproject.org/team/>

 

AUTHOR Author

    Written by Torbjorn Granlund and Richard M. Stallman.

 

COPYRIGHT Copyright

    Copyright (C) 2013 Free Software Foundation, Inc.  License GPLv3+: GNU  GPL  version 3 or later <http://gnu.org/licenses/gpl.html>.

    This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

 

SEE ALSO

    tac(1)

 

    The full documentation for cat is maintained as a Texinfo manual. If the info and cat programs are properly installed at your site, the command

        info coreutils 'cat invocation'

    should give you access to the complete manual.

    The complete documentation for cat is maintained as a Texinfo manual. If both the info and cat programs are installed, execute the command:

        info coreutils 'cat invocation'

    should give you access to the entire manual.

 

GNU coreutils 8.22            June 2014            CAT(1)

 

case analysis:

1. Original documents and content

[root@user test]# ls
test.txt
[root@user test]# cat test.txt
abcdefghijklmnopqrstuvwxyz
cdefghijklm nopqrstuvwxyzab
defghijklmnopqrstuvwxyzabc

efghijklmnopqrstuvwxyzabcd


ijklmnopqrstuvwxyzabcdefgh
9ijklmnopqrstuvwxyzabcdefgh

take aim
Ah
sadfsdf9    00-=-+!@#$%^&
■▲△→↑↓ ̄︿@
[root@user test]#

 

2. View the content and line number of test.txt

[root@user test]# cat -n test.txt
     1  abcdefghijklmnopqrstuvwxyz
     2  cdefghijklm nopqrstuvwxyzab
     3  defghijklmnopqrstuvwxyzabc
     4
     5  efghijklmnopqrstuvwxyzabcd
     6
     7
     8  ijklmnopqrstuvwxyzabcdefgh
     9  9ijklmnopqrstuvwxyzabcdefgh
    10
    11 Aim
    12
    13  sadfsdf9    00-=-+!@#$%^&
    14  ■▲△→↑↓ ̄︿@
[root@user test]#

 

3. Check the content and line number of test.txt, blank lines are not numbered

[root@user test]# cat -b test.txt
     1  abcdefghijklmnopqrstuvwxyz
     2  cdefghijklm nopqrstuvwxyzab
     3  defghijklmnopqrstuvwxyzabc

     4  efghijklmnopqrstuvwxyzabcd


     5  ijklmnopqrstuvwxyzabcdefgh
     6  9ijklmnopqrstuvwxyzabcdefgh
     7
     8 Aim
     9
    10  sadfsdf9    00-=-+!@#$%^&
    11  ■▲△→↑↓ ̄︿@
[root@user test]#

 

4. Check the content and line number of test.txt, only one line is displayed for multiple empty lines

[root@user test]# cat -sn test.txt
     1  abcdefghijklmnopqrstuvwxyz
     2  cdefghijklm nopqrstuvwxyzab
     3  defghijklmnopqrstuvwxyzabc
     4
     5  efghijklmnopqrstuvwxyzabcd
     6
     7  ijklmnopqrstuvwxyzabcdefgh
     8  9ijklmnopqrstuvwxyzabcdefgh
     9
    10 Aim
    11 Yeah
    12  sadfsdf9    00-=-+!@#$%^&
    13  ■▲△→↑↓ ̄︿@
[root@user test]#

 

5. Check the content and line number of test.txt, only one line is displayed for multi-blank lines, and TAB and the end of each line are marked

[root@user test]# cat -snTE test.txt
     1  abcdefghijklmnopqrstuvwxyz$
     2  cdefghijklm^Inopqrstuvwxyzab$
     3  defghijklmnopqrstuvwxyzabc$
     4  $
     5  efghijklmnopqrstuvwxyzabcd$
     6  $
     7  ijklmnopqrstuvwxyzabcdefgh$
     8  9ijklmnopqrstuvwxyzabcdefgh$
     9  ^I$
    10 Aim $
    11 ya$
    12  sadfsdf9^I00-=-+!@#$%^&$
    13  ■▲△→↑↓ ̄︿@$
[root@user test]#

 

Six, -v display

 

[root@user test]# cat -v test.txt
abcdefghijklmnopqrstuvwxyz
cdefghijklm nopqrstuvwxyzab
defghijklmnopqrstuvwxyzabc

efghijklmnopqrstuvwxyzabcd


ijklmnopqrstuvwxyzabcdefgh
9ijklmnopqrstuvwxyzabcdefgh

M-gM-^^M-^DM-gM-^^M-^D
M-eM- ^ QM - ^ @
sadfsdf9    00-=-+!@#$%^&
M-bM-^VM- M-bM-^VM-2M-bM-^VM-3M-bM-^FM-^RM-bM-^FM-^QM-bM-^FM-^SM-oM-?M-#M-oM-8M-?M-oM-<M-
[root@user test]# 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326347685&siteId=291194637