Creating a file and folder inventory
Let's start with something basic – a script that reports in terms of folder and file inventory. As simple as this is, this type of script can use a variety of different tools, including commands, built-in CLI applications, loops – there are a lot of choices to be made. We're going to do this in the simplest way possible – by taking advantage of our knowledge of commands and CLI applications. We're going to create a couple of different versions of this script as it can be used in a variety of different ways – for example, as input into future shell scripts or as plain text reporting tools.
How to do it…
Let's start by creating a script that's just going to tell us the following:
- The number of folders in the current folder and their sizes, sorted by size in descending order
- The number of files in the current folder and their size, sorted by size in descending order