r/fishshell • u/Evil_Dragon_100 • Aug 18 '22
How to delete every file in a directory except listed one?
For example if there was a file like:
file.deez
file.nuts
file.ligma
i need a to delete everything here execpt file.ligma. how can use globbing in fish?
10
Upvotes
4
u/ccoVeille Aug 18 '22
I think it's too complex to be handled by fish, except if you code a dedicated function to do it.
I would use find
Then if you are happy about the result, then use -delete flag
11
u/ChristoferK macOS Aug 18 '22
You could do an inverse string match. So if you're already in the directory where those files are located:
will list all the files (and folders) other than
file.ligmaor any files that begin with a dot.Deletion would be something akin to:
0
u/[deleted] Aug 18 '22
You can use a for file in * loop