Daniel's Blog

Finding the most recently changed files

This small problem came up recently. I was using a docker image that someone else developed. However, there seemed to be some missing data. Whenever I restarted the container, the settings I saved were lost. So their image was not using one of the documented volumes for some data. So I decided to find out where the data was saved. To do this I needed to know what were the most recently changed files inside the source code of the website.

To build this command, I started with the find tool to find all files (rather than directories)

find . -type f

Then I sent that data to xargs so I can call the stat function with the filename returned from find to get the modification date as well as the name of the file. -c will provide a custom output. %y gives the modificatin date. %n gives the filename.

find . -type f | xargs stat -c "%y %n"

Once I have that data, I can send it to sort to sort it by number in reverse order (larger to smaller or in this case most recent datetime to oldest datetime).

find . -type f | xargs stat -c "%y %n" | sort -nr 

Then I can return the top 10 using the head command

find . -type f | xargs stat -c "%y %n" | sort -nr | head -10

Running this command quickly output the following:

2022-09-19 21:16:55.907200669 +0000 ./bootstrap/cache/config.php
2022-09-19 21:16:55.890199100 +0000 ./bootstrap/cache/services.php
2022-09-19 21:16:55.890199100 +0000 ./bootstrap/cache/packages.php
2022-09-19 21:15:07.788223105 +0000 ./public/js/builds/357e9fcadab23c6fd627e5a54475e9bc16634655135.js
2022-09-19 21:15:07.604206123 +0000 ./public/css/builds/3bb21c5791392549ad71507397ffec7014970862482.css
2022-09-19 00:10:57.884748606 +0000 ./public/js/builds/54496ec544e701b2acbc66d50329ddf713307913833.js
2022-09-19 00:10:57.722733655 +0000 ./public/css/builds/26c359100fb64050bd448d995c24790214970862453.css
2022-09-19 00:10:45.631617772 +0000 ./public/js/builds/67c170ad5951969d1f570df9366d88411663546198.js
2022-09-19 00:10:12.911598063 +0000 ./public/js/builds/a6fc42edcb17017969b90a6aaf31137b38259702029.js
2022-09-19 00:10:11.904505120 +0000 ./public/css/builds/7bea3f1ce06380b997abf9a775fcae5219961676623.css

Which tells me the cache information for bootstrap is where the data is located. I investigated those files and found the settings I saved within them. So they need to be moved to the volume to store the data between container starts.