Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove files starting with a particular letter [closed]

Tags:

linux

bash

I want to rm all files in a directory not starting with the letter I or N - what is the easiest way to do it in bash?

like image 262
LordDoskias Avatar asked Dec 03 '22 06:12

LordDoskias


2 Answers

You can do the following:

rm [^IN]*

The [^IN] is a pattern that matches any character except I or N - this syntax is described in the Pattern Matching section of the bash manual.

like image 154
Mark Longair Avatar answered Dec 11 '22 17:12

Mark Longair


Another way:

find . -maxdepth 1 -type f -name "[^NI]*" -delete

Obviously, this option is worse ;)

like image 41
vicentazo Avatar answered Dec 11 '22 16:12

vicentazo