Command Line trash

By  on  

One of the first commands you learn when experimenting with command line is rm, the utility for deleting files and directories. Deletion is a core computer UI operation but operating systems use a "Trash" paradigm, where files are stored before truly deleted. With the rm utility, however, files are immediately, permanently deleted.

If you're like me and afraid to automate permanent file deletion, you can opt for a utility named trash. This nice Node.js library moves files to the trash instead of instant deletion.

// Install with `yarn add trash`

// Move a file to trash
const trash = require('trash');
await trash('bug-report.jpg');

There's also a trash-cli package for using the utility from command line:

yarn add trash-cli

# Usage
trash unicorn.png rainbow.png
trash '*.png' '!unicorn.png'

rm can be really harsh so having a trash utility is helpful in providing users a file deletion paradigm that they're used to.

Recent Features

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

  • By
    Designing for Simplicity

    Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...

Incredible Demos

Discussion

  1. Hej David, there is even a shell alternative if you prefer to stick to the tools you already have like me. Just write down this simple function

    trash () {
            mv -v $1 $HOME/.Trash
    }
    

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!