Find Files that are Modified Today (or Since Certain Time Ago) in Unix & Linux

»»»Find Files that are Modified Today (or Since Certain Time Ago) in Unix & Linux

To find all files that was modified since a specific time ago (i.e an hour ago, a day ago, 24 hours ago, a weeks ago and so on) in Unix and Linux environment, the find command will come in handy. The command syntax is:

To find all files modified in the last 24 hours (last full day) in current directory and its sub-directories:

find . -mtime -1 -print

Flag -mtime -1 option tells find command to look for files modified in the last day (24 hours). Flag -print option will cause find command to print the files’ location. -print can be replaced with -ls if you want a directory-listing-type response.

To find all files modified in the last 24 hours (last full day) in a particular specific directory and its sub-directories:

find /directory_path -mtime -1 -print

The command is basically the same with the earlier command, just that now you no need to cd (change directory) to the directory you want to search.

To find all files with regular file types only, and modified in the last 24 hours (last full day) in current directory and its sub-directories:

find /directory_path -type f -mtime -1 -print

To find all files that are modified today only (since start of day only, i.e. 12 am), in current directory and its sub-directories:

touch -t `date +%m%d0000` /tmp/$$
find /tmefndr/oravl01 -type f -newer /tmp/$$
rm /tmp/$$

The first command can be modified to specify other date and time, so that the commands will return all files that have changed since that particular date and time.

By | 2017-01-01T22:20:47+00:00 January 1st, 2017|Categories: Linux|Tags: , |23 Comments

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.Connect with LK through Tech Journey on Facebook, Twitter or Google+.
  • iPAS

    Great Thnks!

  • Very good article, thanx!

  • Pingback: Finding files modified since a certain time « Tech Notes @ Fernvale()

  • Deiby

    Thanks!!

  • And how you will find files by specified hour?

    example. Files modified in last 8hours, if now, the time is 01AM

  • Prabhakar

    It was of timely help 🙂

    Thanks.

  • Susmita

    thanks a lot for the good article.

  • Additionally, to find files modified less than an hour ago:

    <code>find . -mtime -0.041666667 -print</code>

    Simply divide 1 by 24 (24 hours) and you'll get what you want. For example, 0.1 is 2 hours and 24 minutes.

    I hope this helps whoever needs to find files modified LESS than one full day ago. 🙂

    —–

    Bruno De Barros

  • Kiran Kappeta

    Good one. Thanks.

    Tried

    find . -mtime -0.041666667 -print

    on Debian, it throws an error

    "find: invalid argument `-0.041666667' to `-mtime'"

  • @Kiran Kappeta, it works for me on Ubuntu. Try to see if it supports any non-integer values at all (for example, try 0.5 or 0.25). If it doesn't, there's your problem.

  • Mike

    Question: If one does a find for files modified in the last two minutes, and it takes the command ten minutes to complete, is that going to fail completely?

  • edel

    Merci, danke, thank you… clearly explained and put. Why can't man be this simple to read?

  • RandiR

    Nice article. Don't forget the -exec switch that goes with the find command. It's very powerful.

    I have been struggling with how to do these unix thingies on windows, I had to look a lot – found biterscripting. Here is the biterscripting commnad to do the same thing on windows.

    ls -n -r "*" "/directory-path" ($fmtime >= "20100201")

    Finds files modified since Feb 1st, 2010, etc. The ls command is fairly useful with a lot of search criterial. Since many developers use both unix and windows, thought this tidbit of info may be useful to some.

  • David Rogoff

    Redhat Linux doesn't allow mtime to be real. However, there is mmin which is in minutes.

  • JMKnorrey

    Are these commands the same in Ubuntu ?

  • muthu raman

    thx dude.. gud 1….

  • Leon

    Very usefull , Thanks!

  • Afm

    Thanks… 🙂

  • vikram

    what is the way to find the same in windows?

    • Find on Windows

      lol

    • Enigma IT Solutions

      Sure – Use Powershell:

      Get-ChildItem -Recurse | Where { $_.LastWriteTime -ge $(GetDate).AddDays(-1) }

      Though, if you’re wanting to use the results to copy files, use robocopy with the /maxage parameter.

  • satish dubey

    good way of explanation.

    Thanks a lot!

  • Dan St.André

    I believe that the “-daystart” option modifies “-mtime -1” to force consideration of changes since midnight (0000) between yesterday and today.

STAY IN TOUCH

close-link