Is it safe to open a file that is being written by a running script?

I am running a shell script that is writing to a file.
This script may take a long time to complete and I would like to monitor the partial output rather than wait for the whole script to finish.

Is it safe to open (double click) a file that is being written by the script?


Solution 1:

Reading the file is safe, although double clicking you mentioned will probably open the file in some editor that will offer you an option to make changes and save them. Missclicks happen, so I recommend commands that won't even let you change the file.

These are examples that work in terminal; they will only read the file:

cat file
less file
less +F file
tail -n 5 file
tail -f file

Solution 2:

As long as you are not writing to it, it should be okay.

However, I would recommend using

tail -f log_file

in another terminal.

This command will "follow" the file log_file and write the newly added content as soon as it is updated by the script.

Solution 3:

Not enough rep to add a comment to Kamil Maciorowski's answer:

For some files you'll want tail -F file so that the following will continue through a rotation. Watching syslog for example.