Skip to content

Instantly share code, notes, and snippets.

@consatan
Created February 23, 2022 01:56
Show Gist options
  • Save consatan/a4e48eb8808148dcd25efa5fb20e9c65 to your computer and use it in GitHub Desktop.
Save consatan/a4e48eb8808148dcd25efa5fb20e9c65 to your computer and use it in GitHub Desktop.
find by mtime older than today midnight
#! /bin/bash
# v.a. https://unix.stackexchange.com/a/257966
# -daystart -mtime +0 表示文件的 mtime 时间在当天 0 点前(用于保留最新的一个文件)
# 如果没有 -daystart 的话,表示 文件的 mtime 时间在 24 小时前(用于保留最新的2个文件)
find ./ -maxdepth 1 -type f -name '*.log' -daystart -mtime +0 -exec gzip {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment