
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Move files and folders to the trash
Works on macOS (10.12+), Linux, and Windows (8+).
Note: The Linux implementation is not very good and not maintained. Help welcome. If no one steps up to help maintain it, I will eventually remove Linux support.
In contrast to fs.unlink, del, and rimraf which permanently delete files, this only moves them to the trash, which is much safer and reversible.
npm install trash
import trash from 'trash';
await trash(['*.png', '!rainbow.png']);
Returns a Promise.
Type: string | string[]
Accepts paths and glob patterns.
Non-existent files and glob patterns that match nothing are silently ignored. If you need to know whether files were actually trashed, check for their existence beforehand.
Type: object
Type: boolean
Default: true
Enable globbing when matching file paths.
To install the trash command, run:
npm install --global trash-cli
On macOS, macos-trash is used.
On Linux, the XDG spec is followed.
On Windows, recycle-bin is used.
On WSL (Windows Subsystem for Linux), files are moved to the Windows Recycle Bin.
mvNot 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 macOS, you'll lose the Put back feature.
When running as the Windows SYSTEM account or other service accounts, files are moved to that account's recycle bin (e.g., C:\$Recycle.Bin\S-1-5-18\ for SYSTEM). These files won't be visible in the normal user's recycle bin and may accumulate over time. For service contexts, consider using direct file deletion instead.
FAQs
Move files and folders to the trash
We found that trash demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.