Command Line trash

C

codeguru

Member
Freecoin
282
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 [URL='https://www.npmjs.com/package/trash']trash[/URL]. 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.
 
Last edited by a moderator:

Richest Freecoded User

Most Freecoin

freecoded
freecoded
5,296 Freecoin
P
Peterparker87
1,849 Freecoin
G
GwenJasmine
1,672 Freecoin
J
Johnhendrick
1,551 Freecoin
S
speechhub
898 Freecoin
M
mahlibeardman
793 Freecoin
peterkester96
peterkester96
778 Freecoin
S
Smith16
738 Freecoin
A
Alfrenoe87
618 Freecoin
Davy200
Davy200
590 Freecoin
Top