How To Automatically Organize Similar Type Of Files In Specific Folders

Automatically Organize Similar Type Of Files In Specific Folders

Usually, I like to see my Linux desktop well organized. I have created separate folders for each file types and saved them in the respective folders. There is folder called ‘Entertainment’ to store my movies, videos, and audio files. A folder called ‘Official’ contains all my work related stuffs. ‘Personal’ folder contains my family photos, documents etc. ‘Software’ folder contains all sort of  software stuffs like OS images, applications. I hope everyone has organized their stuffs as the way I do. However, still there are some lazy fellows won’t organize their stuffs. They might keep all sorts of files and folders in a common folder. For those who too lazy to organize their stuffs, here is a command line tool called “Classifier”.

Classifier is simple script written by a fellow Linux user Bhrigu Srivastava using Python programming language. This script will automatically organize your files based on the file extension to different directories. Say for example, it will automatically create a directory called Audio and move all mp3 files in it. Similarly, It moves all zip/tar files to a folder called Archive, films to a folder called Videos and so on. You don’t need to anything. Just install and run this utility, it will take care of everything. To put this simply, Classifier organizes files in your directory instantly, by classifying them into different folders. Sounds useful, isn’t it? Indeed!

Install Classifier

Since it is written using python language, we can easily install it using pip, a python package manager.

On Arch Linux and its derivatives, run the following command to install pip:

sudo pacman -S python-pip

On Debian, Ubuntu, Linux Mint:

sudo apt-get install python-pip

On RHEL, Fedora, CentOS:

sudo yum install python-pip

Or,

sudo dnf install python-pip

On SUSE/openSUSE:

sudo zypper install python-pip

After installing PIP, run the following command to install Classifier.

sudo pip install classifier

Sample output would be:

 Collecting classifier
 Downloading classifier-1.7.tar.gz
 Collecting arrow (from classifier)
 Downloading arrow-0.10.0.tar.gz (86kB)
 100% |████████████████████████████████| 92kB 250kB/s
 Requirement already satisfied: six>=1.10.0 in /usr/lib/python3.6/site-packages (from classifier)
 Collecting python-dateutil (from arrow->classifier)
 Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
 100% |████████████████████████████████| 194kB 389kB/s
 Installing collected packages: python-dateutil, arrow, classifier
 Running setup.py install for arrow ... done
 Running setup.py install for classifier ... done
 Successfully installed arrow-0.10.0 classifier-1.7 python-dateutil-2.6.0

Automatically Organize Similar Type Of Files In Specific Folders Using Classifier

After installing Classifier, go to the directory where you have your files, and run the ‘classifier’ command to organize them automatically, and move them to different folders based on the file extension.

Look at the following screenshot. I have a folder called “test” with different files.

As you see in the above directory, there are different kind of files, such as Zip, ISO, Mp4, Doc, ODt, Xls, JPG etc. Instead of creating folders for each file type, go to this directory (i.e test in our case) and run ‘classifier’ command to organize them automatically in different folders.

cd test/
classifier

You will see output something like below.

Scanning Files
Done!

Your files have been organized in separate folders. Now, go and check the ‘test’ folder. You will see the difference.

As you see in the above screenshot, Classifier has created different directories for each file types and moved them into the respective folders automatically.

You can also classify files of a one directory, and save them in other location. The following command classifies the files of a folder /home/sk/Downloads/, and save them in a folder called /home/sk/ostechnix.

classifier -d /home/sk/Downloads -o /home/sk/ostechnix

Please note that Classifier organizes and moves files only, not directories. And also, you should be careful as there is no undo option.

You can also classify files based on their creation date.

classifier -dt

To classify specific file types, for example .jpg files, run the following command:

classifier -st .jpg -sf "Images"

Here, -st indicates specific file types and -sf indicates specific folder.

The above command will classify the .jpg files and save them in a folder called “Images”.

For more details, check Classifier help section by running the following command:

classifier -h

Classifier is indeed a brilliant script that find and organize different type files to specific folders. If you have large number of different files, It will dramatically reduces the time to organize them. I personally recommend everyone to give it a try. Hope this helps.

That’s all for now folks. I will be soon here with another useful guide. If you find this guide useful, please share it on your social networks and support OSTechNix.

Cheers!

Resource:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

  • Claude

    What are the theme and icons you are using ? And on what desktop ?

    • SK

      I use Arch Linux with Deepin Desktop Environment. Also, I use MATE desktop sometimes.

  • Dan St.André

    Its intuitive that SPECIFIC_TYPES refer to the “file type” from the file name. The –help gives no details about where these files will go if a SPECIFIC_FOLDER is not named.

    Also, it would be nice if one got a report or histogram of the various file types that appear in the folder getting processed.

    Also, it might be nice if one could name a target folder, eg, ~/myClassified, where all processed folders get created and the classified files get copied.

  • Dan St.André

    Your title, “How to Automatically …” lead me to expect that I would learn how to cause ‘classifier’ to run whenever I added files into a folder or connected a USB stick or drive. Sadly, the article did not make any mention of “automaticaly” doing anything.

    I did find ‘classifier’ useful and interesting and will likely find ways to deployit on my writer’s laptop.

    Thanks for the article,
    ~~~ 0;-Dan
    Austin, TX USA