yuan93
V2EX  ›  Ubuntu

ubuntu 清理日志

  •  
  •   yuan93 · Jul 8, 2020 · 2261 views
    This topic created in 2152 days ago, the information mentioned may be changed or developed.

    之前服务器一直用的 centos6/7,第一次使用 ubuntu

    我想找出 space.log 中所有包含某个字符串的行 space.log 只有几百 kb

    root@iZgw85:/data# grep 'Utils' space.log
    Binary file space.log matches
    root@iZgw85:/data# grep -i 'Utils' space.log
    Binary file space.log matches
    root@iZgw85:/data# grep -a 'Utils' space.log
    grep: memory exhausted
    

    space.log 是 logback 生成的日志文件,刚刚生成的时候是可以 grep 搜索内容的

    但是我每天会定时清理日志文件,清理过后再 grep 就会提示 Binary file space.log matches

    清理命令是:echo > space.log 或者 cat /dev/null > space.log 都会这样

    有什么能清理文件内容,但是不改变文件格式的命令吗?

    Supplement 1  ·  Jul 8, 2020
    目前用 strings space.log |grep 'Utils' 可以实现目的了
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2754 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:50 · PVG 17:50 · LAX 02:50 · JFK 05:50
    ♥ Do have faith in what you're doing.