Command Line trash

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 […]

The post Command Line trash appeared first on David Walsh Blog.

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.

The post Command Line trash appeared first on David Walsh Blog.


Print Share Comment Cite Upload Translate
APA
David Walsh | Sciencx (2024-03-29T07:58:26+00:00) » Command Line trash. Retrieved from https://www.scien.cx/2021/10/24/command-line-trash/.
MLA
" » Command Line trash." David Walsh | Sciencx - Sunday October 24, 2021, https://www.scien.cx/2021/10/24/command-line-trash/
HARVARD
David Walsh | Sciencx Sunday October 24, 2021 » Command Line trash., viewed 2024-03-29T07:58:26+00:00,<https://www.scien.cx/2021/10/24/command-line-trash/>
VANCOUVER
David Walsh | Sciencx - » Command Line trash. [Internet]. [Accessed 2024-03-29T07:58:26+00:00]. Available from: https://www.scien.cx/2021/10/24/command-line-trash/
CHICAGO
" » Command Line trash." David Walsh | Sciencx - Accessed 2024-03-29T07:58:26+00:00. https://www.scien.cx/2021/10/24/command-line-trash/
IEEE
" » Command Line trash." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2021/10/24/command-line-trash/. [Accessed: 2024-03-29T07:58:26+00:00]
rf:citation
» Command Line trash | David Walsh | Sciencx | https://www.scien.cx/2021/10/24/command-line-trash/ | 2024-03-29T07:58:26+00:00
https://github.com/addpipe/simple-recorderjs-demo