Search code examples
linuxbashshellredhat

Redhat Shellscript Displaying "count" of files modified in the last 5 days


I am trying to display the count/number of files that was saved/modified last 5 days. In other words, I just need to know the count of 5-day old messages.

I searched google and it talks about using find

For me, I would like to use ls command. I am able to count using ls | wc -l but that does not exclude/filter files by age(last modified)

I tried -mtime +5 or -ctime +5 but still can't get it right.

Thank you.


Solution

  • If you want to find the count of files modified in the last 5 days (understood as last 120 hours) starting from the root directory /, I would try:

    find / -type f -mtime -5 | wc -l
    

    The command wc -l counts the number of lines of output. Error messages are not included in that count.

    If you want to limit your search to a part of the tree structure, v.gr. your $HOME directory, change / by $HOME.

    If you have symlinks in your tree structure, you will need to add some options like -L to the find command