让服务器在后台挂着跑代码,终端可以退出和关闭,同时会在当前目录下生成nohup.out文件,所有的代码在终端的输出会保存在该文件中。
之前发现nohup.out没有实时保存print内容,需要在python后加-u即解决,即
查看nohup.out文件nohup python -u 要执行的文件
实时查看文件内容,在nohup.out文件目录处,输入指令
tail -f nohup.out
查看文件最后100行:
tail -n 100 nohup.out
根据关键字查看:
tail -f nohup.out |grep “关键字”
用关键字查看文件最后100行
清空nohup.out文件tail -n 100 nohup.out |grep “关键字”
cp /dev/null nohup.out
cat /dev/null > nohup.out



