A lightweight and simple Bash-based recycle bin tool that safely manages file deletion in a Linux environment.
Instead of permanently deleting files with rm, this script moves them into a hidden ~/.recycle directory, allowing for easy recovery and safer workflows.
This project was made for my Systems Programming Class, and provided me with great skillsets in Bash scripting, Linux commands, file management, and flag handling.
- Safe deletion: Moves files and directories into
~/.recycleinstead of permanently deleting them. - List mode (
-l): Lists the current contents of the recycle bin. - Purge mode (
-p): Purges all recycled files. - Help menu (
-h): Displays usage information. - Input validation & defensive coding:
- Detects invalid flags
- Prevents combining incompatible options
- Warns about missing files
- Provides descriptive error messages
- rbin.sh: Script for managing the recycle bin.
- /home//.recycle: Separate recycle bin for each user on the system.
Usage: rbin.sh [-hlp] [list of files] -h: Display this help; -l: List files in the recycle bin; -p: Empty all files in the recycle bin; [list of files] with no other flags, these files will be moved to the recycle bin.
Move files to the recycle bin:
./rbin.sh file1.txt notes.pdfList recycled files:
./rbin.sh -lPurge all recycled files:
./rbin.sh -pShow help:
./rbin.sh -hThis project emphasizes safe Linux file operations:
- Avoids immediate irreversible deletion (
rm) - Ensures directories exist before using them (
mkdir -p) - Validates user input and flags
- Displays warnings for non-existent files
- Uses per-user recycle directories to prevent permission issues
This approach mirrors real-world practices used in:
- Secure file handling
- Forensics tooling
- Backup & recovery systems
- User-space safe deletion utilities
- Bash
- GNU Coreutils (
mv,rm,ls,mkdir) - getopts for CLI parsing
- Linux home directory structure
-
Initial state: The working directory contains three example files and
rbin.sh. The recycle bin (~/.recycle) does not yet exist. -
Help message: Running
./rbin.sh -hcorrectly displays usage information. -
Invalid option: Running
./rbin.sh -qshows an error for an unknown flag and prints the usage message. -
Sending files to recycle bin: Running
./rbin.sh example1.txtmoves the file into~/.recycle, automatically creating the folder. Running./rbin.sh example2.txt example3.txtmoves the remaining examples. -
Listing recycle bin:
./rbin.sh -lshows the files currently stored in the recycle bin. -
Emptying the bin:
./rbin.sh -premoves the entire.recycledirectory, andls ~/.recycleconfirms it is gone.