How to organize files in Linux by classifying them into different directories

As a technical writer, I deal with a lot of files in my job - sometimes I'm cropping images, other times I'm playing with .zip and .deb files. Not to mention PDFs and other document types we all deal with in our daily computer work.

At present my Downloads directory contains over a thousand items, including directories, files, and images. So, I was looking for a tool that could organize at least files by classifying them into different directories. And I found one - Classifier.

In this article, we will discuss how to install the tool and how you can use it. But before we do that, it is worth mentioning that all commands and instructions mentioned in this article have been tested on Ubuntu 20.04 LTS.

How to install and use Classifier

According to official documentation, Classifier organizes "files in your current directory, by classifying them into folders of music, pdfs, images, etc."

Here's how you can install the tool:

pip install classifier

In case 'pip' isn't installed, you can install it using the following command:

sudo apt-get install python-pip

Once Classifier is installed, you can use it by running the following command:

classifier

The aforementioned command should be either run inside the directory whose contents you want to organize, or by passing the complete path to that directory as value to the -d command line option.

For example, here's the directory whose contents I wanted to organize:

Existing directories

So, I executed the following command:

classifier-command

See, how Classifier created new directories and moved some of the files there.

New directories by file class

So far, so good. But there are still files that have not been moved. Well, that's because Classifier works with file extensions, and most of the files that were left out don't have an extension.

But what about the .c file, you may ask? Well, all I could conclude was that the tool takes no action on source files, but there are options (-st and -sf) you can use to tell Classifier what kind of files to move to what kind of directories.

For example, I used the following command to move all .c, .cpp, and .py files to a directory called "source-files".

classifier-customize

For more information, head to the tool's GitHub page.

Leave a Comment

*