DirSize: The Command Line Directory Reporting Tool
DirSize is a directory reporting tool. It recursively scans the provided (or current) directory, and reports the number of files and director sizes of each subdirectory present. It also defaults to sorting by by directory size, but there are other options.
Lastly, it's written in Java and packaged into a single executable JAR file. All of the dependencies built in so it should run anywhere. Howver, I've only tested it on Windows 10 and Ubuntu.
One of the interesting things about DirSize is it shows a visual representation of the file sizes of counts. I call this a SizeMap or FilesMap and it's the area to the right of the output. If you sort by size (default or -ss) or directories (-sd) is will show the SizeMap. If sorted by file counts (-sf) the map will change to show a visual representation of the number of files per subdirectory, sorted from high to low.
Usage:
java -jar dirsize.jar [-D] [-x <filename>] [-ss|-sf|-sd][-r] [-c width] [-v] [-h|?] [Directory]
Option | Description |
---|---|
-D | Run program in debug mode. This will display quite a bit of information on the program as it's running. I usually use this as I debug the program, but if you wish to get a bit more insight into what's going on, go for it. |
-x FileName | Export the results as a CSV to the file provided |
-ss | Sort output by the directory sizes. This is the default |
-sf | Sort output by the number of files |
-sd | Sort output by directory name |
-r | Reverse the sort order. Ascending or descending will depend on the sorting type selected. File and Size sorting will be displayed in ascending order. Directory sorting will be displayed alphabetically in reverse order |
-e | Suppress error display. Normally, issues with scanning are display at the end of the output. With this switch enabled, this list will be suppressed. Scanning errors usually happen when DirSize does not have permission to a file or folder although there can be other reasons |
-c Width | Set By default, DirSize uses the full console width. However, you can change this. Useful if you have a very wide console display |
-v | Simply display the program version and exit |
-h | -? | Display the program help |
java -jar dirsize.jar
Display a size sorted report from the current directory
java -jar dirsize.jar -sd C:\Apps
Display a directory name sorted report from the C:\Apps directory
java -jar dirsize.jar -c 80 -sf /home/jimbob
Display a file number sorted report from the jimbob's home dir using 100 columns
java -jar dirsize.jar -x $HOME/usr-output.csv /usr
Output the directory report of /usr
into a CSV file in my home directory
I would encourage anyone with a supported Linux platform to use snap. See Snapcraft Homepage for more information. You can download, install, and keep DirSize up to date automatically by installing the snap. You don't even have to have java as it's bundled within the snap virtual machine. Install via:
sudo snap install dirsize (Assuming snapd is installed)
Note:
Snap applications run in a container and by default do not have rights to see files on the filesystem outside of this 'sandbox.' In order to use DirSize, it needs to be able see file names and sizes. The interface system-backup
gives it that right. Therefore, to use dirsize , you need to allow it to read file information by executing:
sudo snap connect dirsize:system-backup
If you change your mind, you can remove this permission by executing:
sudo snap disconnect dirsize:system-backup
I'm making this freely available in the hope that others may find this useful. Please let me know if you have any issues, thoughts or suggestions for enhancements by mailing dirsize@fross.org.
The MIT License
Copyright (C) 2011-2020 by Michael Fross
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.