Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trash

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trash

Cross-platform command-line app for moving files and directories to the trash - A safer alternative to `rm`

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
115K
increased by11.79%
Maintainers
2
Weekly downloads
 
Created
Source

trash

Cross-platform command-line app for moving files and directories to the trash
A safer alternative to rm

Build Status

Works on OS X, Linux and Windows.

In contrast to rm which is dangerous and permanently delete files, this only moves them to the trash, which is much safer and reversible. You should not alias rm to trash however as that would break most scripts relying on rm behaviour. Rather use trash from the CLI and in your own scripts. I would also recommend reading my guide on safeguarding rm.

CLI

$ npm install --global trash
$ trash --help

  Usage
    trash <path> [<path> ...]

  Example
    trash unicorn.png rainbow.png

Globbing support is left up to your shell, but $ trash *.png should expand to the above in most shells.

API

$ npm install --save trash
var trash = require('trash');

trash(['unicorn.png', 'rainbow.png'], function (err) {
	console.log('done');
});

Info

On OS X AppleScript is used as it's the only way to support built-in features such as Put back.

On Linux xdg-trash is used.

On Windows cmdutils is used.

Tip

Add alias t=trash to your .zshrc/.bashrc to reduce typing: $ t unicorn.png.

FAQ

But I can do the same thing with mv

Not really. The mv command isn't cross-platform and moving to trash is not just about moving the file to a "trash" directory. On all OSes you'll run into file conflicts. The user won't easily be able to restore the file. It won't work on an external drive. The trash directory location varies between Windows versions. For Linux there's a whole spec you need to follow. On OS X you'll loose the Put back feature.

See empty-trash for emptying the trash.

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 14 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc