Martim Gil, 124833
This script implements a recycle bin system for Linux using bash. It allows users to delete files by moving them to a determinated recycle bin directory instead of permanently deleting them. Users can restore files from the recycle bin, see the contents, search for specific files, and empty the recycle bin when needed.
If you want to install the Linux Recycle Bin System, follow these steps: If you are seeing this directly on GitHub, you can download the script by clicking on the "Code" button and selecting "Download ZIP". After downloading, extract the contents of the ZIP file to your desired location. Or, you can clone the repository using Git if you have it installed and configured in your system.
- Open your terminal (Ctrl + Alt + T).
- Navigate to the directory where you want to clone the repository:
cd /path/to/your/directory - Clone the repository using Git:
git clone git@github.com:martimgil/Recycle-Bin-SO.git (using SSH) # or git clone https://github.com/martimgil/Recycle-Bin-SO.git (using HTTPS) - Navigate into the cloned repository:
cd Recycle-Bin-SO - Make the script executable:
chmod +x recycle_bin.sh
- (Optional) Move the script to a directory in your PATH for easier access:
sudo mv recycle_bin.sh /usr/local/bin/recycle_bin
- Verify the installation by running:
recycle_bin --help
- Follow the usage instructions below to start using the recycle bin system.
This script provides two use modes: interactive and command-line.
If you want to use the interactive mode, you need to simply run the script without any arguments:
./recycle_bin.shor, if you moved it to your PATH:
recycle_binThis will launch in you terminal an interactive menu where you can choose options to delete files, restore files, view recycle bin contents, search for files, and empty the recycle bin. You can navigate between each option by entering the corresponding number.
If you want to use the command-line mode, you can use the following commands:
- To delete a file:
./recycle_bin.sh delete /path/to/file
You can delete more than on file at once by specifying multiple files paths separated by spaces.
- To restore a file
./recycle_bin.sh restore filename (or id)
If a conflict occurs during the restoration process (e.g., a file with the same name already exists in the original location), the script will prompt you to choose whether to overwrite the existing file, rename the restored file, or skip the restoration for that specific file.
- To view recycle bin contents:
./recycle_bin.sh list
You can also use the detailed view option in order to see more information about each file. You only need to add the --detailed flag at the end of the command.
bash ./recycle_bin.sh list --detailed
- To search for a file in the recycle bin:
./recycle_bin.sh search filename
- To empty the recycle bin:
./recycle_bin.sh empty
You can add the --force flag at the end of the command in order to skip the confirmation prompt.
bash ./recycle_bin.sh empty --force
You can also inform the script to only delete files with a determinated pattern in their name or a unique id by simply adding as an argument.
bash ./recycle_bin.sh empty pattern_or_id
You can view statistics about the recycle bin and see some information such as total number of files, total directories, newest and oldest files, total storage used, and average file size by using the following command:
./recycle_bin.sh statisticsWhen you want to run the automatic cleanup process to remove files that have exceeded the retention period defined in the configuration file, you can use the following command:
./recycle_bin.sh auto_cleanupIf you want to check the current size of the recycle bin against the maximum size specified in the configuration file and remove the oldest files if necessary, you can use the following command:
```bash
./recycle_bin.sh check_quotaIf recycle bin exceeds the quota, it will perform the auto cleanup action.
You can also use the file preview feature to see a preview of a file's content before deletion:
./recycle_bin.sh preview /path/to/file_or_directoryYou can also use the --help flag to see all available commands and options:
./recycle_bin.sh --helpYou also have the verbose mode available by adding the --verbose flag at the end of any command. This will provide more detailed output about the operations being performed.
./recycle_bin.sh delete /path/to/file --verbose- Move files to recycle bin instead of deleting
- Restore files from recycle bin
- View recycle bin contents
- Search for files in recycle bin
- Empty recycle bin
- Handle name conflicts during restoration
- Automatic metadata backup and recovery system
- Show statistics about recycle bin
- Automatic cleanup based on retention period
- Quota management for recycle bin size
- File preview before deletion
- Automatic metadata backup and recovery system
The recycle bin directory is set to ~/.recycle_bin by default. You can change this by modifying the RECYCLE_BIN_DIR variable in the script.
RECYCLE_BIN_DIR="$HOME/.recycle_bin"You can set it to any directory you prefer. Just make sure the script has the necessary permissions to read and write in that directory.
You can also customize other settings in the script, such as log file location, date format, etc. You have a config file where you can change some settings such as the size limit of the recycle bin, or the time limit for keeping files in the recycle bin.
During the testing phase, no significant issues were encountered. However, users may experience unexpected behavior in certain edge cases or specific system configurations.
[1] "Correct locking in shell scripts," Unix & Linux Stack Exchange, [Online]. Available: https://unix.stackexchange.com/questions/22044/correct-locking-in-shell-scripts. [Viewed: 31 Out. 2025].
[2] "Linux Tips – File Locking in Bash," Tiger Computing Ltd, [Online]. Available: https://www.tiger-computing.co.uk/linux-tips-file-locking-bash/. [Viewed: 31 Out. 2025].
[3] "Tutorial de symlink no Linux: como criar e remover um link simbólico," freeCodeCamp, [Online]. Available: https://www.freecodecamp.org/portuguese/news/tutorial-de-symlink-no-linux-como-criar-e-remover-um-link-simbolico/. [Viewed: 31 Out. 2025].
[4] "Linux: How to Find the Target of a Symbolic Link," LabEx, [Online]. Available: https://labex.io/pt/tutorials/linux-how-to-find-the-target-of-a-symbolic-link-392854. [Viewed: 31 Out. 2025].
[5] "df - Visão Geral," GuiaLinux, [Online]. Available: https://guialinux.uniriotec.br/df/. [Viewed: 31 Out. 2025].
[6] "How to empty/truncate a file on Linux that already exists and is protected (immutable)?," Stack Overflow, [Online]. Available: https://stackoverflow.com/questions/2423281/how-to-empty-truncate-a-file-on-linux-that-already-exists-and-is-protected-i. [Viewed: 31 Out. 2025].
[7] "bc command in Linux with examples," GeeksforGeeks, [Online]. Available: https://www.geeksforgeeks.org/linux-unix/bc-command-linux-examples/. [Viewed: 31 Out. 2025].









