I want to have a window open that is just the content of the file file.txt
. I do not care which command I use to open it, nano, cat, vi
or whatever. I want it to update every time it changes, so if I open it in another window, edit it and save it, the file in the original window will update, kind of like screen
. Any suggestions?
I have already tried just having it open a new cat file.txt
command every few seconds, but it is very unreliable.
Use the command line to navigate to the Desktop, and then type cat myFile. txt . This will print the contents of the file to your command line. This is the same idea as using the GUI to double-click on the text file to see its contents.
Cat. The simplest way to view text files in Linux is the cat command. It displays the complete contents in the command line without using inputs to scroll through it. Here is an example of using the cat command to view the Linux version by displaying the contents of the /proc/version file.
In the Actions ribbon, select File & Folder > Text File Update. In the File field, use the ellipsis (...) to navigate to the text file you want to update. In the Search For field, enter the text which you want to update. The search will look for the exact sequence of words entered.
Use
watch cat file.txt
That should update when any changes occur, also try
man watch
To see what options it has so you can update the frequency of the updates.
The low-tech solution in case watch
is not available:
while sleep 1; do tput clear; cat file.txt; done
(lets you easily adapt the checking interval).
On Linux, you can use the inotifywait command like so:
#!/bin/sh
while inotifywait --event modify file.txt; do
tput clear
cat file.txt
done
which is a modified version of Example 2 in the man page. This has the great advantage of doing absolutely nothing until file.txt is modified. The answers suggesting polling have the problems that polling always does: it will waste time when nothing has changed, and it will fail to catch changes until the polling interval has ended.
If you are on macOS you probably don't have watch
installed per standard. You could go for the low-tech solution - which is elegant anyway, but you can also revert to home-brew.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
You might have to give it (once!) your (administration) password. After the installation finishes, you should always check the system:
brew doctor
There should be a message along the lines:
Your system is ready to brew.
Now you are ready to install watch
:
brew install watch
Once that is finished, you are ready for the solution by @dave-mackintosh:
watch cat file.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With