├── .editorconfig ├── .gitattributes ├── .github ├── security.md └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── cli.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 22 14 | - 20 15 | - 18 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-node@v4 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: npm install 22 | - run: npm test 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import process from 'node:process'; 3 | import meow from 'meow'; 4 | import trash from 'trash'; 5 | 6 | // Ignore all flags of `rm` program. 7 | const ignoredFlags = [ 8 | 'r', 9 | 'f', 10 | 'i', 11 | 'd', 12 | 'P', 13 | 'R', 14 | 'v', 15 | 'W', 16 | ]; 17 | 18 | const ignoredFlagsConfig = {}; 19 | for (const flag of ignoredFlags) { 20 | ignoredFlagsConfig[flag] = { 21 | type: 'boolean', 22 | }; 23 | } 24 | 25 | const cli = meow(` 26 | Usage 27 | $ trash […] 28 | 29 | Examples 30 | $ trash unicorn.png rainbow.png 31 | $ trash '*.png' '!unicorn.png' 32 | `, { 33 | importMeta: import.meta, 34 | flags: { 35 | ...ignoredFlagsConfig, 36 | }, 37 | }); 38 | 39 | if (cli.input.length === 0) { 40 | console.error('Specify at least one path'); 41 | process.exit(1); 42 | } 43 | 44 | await trash(cli.input); 45 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "trash-cli", 3 | "version": "6.0.0", 4 | "description": "Move files and folders to the trash", 5 | "license": "MIT", 6 | "repository": "sindresorhus/trash-cli", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "bin": { 15 | "trash": "./cli.js" 16 | }, 17 | "engines": { 18 | "node": ">=18" 19 | }, 20 | "scripts": { 21 | "test": "xo && ava" 22 | }, 23 | "files": [ 24 | "cli.js" 25 | ], 26 | "keywords": [ 27 | "cli-app", 28 | "cli", 29 | "trash", 30 | "recycle", 31 | "bin", 32 | "rm", 33 | "rmrf", 34 | "rimraf", 35 | "remove", 36 | "delete", 37 | "del", 38 | "file", 39 | "files", 40 | "directory", 41 | "directories", 42 | "folder", 43 | "folders", 44 | "xdg" 45 | ], 46 | "dependencies": { 47 | "meow": "^13.2.0", 48 | "trash": "^9.0.0" 49 | }, 50 | "devDependencies": { 51 | "ava": "^6.1.3", 52 | "execa": "^9.3.0", 53 | "path-exists": "^5.0.0", 54 | "temp-write": "^5.0.0", 55 | "xo": "^0.59.2" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # trash-cli 2 | 3 | > Move files and folders to the trash 4 | 5 | Works on macOS (10.12+), Linux, and Windows (8+). 6 | 7 | In contrast to [`rm`](http://en.wikipedia.org/wiki/Rm_(Unix)) which is [dangerous](http://docstore.mik.ua/orelly/unix3/upt/ch14_03.htm) and permanently deletes files, this only moves them to the trash, which is much safer and reversible. I would also recommend reading my guide on [safeguarding `rm`](https://github.com/sindresorhus/guides/blob/main/how-not-to-rm-yourself.md#safeguard-rm). 8 | 9 | Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). 10 | 11 | ## Install 12 | 13 | ```sh 14 | npm install --global trash-cli 15 | ``` 16 | 17 | ## Usage 18 | 19 | ``` 20 | $ trash --help 21 | 22 | Usage 23 | $ trash […] 24 | 25 | Examples 26 | $ trash unicorn.png rainbow.png 27 | $ trash '*.png' '!unicorn.png' 28 | ``` 29 | 30 | ## Tip 31 | 32 | Add `alias rm=trash` to your `.zshrc`/`.bashrc` to reduce typing & safely trash files: `$ rm unicorn.png`. 33 | 34 | ## [FAQ](https://github.com/sindresorhus/trash#faq) 35 | 36 | ## Related 37 | 38 | - [trash](https://github.com/sindresorhus/trash) - API for this package 39 | - [empty-trash-cli](https://github.com/sindresorhus/empty-trash-cli) - Empty the trash 40 | - [del-cli](https://github.com/sindresorhus/del-cli) - Delete files and folders 41 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import tempWrite from 'temp-write'; 3 | import {pathExists} from 'path-exists'; 4 | import {execa} from 'execa'; 5 | 6 | test('trash file', async t => { 7 | const filename = tempWrite.sync('foo'); 8 | await execa('./cli.js', [filename]); 9 | t.false(await pathExists(filename)); 10 | }); 11 | 12 | test('ignore rm flags', async t => { 13 | const filename = tempWrite.sync('foo'); 14 | await execa('./cli.js', ['-rf', filename]); 15 | t.false(await pathExists(filename)); 16 | }); 17 | --------------------------------------------------------------------------------