If a file exists,
> will overwrite the file and
>> will append to the end of the file. If a file does not exist, both will create a new file.
echo command automatically adds a newline after your string.
echo 1 > num.txt echo 1 > num.txt echo 2 >> num.txt
will create the following file:
1 1 2
Furthermore, you cannot just modify a single line in a text file. You have to read the whole file, modify it in your code and then write to the whole file again.