Common commands on Linux (i)--cat

Source: Internet
Author: User

In recent months just turned from windows, and began to slowly familiar with Linux, first not to rip than which is better, first of all with the spirit of mutual reference to understand each platform.

Linux on the development, remove the use of text editor to do the development of the Big God, everyone (including my rookie novice) need to master the Linux is a common command, can make some occasional trivial and troublesome needs to simplify. This time we'll tidy up a few.

    1. Cat
    2. Paste
    3. Cut
    4. Grep

One by one, starting with cat, yesterday the interview was asked to answer not to come up ...

Cat

Mainly three functions: displaying file contents, creating files, merging files

The basic syntax is: Cat [-parameter] file name

Specific parameters, please enter your own cat--help view, here first introduce a few I think commonly used

    • Simply display a file
Cat Test.cpp

The Terminal Small Black window will directly print out all the contents of this file, if the file is too long, you can pass the pipeline to less to slowly see

Cat Test.cpp|less
    • Display a file and add line numbers

Add line numbers to all rows

Cat-n Test.cpp

Add line numbers to non-blank lines

Cat-b Test.cpp
    • Create a file
Cat > Test.txt << EOF

Simply execute the cat > Test.txt, then the terminal will wait for you to continue typing, all your input will be written to the Test.txt, finally can use CTRL + C to end, but this is not excellent (zhuang) Ya (BI), where the << EOF means that when the terminal detects that you are entering the EOF string, end the input.

    • Merging files (similar to paste's basic functionality)
Cat Test.cpp test.txt > Testall

The meaning of this sentence is to output test.cpp and test.txt in sequence, and then put the results into testall this file, note here > if changed to >> that is splicing to testall the original content, otherwise it is covered by the original content

So much for the moment, a few other commands to follow. Incidentally, cat can also be used in combination with piping and paste, grep, etc., for example:

The cat test.cpp|grep-a 3 ' haha ' function is to take out all the contents of the test.cpp into grep to find the haha string and enter the line of the string that satisfies the condition and the following 3 rows

Resources:

Http://www.cnblogs.com/perfy/archive/2012/07/23/2605550.html

http://my.oschina.net/hebad/blog/346408

Common commands on Linux (i)--cat

Related Article

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.