Create text file and fill it using bash

前端 未结 5 693
一整个雨季
一整个雨季 2020-12-12 19:45

I need to create a text file (unless it already exists) and write a new line to the file all using bash.

I\'m sure it\'s simple, but could anyone explain this to me?

5条回答
  •  情深已故
    2020-12-12 19:56

    Creating a text file in unix can be done through a text editor (vim, emacs, gedit, etc). But what you want might be something like this

    echo "insert text here" > myfile.txt
    

    That will put the text 'insert text here' into a file myfile.txt. To verify that this worked use the command 'cat'.

    cat myfile.txt
    

    If you want to append to a file use this

    echo "append this text" >> myfile.txt
    

提交回复
热议问题