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
    Create a CSS Cube

    CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals.  Add animation and you've got something really neat.  Unfortunately each CSS cube tutorial I've read is a bit...

  • By
    fetch API

    One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest, wasn't really made for what we've been using it for.  We've done well to create elegant APIs around XHR but we know we can do better.  Our effort to...

Incredible Demos

  • By
    Duplicate the jQuery Homepage Tooltips

    The jQuery homepage has a pretty suave tooltip-like effect as seen below: The amount of jQuery required to duplicate this effect is next to nothing;  in fact, there's more CSS than there is jQuery code!  Let's explore how we can duplicate jQuery's tooltip effect. The HTML The overall...

  • By
    The Simple Intro to SVG Animation

    This article serves as a first step toward mastering SVG element animation. Included within are links to key resources for diving deeper, so bookmark this page and refer back to it throughout your journey toward SVG mastery. An SVG element is a special type of DOM element...

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!