Member-only story

How to Organize Files Using a Shell Script

Rakan Khaled
4 min readAug 27, 2024
Photo by Leiada Krozjhen on Unsplash

Have you ever had your Linux/Unix Desktop looking like as if a hurricane Katrina decided to pay you a quick visit?

Wouldn’t it be nice if it was all nice and tidy?

LOOK NO MORE! today I’m going to help you achieve that!

We’re going to be using a shell script, where we can automate the organization of files based on criteria like file type, date modified, size, and more.

This not only saves time but also reduces the risk of manual errors (especially when we haven't had our 3rd cup of coffee yet!).

Step-by-Step Guide to Writing a File Organization Shell Script

Below is a simple shell script example that organizes files in a directory based on their file type. The script will:

  1. Create folders for each file type (e.g., Documents, Images, Videos, etc.).
  2. Move files into their respective folders based on their extension.

Here’s the script Script, It will organize files by type

#!/bin/bash

# Define the directory to organize. Default to the current directory.
DIR=${1:-.}

# Define file type extensions and their corresponding folder names…

--

--

Rakan Khaled
Rakan Khaled

Responses (1)