The use of cat and Echo in Linux

Source: Internet
Author: User

    • To create an empty file:

      Touch Akeke.log

    • Use Echo to create a new file and simply edit a file:

      #echo "I am Wuyike" >wuyike.txt

      Then use Cat view: #cat wuyike.txt

    • The difference between > and >>:

> is to empty and add new content, i.e. redirect

>> is to append a new content after the file content, that is, append redirect

  • Append content to a file with Cat: (Pros: Multiple lines of content can be added)

    [email protected] ~]# cat >>wuyike.txt<<eof

    > I am Beautiful

    > EOF

    View results:

    [email protected] ~]# cat Wuyike.txt

    I am Wuyike

    I am Beautiful

  • Using cat to redirect files:(Pros: Multiple lines of content can be added)

    [[Email protected] ~] #cat >wuyike.txt<<eof

    > I am a Student

    > EOF

    View results:

    [email protected] ~]# cat Wuyike.txt

    I am a Student

  • You can also add multiple lines of content to a file using echo:

    [Email protected] ~]# echo "Wuyike

    > Wuyikeke ">>wuyike.txt

    View results:

    [email protected] ~]# cat Wuyike.txt

    I am a Student

    Wuyike

    Wuyikeke

  • Correct output redirection: Code 1, using > or >>.

    Error output redirection: Code 2, using 2> or 2>>. Make the error message in the file.

    [Email protected] ~]# Ech wuyike 2>test.txt

    [email protected] ~]# cat Test.txt

    -bash:ech:command not found

    Or:

    [Email protected] ~]# echo 111 1>wuyike.txt 2>wuyike1.txt

    [email protected] ~]# cat Wuyike.txt

    111

    [email protected] ~]# cat Wuyike1.txt

    [Email protected] ~]#

    [Email protected] ~]# Ech 111 1>wuyike.txt 2>wuyike1.txt

    [email protected] ~]# cat Wuyike.txt

    [email protected] ~]# cat Wuyike1.txt

    -bash:ech:command not found


This article from "11805879" blog, declined reprint!

The use of cat and Echo in Linux

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.