A "rm" replacement with soft-deletes, config-based deletion, debug information, and saner defaults.
| Feature | 2rm | trash-cli | shell-safe-rm | trashy | gomi | trash |
|---|---|---|---|---|---|---|
| Config-based deletion | ✅ | ❌ | ✅ ^1 | ❌ | ❌ | ❌ |
| Supports dry runs | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| GNU "rm" compatibility | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Comes with "man" pages | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ |
- ^1 - Shell safe rm supports configuring the soft delete backup location and protected files, but does not support any of the other config options provided by 2rm
-iInteractively prompt before each deletion request-IPrompt if deleting more than the interactive threshold of files (default 3)-r,-R,--recursiveRecursively delete a directory of files-v,--verboseEmit additional verbose information-d,--dirOnly delete empty directories--helpDisplay help information (without deletion)--versionDisplay version information (without deletion)--interactive[=WHEN]Interactive with a custom threshold- Never Prompt:
never,no,none - Prompt Once:
once - Always Prompt:
always,yes
- Never Prompt:
--overwriteOverwrite the disk location location with zeros-H,--hardDo not soft-delete file-S,--softSoft delete a file and store a backup (default/tmp/2rm)--silentDo not print out additional information priduced by 2rm. This is useful for scripting situations--dry-runPerform a dry run and show all the files that would be deleted--bypass-protectedUsing this flag will allow you to delete a file protected by the 2rm config--notifySend a system notification once deletion is complete--forceBypass 2rm protections
--one-file-systemDo not allow cross-file-system deletes-f,--forceBypass protections (full GNU "rm" compatibility)
I have done this so that you can't accidentally add a space and remove your root directory with a typo such as
$ rm -rf ./directory /
>(yes I know that you have to use --no-preserve-root and I have removed that too)
You no longer have to add the -r flag when deleting a directory
(although you still can if you want to)
By default, the program will soft delete your files by adding a hard link to the file in the /tmp/2rm directory.
This means that the files underlying INode is not freed, and can be recovered from the /tmp/2rm directory if you deleted the wrong file by mistake.
By using the /tmp directory, the operating system will automatically hard delete files upon restart.
Sometimes you want to hard delete a file/directory every time that you run the rm command e.g. you probably want your node_modules hard deleted every time and never want to soft delete them.
In this case, you can modify your ~/.local/share/2rm/config.yml file to always hard delete node_modules.
When deleting a file with the linux inbuilt rm command, the file is still available on disk.
Meaning that the file can still be recovered by any sufficiently technical user.
This can be problematic when dealing with sensitive files such as private keys that if leaked could lead to catastrophic consequences.
You can overwrite a files disk location (rendering it unrecoverable) by using the --overwrite flag.
2rm will still soft-delete the file by default, but the soft-deleted file will be completely filled with zeros.
I made the decision that overwritten files will still be soft deleted because it might be useful for timestamp logging/auditing purposes. E.g. "when did I overwrite xyz"
If you want to fully delete a file from disk and the file system use both the --overwrite and --hard flags.
You can specify what directories are soft-deleted anb hard-deleted by using the ~/.local/share/2rm/config.yml file.
This is useful because you usually don't want to soft-delete directories such as node_modules, and cache files.
Therefore, instead of constantly calling the GNU "rm" command or constantly passing in the --hard flag, you can
set up a 2rm config file to automatically hard delete certain paths.
# user specific: ~/.local/share/2rm/config.yml # system wide: /etc/2rm/config.yml # defaults to /tmp/2rm/ if not specified # in the config file # any files that are soft deleted will be # backed up in the `backups` directory backups: /tmp/2rm/ # whenever files matching these paths are deleted # the disk location will be overwritten with zeros overwrite: # when deleting ssh keys, we always want to # overwrite them with zeros to protect # against attackers recovering the production # ssh keys - ".ssh/*" hard: - "node_modules/" - "target/" - ".angular/" - ".next/" - ".cache/" # always soft delete backup files, # regardless of it they are configured # for a hard delete soft: - "*.bak" # do not allow deleting these files/directories # without using the `--bypass-protected` flag this # does not make the file protected at the system level # through other tools, but it does protect against # accidental deletion through 2rm protected: - ".ssh/" # when using the -I flag without any arguments, the user will be prompted # for confirmation before deleting each file if the number of files is # greater or equal to this threshold # default is 3 files/directories interactive: 10
An error that would have been thrown by a traditional "rm" command such as the GNU "rm" implementation.
An error was thrown during 2rm functionality (e.g. deleting a protected file)