328

E.g., a MySQL server is running on my Ubuntu machine. Some data has been changed during the last 24 hours.

What (Linux) scripts can find the files that have been changed during the last 24 hours?

Please list the file names, file sizes, and modified time.

Benjamin W.
  • 38,596
  • 16
  • 96
  • 104
JackWM
  • 9,467
  • 21
  • 61
  • 91
  • 1
    You could use http://stackoverflow.com/questions/4561895/how-to-recursively-find-the-latest-modified-file-in-a-directory – vaugham Apr 18 '13 at 14:40

6 Answers6

577

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 -ls

Should be to your liking

The - before 1 is important - it means anything changed one day or less ago. A + before 1 would instead mean anything changed at least one day ago, while having nothing before the 1 would have meant it was changed exacted one day ago, no more, no less.

ArtOfWarfare
  • 19,191
  • 16
  • 128
  • 186
Xavjer
  • 8,390
  • 2
  • 21
  • 41
57

Another, more humane way:

find /<directory> -newermt "-24 hours" -ls

or:

find /<directory> -newermt "1 day ago" -ls

or:

find /<directory> -newermt "yesterday" -ls
Maxim Egorushkin
  • 125,859
  • 15
  • 164
  • 254
48

You can do that with

find . -mtime 0

From man find:

[The] time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.

Michael
  • 55,116
  • 9
  • 74
  • 120
13

On GNU-compatible systems (i.e. Linux):

find . -mtime 0 -printf '%T+\t%s\t%p\n' 2>/dev/null | sort -r | more

This will list files and directories that have been modified in the last 24 hours (-mtime 0). It will list them with the last modified time in a format that is both sortable and human-readable (%T+), followed by the file size (%s), followed by the full filename (%p), each separated by tabs (\t).

2>/dev/null throws away any stderr output, so that error messages don't muddy the waters; sort -r sorts the results by most recently modified first; and | more lists one page of results at a time.

Stephen G Tuggy
  • 809
  • 9
  • 13
9

For others who land here in the future (including myself), add a -name option to find specific file types, for instance: find /var -name "*.php" -mtime -1 -ls

jytou
  • 430
  • 4
  • 5
resedasue
  • 434
  • 5
  • 14
5

This command worked for me

find . -mtime -1 -print
BhandariS
  • 586
  • 7
  • 19