perplexity-cli
🧠 A simple command-line client for the Perplexity API. Ask questions and receive answers directly from the terminal! 🚀🚀🚀
😎 Safe-rm: A drop-in and much safer replacement of bash rm with nearly full functionalities and options of the rm comm…
git clone https://github.com/kaelzhang/shell-safe-rm.gitkaelzhang/shell-safe-rm _______ _______ _______ _______ ______ __ __
| || _ || || | | _ | | |_| |
| _____|| |_| || ___|| ___| ____ | | || | |
| |_____ | || |___ | |___ |____| | |_||_ | |
|_____ || || ___|| ___| | __ || |
_____| || _ || | | |___ | | | || ||_|| |
|_______||__| |__||___| |_______| |___| |_||_| |_|
Safe-rm, a drop-in and much safer replacement of the unix rm command with ALMOST FULL features of the original rm.
The project was initially developed on Mac OS X and has been continuously used by myself since then, with later testing conducted on Linux. If you encounter any issues during use, please feel free to submit an issue.
safe-rm, the files or directories you choose to remove will be moved to the system Trash instead of simply deleting them. You could put them back whenever you want manually.
safe-rm will use AppleScript to delete files or directories as much as possible to enable the built-in "put-back" capability in the system Trash bin.SAFE_RM_TRASH_PER_MOUNT)For those implemented options, safe-rm will act exactly the same as the original rm command:
| Option | Brief | Description |
|---|---|---|
-i, --interactive |
Interactive | Prompts you to confirm before removing each file |
-I, --interactive=once |
Less Interactive | Prompts only once before removing more than three files or when recursively removing directories |
-f, --force |
Force | Removes files without prompting for confirmation, ignoring nonexistent files and overriding file protections |
-r, -R, --recursive, --Recursive |
Recursive | Removes directories and their contents recursively. Required for deleting directories |
-v, --verbose |
Verbose | Displays detailed information about each file or directory being removed |
-d, '--directory' |
Remove Empty Directories | safe-rm can check and only remove empty directories specifically with this flag |
-- |
End of Options | Used to indicate the end of options. Useful if a filename starts with a - |
Combined short options are also supported, such as
-rf, -riv, -rfv, etc
The BSD-only options -P (overwrite), -W (undelete), and -x (don't cross mount points) are intentionally not supported, since they have no meaning for a trash-based tool; safe-rm reports them as an illegal option rather than silently ignoring them.
Add an alias to your ~/.bashrc script,
alias rm='/path/to/bin/rm.sh'
and /path/to is where you git clone shell-safe-rm in your local machine.
If you have NPM (NodeJS) installed (RECOMMENDED):
npm i -g safe-rm
Or by using the source code, within the root of the current repo (not recommended, may be unstable):
# If you have NodeJS installed npm link # If you don't have NodeJS or npm installed make && sudo make install # For those who have no `make` command: sudo sh install.sh
Installing safe-rm will put safe-rm in your /bin directory. In order to use
safe-rm, you need to add an alias to your ~/.bashrc script and in all yours
currently open terminals, like this:
alias rm='safe-rm'
After installation and alias definition, when you execute rm command in the Terminal, lines of below will be printed:
$ rm
safe-rm
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
which helps to tell safe-rm from the original rm.
First remove the alias rm=... line from your ~/.bashrc file, then
npm uninstall -g safe-rm
Or
make && sudo make uninstall
Or
sudo sh uninstall.sh
Since 3.0.0, you could create a configuration file located at ~/.safe-rm/config in your $HOME directory, to support
safe-rm to permanently delete files and directories that are already in the trashsafe-rm to use AppleScriptFor the description of each config, you could refer to the sample file here
# You could cp -r ./.safe-rm ~/
If you want to use a custom configuration file
alias="SAFE_RM_CONFIG=/path/to/safe-rm.conf /path/to/shell-safe-rm/bin/rm.sh"
Or if it is installed by npm:
alias="SAFE_RM_CONFIG=/path/to/safe-rm.conf safe-rm"
Put-back Functionality on MacOS (MacOS only)In ~/.safe-rm/config
export SAFE_RM_USE_APPLESCRIPT=no
By default, on MacOS, safe-rm uses AppleScript as much as possible so that removed files could be put back from system Trash app.
export SAFE_RM_TRASH=/path/to/trash
Note (MacOS): setting a custom SAFE_RM_TRASH makes safe-rm move files with mv instead of AppleScript, which disables the Finder "Put Back" capability (the same trade-off as SAFE_RM_USE_APPLESCRIPT=no). You can still drag items back out of the trash folder manually.
Whether a trashed item can be restored depends on which path safe-rm uses:
| Situation | Mechanism | Restorable |
|---|---|---|
| MacOS, default system trash | AppleScript (Finder) | ✅ Finder Put Back |
MacOS, custom SAFE_RM_TRASH, SAFE_RM_USE_APPLESCRIPT=no, or a symlink target |
mv |
❌ no metadata (drag back manually) |
| Linux | mv + a FreeDesktop .trashinfo |
✅ via the desktop trash's Restore |
By default, safe-rm moves everything into the home trash. Removing a file that
lives on another filesystem/mount (an external drive, a separate partition) then
becomes a slow cross-device copy instead of an instant move.
When SAFE_RM_TRASH_PER_MOUNT is enabled, safe-rm routes each target to a
trash directory on the same filesystem, so the move stays instant:
export SAFE_RM_TRASH_PER_MOUNT=yes
It follows the FreeDesktop.org Trash specification for mount-point
trash directories: it uses $topdir/.Trash/$uid when the volume has an
administrator-created .Trash directory that passes the spec's checks (a real
directory, with the sticky bit, not a symlink), otherwise it creates and uses
$topdir/.Trash-$uid. Files trashed there record a Path relative to the
volume's top directory, so standard desktop trash tools can still restore them.
Pay ATTENTION that:
SAFE_RM_TRASH_PER_MOUNT starts with y/Y.SAFE_RM_TRASH consolidates everything there and disables per-mount routing.safe-rm falls back to the home trash.export SAFE_RM_PERM_DEL_FILES_IN_TRASH=yes
export SAFE_RM_SCOPE="$HOME"
When SAFE_RM_SCOPE is set, safe-rm only removes targets under that directory.
Targets outside the configured scope will be skipped and reported as unsafe.
For example:
SAFE_RM_SCOPE="$HOME" safe-rm -rf / # rm: target '/' skipped, unsafe directory scope
You could also use a relative scope such as .:
SAFE_RM_SCOPE=. safe-rm -rf ./foo SAFE_RM_SCOPE=. safe-rm -rf ../ # rm: target '../' skipped, unsafe directory scope
rm dir -rf)GNU rm (most Linux distros) accepts options anywhere on the command line, so rm dir -rf works like rm -rf dir. BSD rm (MacOS) does not — it stops parsing options at the first operand and would treat -rf as a filename.
By default, safe-rm mirrors the host's real rm:
To override the auto-detection (e.g. on Alpine/BusyBox where rm does not permute):
# Force GNU-style permutation export SAFE_RM_OPTIONS_ANYWHERE=yes # Force BSD-style strict ordering export SAFE_RM_OPTIONS_ANYWHERE=no
-- always terminates option parsing in either mode.
If you want to protect some certain files or directories from deleting by mistake, you could create a .gitignore file under the "~/.safe-rm/" directory, you could write .gitignore rules inside the file.
If a path is matched by the rules that defined in ~/.safe-rm/.gitignore, the path will be protected and could not be deleted by safe-rm
For example, in the ~/.safe-rm/.gitignore
/path/to/be/protected
And when executing
$ safe-rm /path/to/be/protected # or $ safe-rm /path/to/be/protected/foo # or $ safe-rm -rf /path/to/be/protected/bar # An error will occur
But pay attention that, by adding the protected pattern above, if we:
$ safe-rm -rf /path/to
To keep the performance of safe-rm and avoid conducting unnecessary file system traversing, this would not prevent /path/to/be/protected/foo from removing.
Pay ATTENTION that:
".gitignore" inside the "~/.safe-rm/" directory, it requires git to be installed in your environment".gitignore" patterns apply to the root directory ("/"), which means that the patterns defined within it need to be relative to the root directory./ in the protected rules file, or everything will be protectedmore like this
🧠 A simple command-line client for the Perplexity API. Ask questions and receive answers directly from the terminal! 🚀🚀🚀
Comprehensive analytics dashboard for AI coding agents — Cursor, Windsurf, Claude Code, VS Code Copilot, Zed, Antigravi…
search projects, people, and tags