Write to file, but overwrite it if it exists

前端 未结 8 1584
一个人的身影
一个人的身影 2020-12-07 07:29
echo \"text\" >> \'Users/Name/Desktop/TheAccount.txt\'

How do I make it so it creates the file if it doesn\'t exist, but overwrites it if it

8条回答
  •  日久生厌
    2020-12-07 08:26

    To overwrite one file's content to another file. use cat eg.

    echo  "this is foo" > foobar.txt
    cat foobar.txt
    
    echo "this is bar" > bar.txt
    cat bar.txt
    

    Now to overwrite foobar we can use a cat command as below

    cat bar.txt >> foobar.txt
    cat foobar.txt
    

提交回复
热议问题