GithubHelp home page GithubHelp logo

trash-cli's Introduction

trash-cli

Move files and folders to the trash

Works on macOS (10.12+), Linux, and Windows (8+).

In contrast to rm which is dangerous 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.

Accepts paths and glob patterns.

Install

npm install --global trash-cli

Usage

$ trash --help

  Usage
    $ trash <path|glob> […]

  Examples
    $ trash unicorn.png rainbow.png
    $ trash '*.png' '!unicorn.png'

Tip

Add alias rm=trash to your .zshrc/.bashrc to reduce typing & safely trash files: $ rm unicorn.png.

Related

trash-cli's People

Contributors

jv-k avatar moox avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trash-cli's Issues

Can't find the files!

Using zsh on kubuntu 16.04.

 ✘  ~  sudo npm install --global trash-cli
/usr/local/bin/trash -> /usr/local/lib/node_modules/trash-cli/cli.js
/usr/local/lib
`-- [email protected] 

 ~  take new
 ~/new  .. 
 ~  trash new
/usr/bin/env: ‘node’: No such file or directory
 ~  touch hello
 ~  trash hello
/usr/bin/env: ‘node’: No such file or directory

Use of const in strict mode

Running node 0.12.7 on OS X 10.10.5:

$ npm i --global trash-cli
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.12.7","npm":"2.11.3"})
/Users/hfp/.nvm/versions/node/v0.12.7/bin/trash -> /Users/hfp/.nvm/versions/node/v0.12.7/lib/node_modules/trash-cli/cli.js
[email protected] /Users/hfp/.nvm/versions/node/v0.12.7/lib/node_modules/trash-cli
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

$ trash .bash_profile
/Users/hfp/.nvm/versions/node/v0.12.7/lib/node_modules/trash-cli/cli.js:4
const updateNotifier = require('update-notifier');
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

High vulnerability in dependency

npm audit shows a HIGH vulnerability in a dependency of trash-cli:

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ dot-prop                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=5.1.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ trash-cli [dev]                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ trash-cli > update-notifier > configstore > dot-prop         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1213                            │
└───────────────┴──────────────────────────────────────────────────────────────┘

Please consider updating and putting out a new release to resolve this.

Error: spawn E2BIG

I tried to delete all my node_modules folders, but it seems like I hit some limit. Would it be possible to fix this by letting the trash-cli split up the expanded glob before performing the work?

❯ trash '**/node_modules'
Error: spawn E2BIG
at exports._errnoException (util.js:1012:11)
at ChildProcess.spawn (internal/child_process.js:302:11)
at exports.spawn (child_process.js:372:9)
at exports.execFile (child_process.js:139:15)
at /usr/local/lib/node_modules/trash-cli/node_modules/pify/index.js:29:7
at /usr/local/lib/node_modules/trash-cli/node_modules/pify/index.js:12:10
at ret (/usr/local/lib/node_modules/trash-cli/node_modules/pify/index.js:56:34)
at module.exports (/usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/osx.js:37:32)
at module.exports (/usr/local/lib/node_modules/trash-cli/node_modules/trash/index.js:22:45)
at Object. (/usr/local/lib/node_modules/trash-cli/cli.js:27:1)
~/Devel 1m 49s

ImportError: No module named trashcli.put

On Ubuntu 20.04 I installed using sudo npm install --global trash-cli but then running trash gives:

Traceback (most recent call last):
  File "/usr/local/bin/trash", line 4, in <module>
    from trashcli.put import main as main
ImportError: No module named trashcli.put

Strange file names in trash folder

Here is what I get in my (Ubuntu) trash folder after deletion and I cannot restore these files as well. Initially i called this file new.rb
image

`sudo trash` still has no permission

I'm on macOS 10.15.2

Create

❯ sudo mkdir /Users/wow

❯ sudo mkdir /Users/wow
mkdir: /Users/wow: File exists #

Delete with trash

❯ trash /Users/wow
Error: Command failed: /usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/macos-trash /Users/wow
“wow” couldn’t be moved to the trash because you don’t have permission to access it.

❯ sudo trash /Users/wow
Error: Command failed: /usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/macos-trash /Users/wow
“wow” couldn’t be moved to the trash because you don’t have permission to access it.

Delete with rm

❯ sudo rm -rf /Users/wow

❯ test -d /Users/wow || echo 'no folder'
no folder

Hard-deletes on macOS Mojave

Running trash or trash-put on macOS Mojave (10.14.3) simply rms (hard-deletes) the file. It is not in the trash bin!

Error from Update Notifier module

I recently updated my version of trash-cli, and I have been getting the following error:

/usr/local/lib/node_modules/trash-cli/node_modules/update-notifier/index.js:74
                        (async () => {
                               ^
SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/trash-cli/cli.js:3:24)

I'm on npm version 6.9.0 - not sure if anyone else is seeing this.
Not sure if this an issue I should open with the update-notifier module or not

To alias, or not to alias

Unless there's a distinction I do not understand, the Readme both advise aliasing rm to trash... and not doing it.

You should not alias rm to trash however as that would break most scripts relying on rm behavior.

Add alias rm=trash to your .zshrc/.bashrc to reduce typing & safely trash files: $ rm unicorn.png.

Add restore feature

Like restore -last, restore -last=<n>, n means the last nth file/folder removed to trash.

windows-trash.exe does not work with subst virtual drive paths

  • windows-trash.exe silently fails to remove files if the path is in a subst virtual drive.
  • windows-trash.exe successfully removes the same files if the full, non-virtual drive paths are used.
P:\tmp>subst
       &REM Show subst virtual drive maping:
P:\: => V:\Insync\Dropbox\p

P:\tmp>windows-trash.exe FILE_TO_TRASH
       &REM Running from virtual drive silently fails to remove file:

P:\tmp>dir
06/18/2023  12:15 AM                 0 FILE_TO_TRASH
06/17/2023  11:10 PM            28,672 windows-trash.exe

P:\tmp>v:
       &REM Switch to non-virtual drive.

V:\Insync\Dropbox\p\tmp>windows-trash.exe FILE_TO_TRASH
                        &REM Running from non-virtual drive successfully to removes file:

V:\Insync\Dropbox\p\tmp>dir
06/17/2023  11:10 PM            28,672 windows-trash.exe


I was trying to debug or workaround this error:

/p/tmp
$ trash FILE_TO_TRASH
Error: Command failed: V:\pnpm-home\global\5\.pnpm\[email protected]\node_modules\trash\lib\windows-trash.exe P:\tmp\FILE_TO_TRASH

    at ChildProcess.exithandler (node:child_process:419:12)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5)

The error does not happen if not in a virtual drive:

/v/Insync/Dropbox/p/tmp
$ trash FILE_TO_TRASH

/v/Insync/Dropbox/p/tmp
$ ls
windows-trash.exe*

Also the error only occurs after trash-cli version 3.0.0. (So my workaround is to use version 2.0.0)

Environment:

  • Windows 11
  • Git bash for windows (2.41.0.windows.1)
  • Node v18.16.0
  • NPM 9.5.1 or PNPM 8.6.2

Add example unicorn.png

In the readme.md of this repository there's a reference to a file named unicorn.png.

Considering that this tool (trash) is amazing, simple logic tells us that the unicorn must also be amazing.

For purposes of:

  • amazing,
  • reference,
  • removal of ambiguity,

please include the (amazing) unicorn.png image file in this repository. Thank you.

.Trash directory

On mounted partition, when I trash $somedir$, it just works fine as the $somedir$ is moved to my OS's home trash directory. But, a directory named .Trash is automatically generated in the path I executed the command. If I tried to trash .Trash, it fails like the below.

This result happened on Ubuntu 18.04.

➜  SHARE trash .Trash 
Alias tip: th .Trash
Traceback (most recent call last):
  File "/usr/bin/trash", line 5, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/dist-packages/trashcli/cmds.py", line 10, in put
    ).run(sys.argv)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 548, in run
    self.trash_all(args)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 557, in trash_all
    self.trash(arg)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 560, in trash
    self.trashcan.trash(arg)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 324, in trash
    trashed_file = trash_dir.trash(file)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 80, in trash
    move(path, trashed_file.actual_path)
  File "/usr/lib/python2.7/dist-packages/trashcli/fs.py", line 47, in move
    return shutil.move(path, str(dest))
  File "/usr/lib/python2.7/shutil.py", line 312, in move
    raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
shutil.Error: Cannot move a directory '.Trash' into itself '/media/user/SHARE/.Trash/1000/files/.Trash'.

Verbose mode

It would be useful to have a flag for verbose mode.

$ trash -v unicorn.png rainbow.png
removed 'unicorn.png'
removed 'rainbow.png'

Usage

$ trash --help

  Usage
    $ trash [flags] <path|glob> [...]

  Examples
    $ trash unicorn.png rainbow.png
    $ trash '*.png' '!unicorn.png'
    $ trash -v unicorn.png rainbow.png

Trash cli failed to install in shelll

sudo npm install --global trash-cli
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.10.37","npm":"1.4.28"})
npm WARN engine [email protected]: wanted: {"node":">=0.12.0","iojs":">=1.0.0"} (current: {"node":"0.10.37","npm":"1.4.28"})
npm ERR! 404 Not Found
npm ERR! 404 
npm ERR! 404 'sindresorhus/df' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404 It was specified as a dependency of 'xdg-trashdir'
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

npm ERR! System Linux 3.16.0-55-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "--global" "trash-cli"
npm ERR! cwd /home/rakesh
npm ERR! node -v v0.10.37
npm ERR! npm -v 1.4.28
npm ERR! code E404
npm ERR! not ok code 0

Error installing

❯ npm install --global trash-cli
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--global" "trash-cli"
npm ERR! node v7.7.2
npm ERR! npm  v4.1.2

npm ERR! Invalid name: "@sindresorhus/df"
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/username/settings/npm-debug.log

v5 throws ERR_UNSUPPORTED_ESM_URL_SCHEME error

Notes from my build:

Step #3: > trash build
Step #3:
Step #3: internal/modules/run_main.js:54
Step #3: internalBinding('errors').triggerUncaughtException(
Step #3: ^
Step #3:
Step #3: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
Step #3: at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:669:11)
Step #3: at Loader.resolve (internal/modules/esm/loader.js:97:40)
Step #3: at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
Step #3: at ModuleWrap. (internal/modules/esm/module_job.js:42:40)
Step #3: at link (internal/modules/esm/module_job.js:41:36) {
Step #3: code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
Step #3: }
Step #3: npm ERR! code ELIFECYCLE
Step #3: npm ERR! errno 1
Step #3: npm ERR! @0.0.1 clean: trash build
Step #3: npm ERR! Exit status 1
Step #3: npm ERR!

No such file or directory message

When you trash asdf.txt and asdf.txt does not exist, no feedback is given to the user.

Is this planned to be so? Should there not be some message that informs the user the file he is trying to sent to the trashbin is not there?

Error encountered

>trash build
Error: Command failed: (project_path)\node_modules\trash\lib\win-trash.exe (project_path)\build

at ChildProcess.exithandler (child_process.js:204:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Socket.<anonymous> (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:501:12)

npm ERR! Windows_NT 6.2.9200
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules
\npm\bin\npm-cli.js" "run" "build"
npm ERR! node v6.10.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! (project_name)@0.0.1 build: trash build
npm ERR! Exit status 1
...
...

No put back option in the Trash

If I drag a file into trash, I can right click and choose put back.
However, if I use trash-cli, there is no put back option.

Restoring issue

It seems that trash-cli do weird stuff with symlinks.
I have a Download folder on a separate partition, wich I symlinked to my home folder.
If I trash-put file inside it, I am not able to restore the file with trash-restore; neither from /home/user/Download nor /mountpoint/Download.

EDIT: it seems that I am unable to restore files trashed on this partition.

Can't trash folders with content

When trying to trash a folder with any content (be it other folders or files) an error is thrown:

at ChildProcess.exithandler (child_process.js:303:12)
at ChildProcess.emit (events.js:321:20)
at maybeClose (internal/child_process.js:1026:16)
at Socket.<anonymous> (internal/child_process.js:441:11)
at Socket.emit (events.js:321:20)
at Pipe.<anonymous> (net.js:672:12)

I have checked and no process is currently using the folder or any files/folders within it.

I'm also able to trash files just fine, as well as folders that do not have any content.

My system:
OS: Windows 10 Home Version 1909 Build 18363
NodeJS: v13.9.0
trash-cli: 3.0.0
trash: 6.1.1
Env: PowerShell 6.2.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.