Find todays files

I am trying to find todays files only in the "root directories like /etc, /opt etc.

I do not want to search in my home directory or any of its subdirectories.

That's hard because a directory listing does not show the year?

-rw------- 1 andy andy 22487 Oct 12 13:40 .xsession-errors

find . -type f -ls |grep 'Oct 12'

You dont mention your OS...
Have you seen all the options of find cmd?

today=$(date +"%Y-%m-%d")

for dir in /etc /opt /tmp
do
   find $dir -type f -mtime -1 2>/dev/null | while read file
   do
      cdate=$(stat -c %y "$file")
      [[ ${cdate%% *} = $today ]] && echo "$file"
   done
done
1 Like

Ubuntu Mate 18.04

I looked for a way to add a signature here where I could list that.

Did not find it.

Why not

stat -c"%y %n" /etc/* /opt/* | awk -vTD="$today" '$0 ~ "^" TD {sub ($1 FS $2 FS "\\" $3 FS, ""); print}'

or

stat -c"%y %n" /etc/* /opt/* | grep "^$today" | cut -d" " -f4-

I would like the output to show the date and time of each file.

I can read up on it, just need a link. :slight_smile:

DREF=/tmp/dref
# set file time to one second before midnight of today in
# this example midnight is 201810120000   %Y %m %d %H %S format (with no spaces)

touch -t 201810115959  $DREF

ls -a /etc /opt /foo /bar /farkle | while read fname 
do
  # regular file from today
  if [[  $fname -nt $DREF && -f $fname ]]; then
       echo $fname
  fi
done > todays_files
$rm $DREF
1 Like

I forgotten touch -t Though my preferred method when searching a precise timestamp...

Would something like this help:-

touch -mt $(date +%Y%m%d0000) /tmp/start_of_today                 # Create a reference file with a timestamp starting at 00:00 today
find /etc /opt /tmp -type f -newer /tmp/start_of_today -ls        # Search for files in these 3 directories that are newer than the reference and list them.

The output is not quite the same as ls -l but it should be usable. It is far safer than trying to interpret the output from ls -l

I hope that this is useful.
Robin

1 Like