https://github.com/meekb/bash-files-organizer
Beginner bash script to organize files by extension
https://github.com/meekb/bash-files-organizer
bash bash-script bash-scripting
Last synced: about 2 months ago
JSON representation
Beginner bash script to organize files by extension
- Host: GitHub
- URL: https://github.com/meekb/bash-files-organizer
- Owner: Meekb
- Created: 2025-08-31T19:24:28.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-31T20:15:55.000Z (10 months ago)
- Last Synced: 2025-08-31T21:25:12.092Z (10 months ago)
- Topics: bash, bash-script, bash-scripting
- Language: Shell
- Homepage:
- Size: 52.7 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# File Organizer
A simple Bash script that organizes files by extension.
It moves files from a source folder into subfolders inside a target folder based on their file type.
---
## Table of Contents
- [About](#about)
- [Usage](#usage)
- [Requirements](#requirements)
- [Installation](#installation)
- [Example](#example)
---
## About
The File Organizer helps keep your folders clean by automatically sorting files into subfolders based on their file extensions.
For example: `.txt` files go into a `txt/` folder, `.jpg` files into a `jpg/` folder, and files without an extension are placed in `no-ext-files/`.
**Note:** In this demo, files are *copied* from the unorganized folder so the original files remain intact.
In a real usage scenario, you can switch `cp` to `mv` to actually move the files instead of duplicating them.
---
## Usage
```bash
./files_organizer.sh ./unorganized ./organized
```
Creates subfolders like png, pdf, txt, etc.
Files without an extension are placed in no-ext-files.
#### Safety:
- The script first `copies` the files from `./unorganized` into `./organized`
- Uses `${ORGANIZED:?}` so it will `exit` if the organized path is empty - preventing accidental `rm -rf /*`
## Requirements
- Bash 4+
- macOS 13+ includes this by default
- For older macOS: install via Homebrew
- `brew install bash`
## Installation
### Clone the repository
- `git clone git@github.com:Meekb/bash-files-organizer.git`
- `cd bash-file-organizer`
- Open the `./unorganized` directory and look at the files
- Open `./files_organizer.sh`
- Change the value of `USER` to your username
### Make the script executable
```bash
chmod +x files_organizer.sh
```
## Example
### Before
unorganized/
├── document.txt
├── photo1.jpeg
├── photo2.jpeg
├── report.pdf
├── script
### Run
`./files_organizer.sh ./bash_unorganized ./bash_organized
`
### After
organized/
├── txt/
│ └── document.txt
├── jpeg/
│ ├── photo1.jpeg
│ └── photo2.jpeg
├── pdf/
│ └── report.pdf
└── no-ext-files/
└── script