File System Scanner (FSS): Find folder size & search your file system from command line


0 comments

/

By Aditya

/

June 2, 2020

Conveniently finding out folder sizes from the command-line continues to be a challenge, so here is a nifty little tool from Dumblebots to do just that. ag_file_system_scanner (abbreviated to fss) is a CLI application written in Rust for Windows (x86-64) and Linux (x86-64) to do that and more.

By default, fss lists the directories in the current working directory in tree form. A summary of files and symlinks, similar to the dir and ll commands is printed alongside. You can additionally get the last modification times and permissions (POSIX-style only) of each file, symlink. Directory/folder sizes (calculated recursively as the sum of the sizes of all files, directories inside them) can also be optionally shown. If instead, a file/symlink/directory is to be searched for, a string pattern can be specified and one of three search types can be specified, in which case only those entries matching the entry will be shown.

Installation


In this section, we will see how to install and setup ag_file_system_scanner. Since it is written in Rust, it may be installed using Cargo or built from source. Do note that Cargo is required either ways, including when it is built from source. Both these methods are covered in this blog.

Using cargo


If Cargo is ready to run, simply run the following command to install the latest version of fss (v0.1.3 as of writing this blog).

To install a specific version, such as v0.1.3, the command may be modified as follows.

To check if everything works, run the fss command. It should list the directories in the current working directory. We will see its usage in the next section.

Building from source


To build the program from source, clone the ag_file_system_scanner repository using git as shown below.

Then use Cargo to build it in release mode using the following command.

The final program should be listed as ag_file_system_scanner/target/release/fss. For now, the complete path to the program must be given each time it is run. To solve this problem, the binary may be moved to a location on the system's path or the target/release directory may itself be added to the system's path.

To check if everything works, run the fss command. It should list the directories in the current working directory. We will see its usage in the next sectio

Usage


In this section we will see some use cases of fss along with the outputs.

As a start, simply running fss without any arguments lists the directories in the current directory along with an aggregated count of regular files, symlinks and special files.

Linux - Scanning the current working directory
Windows - Scanning the current working directory
Linux - Scanning the root directory
Windows - Scanning C:/

To expand and show files, symlinks and special files, you may provide the --files, --symlinks or --special flags respectively. The shortened versions of each of these flags are -f, -l and -s respectively and they may be used instead of long forms.

Linux - Expanding files, symlinks and special entries
Windows - Expanding files, symlinks and special entries

If fss is to be run on a different directory from the current one, the relative/absolute path can be provided as the first argument (before any flags, if any are provided) and this will start the scan from the given path instead of the current working directory.

Linux - Supplying the path to scan
Linux - Supplying the path to scan

fss can be used to scan and print directories and print them in a tree format. To recursively scan directories, the -r/--recursive flag can be specified. The maximum recursive depth can optionally be provided as well as a non-negative integer after the -r/--recursive flag. To omit the tree format and instead print the entries without indentation (with their absolute paths), the --no-tree flag can be specified.

Linux - Recursively scanning one level down
Windows - Recursively scanning one level down
Linux - Recursively scanning one level down (without tree)
Windows - Recursively scanning one level down (without tree)

To print directory sizes, the -d/--dir-size flags can be used. This recursively goes within the folder and calculates the size as a sum of the sizes of the files and sub-directories. This can cause a performance impact depending on the size and structure of the directory. If the size of a directory could not be calculated, for example due to insufficient privileges while iterating over its contents, then this is indicated.

Linux - Getting directory sizes
Windows - Getting directory sizes

fss can also be used to search the filesystem. Given a search-pattern, the following types of searches can be done -

  • Find entries whose names exactly match the pattern, by using the -S/--search flag
  • Find entries whose names (without the extension) exactly match the pattern by using the --search-noext flag
  • Find entries whose names contain the pattern by using the --contains flag

Each of the above flags can be followed by the search-pattern.

Linux - Searching for a filesystem entry
Windows - Searching for a filesystem entry
Linux - Searching for a file while ignoring the extension
Windows - Searching for a file while ignoring the extension

Apart from the above mentioned features, there are more things that fss can do such as printing permissions, verbose errors etc. To view the complete list of flags supported by fss, you can use the -h/--help flag.

This concludes the brief demonstration of the tool and I hope that you find it useful. You can mail any comments and suggestions to aditya.agarwal@dumblebots.com

Comments


No comments yet

Add a Comment


  • All comments undergo moderation before being published.
  • Please maintain objectivity in your comments and ensure that it is respectful of others.
  • Comments consisting of hate-speech, violence, discrimination or other inappropriate language will be removed.