Bash: Find File Created Today Since Midnight

Find file that was created today since midnight.

Method 1

# List file and use awk to grab the month and day columns.

FILEDATE=$(ls -l filename | awk '{print $6" "$7}')

# Find what date is.

TODAYDATE=$(date +"%b %e")

# Check to see if the file was really created after midnight.

if [ "$FILEDATE" = "$TODAYDATE" ];then
echo "Found file from today." else echo "File from today not found."
fi

Method 2

# Make dummy file for comparing date.

touch -t $(date +%m%d0000) /tmp/$$

# Find result file created today.

FILE=$(find . -type f -newer /tmp/$$ | head -n1) # Remove temp dummy file. rm /tmp/$$ if [$FILE = ""]; then
      echo "File from today found!"
else
echo "File from today found!"

Leave a comment

Your email address will not be published. Required fields are marked *