Using gtrash with Termux and proot desktops on Android
This is another post about using my phone as a desktop replacement and the various tools I use. See all the posts in this series here
gtrash is a command line utility that moves files to the system trash can instead of completely removing. I see this as an addition tool to the standard rm command. For most files I want to move them to the system trash so I can restore as necessary, then purging all the files on occasion.
Using Termux, I often work in a proot desktop while in Dex-mode on my phone for the full Linux desktop experience. Using gtrash is a handy tool that will prevent accidental file deletions.
Git URL: https://github.com/umlx5h/gtrash
Termux installation
There is not an official Termux package. But, there is a arm64 binary that works in Termux and can be dropped into my $PATH.
Download from the releases, chmod +x, and place into your preferred $PATH directory.
Aliases
I have multiple aliases configured to help with remembering to use this tool. First, I use this one as a reminer:
alias rm="echo -e 'If you want to use rm really, then use \"rmf\" instead. Remember, we are using \"gtrash\" now.'; false"
This alias prints a note when using rm to use rmf if I really want to remove a file. Then, it reminds me that I’m using gtrash on most occasions.
In order for rmf to work, I need another alias. This is the alias I have on my phone in [[Termux]], but the process is the same by passing the absolute path to rm. I can’t just alias to rm as it will cause a loop with the message above.
alias rmf='/data/data/com.termux/files/usr/bin/rm -i --preserve-root'
In this alias I am also passing the flags for interactive mode (confirm I want to delete).
The last alias is for the put command in gtrash. Instead of typing gtrash put anytime I want to use it, I just alias it to gm. This is similar enough to rm I should be able to remember it.
alias gm='gtrash put'
Then:
funsave gm
funcsave rm
funcsave rmf
Usage
Delete
To delete a file:
gtrash put foo
or:
gm foo
Removing directories does not require the -r flag.
Summary
To see how many files are in the trash, storage use, find the path for the trash can, etc.:
gtrash summary
Restore
There is a built in TUI for restoring files. Run with:
gtrash restore
Empty trash
To remove all files in the trash can:
gtrash find --rm