{"id":14110688,"url":"https://github.com/kaelzhang/shell-safe-rm","last_synced_at":"2025-04-14T11:24:33.896Z","repository":{"id":7505109,"uuid":"8855043","full_name":"kaelzhang/shell-safe-rm","owner":"kaelzhang","description":"😎 Safe-rm: A drop-in and much safer replacement of bash rm with nearly full functionalities and options of the rm command! Safe-rm will act exactly the same as the original rm command.","archived":false,"fork":false,"pushed_at":"2025-04-05T14:36:10.000Z","size":123,"stargazers_count":468,"open_issues_count":3,"forks_count":37,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T03:16:13.607Z","etag":null,"topics":["alternative","bash","command","command-line","linux","mac","macos","macosx","remove","replacement","rm","safe-rm","shell","trash"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-03-18T13:45:53.000Z","updated_at":"2025-04-05T14:36:13.000Z","dependencies_parsed_at":"2024-12-20T17:04:26.373Z","dependency_job_id":"611383e6-3508-49db-8629-6265323d62e7","html_url":"https://github.com/kaelzhang/shell-safe-rm","commit_stats":{"total_commits":104,"total_committers":5,"mean_commits":20.8,"dds":0.375,"last_synced_commit":"06c25dd42202b6fcd59e81ccb8aec9f65654dd5d"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fshell-safe-rm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fshell-safe-rm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fshell-safe-rm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fshell-safe-rm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/shell-safe-rm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248658375,"owners_count":21140931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alternative","bash","command","command-line","linux","mac","macos","macosx","remove","replacement","rm","safe-rm","shell","trash"],"created_at":"2024-08-14T10:02:57.338Z","updated_at":"2025-04-14T11:24:33.859Z","avatar_url":"https://github.com/kaelzhang.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# safe-rm\n\n```\n _______  _______  _______  _______         ______    __   __\n|       ||   _   ||       ||       |       |    _ |  |  |_|  |\n|  _____||  |_|  ||    ___||    ___| ____  |   | ||  |       |\n| |_____ |       ||   |___ |   |___ |____| |   |_||_ |       |\n|_____  ||       ||    ___||    ___|       |    __  ||       |\n _____| ||   _   ||   |    |   |___        |   |  | || ||_|| |\n|_______||__| |__||___|    |_______|       |___|  |_||_|   |_|\n```\n\n[![Build Status](https://github.com/kaelzhang/shell-safe-rm/actions/workflows/nodejs.yml/badge.svg)](https://github.com/kaelzhang/shell-safe-rm/actions/workflows/nodejs.yml)\n\n[Safe-rm][safe-rm], a drop-in and much safer replacement of the unix [`rm`][rm] command with **ALMOST FULL** features of the original [`rm`][rm].\n\nThe 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](https://github.com/kaelzhang/shell-safe-rm/issues/new).\n\n## Features\n- Supports both MacOS and Linux with full test coverage.\n- Using `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.\n  - On MacOS, `safe-rm` will use [AppleScript][applescript] to delete files or directories as much as possible to enable the built-in \"put-back\" capability in the system Trash bin.\n  - On Linux, it also follows the operating system's conventions for handling duplicate files in the Trash to avoid overwriting\n- Supports Custom [configurations](#configuration).\n\n## Supported options\n\nFor those implemented options, safe-rm will act **exactly the same** as the original `rm` command:\n\n| Option | Brief | Description |\n| ------ | ----- | ------------ |\n| `-i`, `--interactive` | **Interactive** | Prompts you to confirm before removing each file |\n| `-I`, `--interactive=once` | **Less Interactive** | Prompts only once before removing more than three files or when recursively removing directories |\n| `-f`, `--force` | **Force** | Removes files without prompting for confirmation, ignoring nonexistent files and overriding file protections |\n| `-r`, `-R`, `--recursive`, `--Recursive` | **Recursive** | Removes directories and their contents recursively. Required for deleting directories |\n| `-v`, `--verbose` | **Verbose** | Displays detailed information about each file or directory being removed |\n| `-d`, '--directory' | **Remove Empty Directories** | `safe-rm` can check and only remove empty directories specifically with this flag |\n| `--` | **End of Options** | Used to indicate the end of options. Useful if a filename starts with a `-` |\n\nCombined short options are also supported, such as\n\n`-rf`, `-riv`, `-rfv`, etc\n\n## Usual Installation\n\nAdd an alias to your `~/.bashrc` script,\n\n```sh\nalias rm='/path/to/bin/rm.sh'\n```\n\nand `/path/to` is where you git clone `shell-safe-rm` in your local machine.\n\n## Permanent Installation\n\nIf you have NPM ([NodeJS](https://nodejs.org/)) installed (RECOMMENDED):\n\n```sh\nnpm i -g safe-rm\n```\n\nOr by using the source code, within the root of the current repo (not recommended, may be unstable):\n\n```sh\n# If you have NodeJS installed\nnpm link\n\n# If you don't have NodeJS or npm installed\nmake \u0026\u0026 sudo make install\n\n# For those who have no `make` command:\nsudo sh install.sh\n```\n\nInstalling safe-rm will put `safe-rm` in your `/bin` directory. In order to use\n`safe-rm`, you need to add an alias to your `~/.bashrc` script and in all yours\ncurrently open terminals, like this:\n\n```sh\nalias rm='safe-rm'\n```\n\nAfter installation and alias definition, when you execute `rm` command in the Terminal, lines of below will be printed:\n\n```sh\n$ rm\nsafe-rm\nusage: rm [-f | -i] [-dPRrvW] file ...\n     unlink file\n```\n\nwhich helps to tell safe-rm from the original rm.\n\n## Uninstall\n\nFirst remove the `alias rm=...` line from your `~/.bashrc` file, then\n\n```sh\nnpm uninstall -g safe-rm\n```\n\nOr\n\n```sh\nmake \u0026\u0026 sudo make uninstall\n```\n\nOr\n\n```sh\nsudo sh uninstall.sh\n```\n\n# Advanced Sections\n\n## Configuration\n\nSince 3.0.0, you could create a configuration file located at `~/.safe-rm/config` in your `$HOME` directory, to support\n- defining your custom trash directory\n- allowing `safe-rm` to permanently delete files and directories that are already in the trash\n- disallowing `safe-rm` to use [AppleScript][applescript]\n\nFor the description of each config, you could refer to the sample file [here](./.safe-rm/config)\n\n```sh\n# You could\ncp -r ./.safe-rm ~/\n```\n\nIf you want to use a custom configuration file\n\n```sh\nalias=\"SAFE_RM_CONFIG=/path/to/safe-rm.conf /path/to/shell-safe-rm/bin/rm.sh\"\n```\n\nOr if it is installed by npm:\n\n```sh\nalias=\"SAFE_RM_CONFIG=/path/to/safe-rm.conf safe-rm\"\n```\n\n### Disable `Put-back` Functionality on MacOS (MacOS only)\n\nIn `~/.safe-rm/config`\n\n```sh\nexport SAFE_RM_USE_APPLESCRIPT=no\n```\n\nBy default, on MacOS, `safe-rm` uses AppleScript as much as possible so that removed files could be put back from system Trash app.\n\n### Change the Default Trash Bin Other Than System Default\n\n```sh\nexport SAFE_RM_TRASH=/path/to/trash\n```\n\n### Permanent Delete Files or Directories that Are Already in the Trash\n\n```sh\nexport SAFE_RM_PERM_DEL_FILES_IN_TRASH=yes\n```\n\n### Protect Files And Directories From Deleting\n\nIf 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](https://git-scm.com/docs/gitignore) inside the file.\n\nIf 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`\n\nFor example, in the `~/.safe-rm/.gitignore`\n\n```.gitignore\n/path/to/be/protected\n```\n\nAnd when executing\n\n```sh\n$ safe-rm /path/to/be/protected           # or\n$ safe-rm /path/to/be/protected/foo       # or\n$ safe-rm -rf /path/to/be/protected/bar\n\n# An error will occur\n```\n\nBut pay attention that, by adding the protected pattern above, if we:\n\n```sh\n$ safe-rm -rf /path/to\n```\n\nTo keep the performance of `safe-rm` and avoid conducting unnecessary file system traversing, this would not prevent `/path/to/be/protected/foo` from removing.\n\nPay **ATTENTION** that:\n- Before adding protected rules, i.e. placing the `\".gitignore\"` inside the `\"~/.safe-rm/\"` directory, it requires `git` to be installed in your environment\n- The `\".gitignore\"` patterns apply to the root directory (`\"/\"`), which means that the patterns defined within it need to be relative to the root directory.\n- Avoid adding `/` in the protected rules file, or everything will be protected\n\n\n[applescript]: https://en.wikipedia.org/wiki/AppleScript\n[rm]: https://en.wikipedia.org/wiki/Rm_(Unix)\n[safe-rm]: https://github.com/kaelzhang/shell-safe-rm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fshell-safe-rm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Fshell-safe-rm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fshell-safe-rm/lists"}