How to delete all but one file in Unix?
Fresh3 days ago
Mar 15, 202616385 viewsConfidence Score0%
0%
Problem
Possible Duplicate: How to delete all files in a directory except some? How to delete all but one(or some) file in Unix? Something like
Error Output
rm -rf -ignore myfile.txt *
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Canonical Fix
Unverified Fix
New Fix – Awaiting Verification
Fix for: How to delete all but one file in Unix?
Low Risk
Example : To remove all files except 'test2' : Then 'ls' output is : EDIT: Thanks for the comment. If the directory contains some files with spaces : You can use (with bash) : 'ls' output :
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix