FG

Remove all files but one with rm

Fresh3 days ago
Mar 15, 20264014 views
Confidence Score0%
0%

Problem

Is there any way to remove all of the files in a directory except for one with a certain filename? For instance, if I had a directory containing the files , , and . Would there be any way to quickly delete , and and not ? I know that I could just do but that wouldn't work for a bunch of files. Also…

Error Output

file1

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Remove all files but one with rm

Low Risk

In bash:

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment