如何从linux终端删除日志文件的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12302290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete content of a log file from linux terminal?
提问by Sushan Ghimire
I have a log file on server called writelog
which is about 2GB
.
我呼吁服务器日志文件writelog
大约是2GB
。
I want to delete first 100,000
lines from the file. I could open the file and delete those lines but because of the file size it takes me forever to download it.
我想100,000
从文件中删除第一行。我可以打开文件并删除这些行,但由于文件大小,我需要永远下载它。
So, is it possible to do this from Linux terminal? If yes how?
那么,是否可以从 Linux 终端执行此操作?如果是如何?
采纳答案by perreal
If you are running a Linux server, you can use ssh
:
如果您正在运行 Linux 服务器,则可以使用ssh
:
ssh [email protected] sed -i '1,100000d' /path/to/logfile
回答by Aaron Digulla
回答by roblogic
If you want to clear out the whole filea quick way is
如果你想清除整个文件,一个快速的方法是
cat /dev/null > writelog
cat /dev/null > writelog
See also this thread on unix.com.
另请参阅unix.com 上的此线程。