Bash: deep listing the most recently modified files in a directory

Finding the most recently modified files in a directory can be extremely beneficial when you have been making changes in files throughout the directory structure as part of a work effort, and now need to go back and pinpoint everything that was changed.

This command will provide you the 10 most recently modified files, excluding any hidden directories that start with a period.

find . -type f -not -path '*/[@.]*' -printf "\n%T@\t%AD %AT %p" | sort -r | cut -d$'\t' -f2- | head -n10

The ‘-not -path’ argument is to exclude special directories that start with a period (e.g. .git).

The “%T@” in the printf makes the first column a timestamp that allows for machine sorting, but doesn’t help the human-readable output, so we cut it before display.

 

REFERENCES

tecmint, find and sort files by modification date

superuser.com, linux find and sort by date

NOTES

The cut command syntax for specifying a delimeter -d with a special character is to use the dollar sign

cut -d$'\t' -f2-