Find number of files in directory that has been created specific year

datefilesfind

I would like to get the number of files in a directory and its sub-directories (recursively) that was created year 2016. I only care about files that has a specific file ending, for example ".txt". How can I achieve this in the terminal?

Best Answer

With GNU find:

find /some/dir -type f -name '*.txt' -printf '%CY\n' | grep -Fxc 2016

This counts the files with a ctime in 2016 in the local timezone. Please note that ctime is not the creation time of the files, but it's about the best approximation of it you can hope for with standard UNIX semantics.

If you want to match modification time you can use -printf '%TY\n' above instead of -printf '%CY\n'.

Related Question