Skip to content

mtognela/t

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

T - A minimal suckless trash command

A lightweight bash script that provides a safe alternative to rm by moving files to a trash directory instead of permanently deleting them.

Features

  • Move files to trash instead of permanent deletion
  • Preserves original directory structure
  • Easy file restoration
  • Automatic cleanup of files older than 30 days
  • Lightweight and fast
  • No dependencies beyond standard Unix tools

Installation

Quick Install

# Download the script
curl -o ~/.t.sh https://raw.githubusercontent.com/mtognela/t/master/t 

# Make it executable
chmod +x ~/.t.sh

# Add to your shell configuration
echo "source ~/.t.sh" >> ~/.bashrc

# Reload your shell
source ~/.bashrc

# Initialize trash directory
st

Manual Install

  1. Clone or download this repository
  2. Copy t.sh to your home directory (or anywhere you prefer)
  3. Add the following line to your ~/.bashrc or ~/.zshrc:
    source /path/to/trash.sh
  4. Reload your shell configuration:
    source ~/.bashrc
  5. Initialize the trash directory:
    st

Usage

Available Commands

t <file1> [file2 ...]

Move files to trash (similar to rm)

t myfile.txt
t file1.txt file2.txt dir/

rt <file1> [file2 ...]

Restore files from trash to current directory

rt myfile.txt
rt file1.txt file2.txt

lt

List all files in trash with details

lt

ct

Clean trash - permanently delete ALL files in trash

ct

Warning: This permanently deletes everything in trash!

coldt

Clean old trash - automatically delete files older than 30 days

coldt

st

Setup/initialize trash directory

st

How It Works

File Organization

When you trash a file, the script:

  1. Converts the file path to an absolute path
  2. Recreates the full directory structure inside ~/.t/
  3. Moves the file to preserve its original location

Example:

Original: /home/user/projects/myapp/file.txt
Trashed:  /home/user/.t/home/user/projects/myapp/file.txt

This approach:

  • Prevents filename conflicts
  • Makes it easy to know where files came from
  • Allows for straightforward restoration

Automatic Cleanup

The coldt function removes files that have been in trash for more than 30 days using the find command with -mtime +30.

Optional: Set up automatic cleanup with cron:

# Edit crontab
crontab -e

# Add this line to run cleanup daily at 3 AM
0 3 * * * source ~/.trash.sh && coldt

Configuration

Change Trash Directory

Edit the TRASH_DIR variable at the top of the script:

TRASH_DIR="$HOME/.t"  # Default
# or
TRASH_DIR="$HOME/.t"
# or
TRASH_DIR="/tmp/t"

Adjust Cleanup Age

Modify the -mtime value in the coldt function:

find "$TRASH_DIR" -type f -mtime +30 -delete  # 30 days (default)
find "$TRASH_DIR" -type f -mtime +7 -delete   # 7 days
find "$TRASH_DIR" -type f -mtime +90 -delete  # 90 days

Safety Tips

Don't Alias rm

This script is not intended to be alias to rm, instead, train yourself to use t directly.

Regular Cleanup

Remember to run coldt periodically or set up the cron job to prevent trash from consuming too much disk space.

Emergency Recovery

If you accidentally run ct, your files are gone permanently. Always double-check before using this command.

Upstream

Upstream git repo at:

   git clone https://github.com/mtognela/t.git

License

This project is licensed under the GNU General Public License v2.0 - see the LICENSE.md file for details.

Credits

Author: Mattia Tognela

Copyright: (C) 2025 Mattia Tognela

Created as a lightweight, dependency-free alternative to permanent file deletion for Unix-like systems. This tool was born from the need for a simple, transparent trash system that works entirely in bash without external dependencies.

About

A minimal suckless trash command

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages