Bash: How to find all files modified on a certain day

The following bash function (e.g. stored in your ~/.bash_aliases) finds all files within a directory that was changed on a specific date. I use this to retroactively check on all my activities throughout a day. For code-related changes, a filtered git log certainly is better, but this includes file downloads, modified text documents in one search query, if aimed at my home directory.

# CHON
#   list files changed on certain day
#
# Usage
#   chon <folder> [<date>]
#
# Arguments
#   folder: absolute/relative path to search location
#           defaults to '.'
#   date: day of changes (expected in yyyy-mm-dd format)
#         defaults to 'today'
#
# Examples
#   chon
#   chon /var/www/logs
#   chon src/moduleA 1995-11-24
#
function chon()
{
    search_dir=${1:-.}
    day=${2:-$(date +%Y-%m-%d)}
    next_day=$(date +%Y-%m-%d -d "${day} + 1 day")
    find $search_dir \
        -type f \
        -newermt ${day} \
        ! -newermt ${next_day} \
        -ls
}


Posted

in

,

by

Tags: