1.linux下删除指定文件最后一行
def delLastText(self, fileName): """ 删除指定文件最后一行 """ self.cmd('cd /var/www/html/http/') self.cmd('pwd') self.cmd("sed -i '$d' %s" % fileName) result = self.cmd('cat %s' % fileName) return result
2.linux下给指定文件追加最后一行
def addLastText(self, fileName, text): """ 给某个文件添加内容 """ self.cmd('cd /var/www/html/http/') self.cmd('pwd') self.cmd("echo '%s' >> %s" % (text, fileName)) result = self.cmd('cat %s' % fileName) return result