如何解决linux - 文件更改时终端上的输出更改
在打开的终端中,当进程向文件写入数据时,我怎么能看到添加到文件中的所有新内容?
我尝试了
class Website:
"""The parent Website class"""
def __init__(self):
self.name = "X"
self.url = "X"
self.articles = "X"
def get_articles(self):
return "N/A"
def get_all_subclasses(cls):
all_subclasses = []
for subclass in cls.__subclasses__():
all_subclasses.append(subclass)
return all_subclasses
class Website1(Website):
"""Implementation for Website1"""
def __init__(self):
self.name = 'Website1'
self.url = 'www.google.com'
self.articles = self.get_articles()
def get_articles(self):
# insert custom logic to get articles based on url
articles = ['article 1','article 2','articl 3']
return articles
class Website2(Website):
"""Implementation for Website2"""
def __init__(self):
self.name = 'Website2'
self.url = 'www.google.com'
self.articles = self.get_articles()
def get_articles(self):
# insert custom logic to get articles based on url
articles = ['article 1','article 3']
return articles
site_articles = {}
websites = Website.get_all_subclasses(Website)
for site in websites:
site_articles[site().name] = site().articles
和 cat
的组合,但没有成功
解决方法
使用带 -f 的尾部
tail -f filename
取自 tail 的手册页:
-f,--follow[={name|descriptor}]
output appended data as the file grows;
an absent option argument means 'descriptor'
,
你不能用cat来做,你应该使用tail -f <filename>
或less <filename>
并压入F以等待数据。
$ man less
...
F Scroll forward,and keep trying to read when the end of file is reached. Normally this
command would be used when already at the end of the file. It is a way to monitor the
tail of a file which is growing while it is being viewed. (The behavior is similar to
the "tail -f" command.)
...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。