Get Size of Files in a Linux Directory Modified in the Past 24 Hours
With a system thats regularly creating files on-the-fly it’s important to keep track of the filesizes to monitor disk usage. One of the daily tasks I perform is to track the filesize of files created within the last day by running the following on the command line:
find /directory_name -iname "*.zip" -mtime -1 -printf "%p %k\n"
By running the above you will be presented with a list of all ZIP files modified in the last 24 hours along with the filesize of each. Let me break it down a bit further:
‘find’ is a linux command used to locate files on the Linux system. Used in conjunction with additional parameters it can be a powerful command to find a set of specific files.
This is the directory that we wish to search within. All subdirectories of this specified folder will also be included in the search.
Used to locate all files with a ‘.zip’ extension.
Here we specify the modified date of the files that we wish to return. In this scenario we are saying show all files modified within the last 1 day.
-printf "%p %k\n"
This is the format of the files output to screen. %p correponds to the filename and %k relates to the size of the file in kilobytes. Each file will be separated by a new line (\n).