Remove files that start with but don't contain
Yes you can use more than one pattern with find
:
$ find -name 'master-*' \! -name 'master-2018*' -print0 -prune |
xargs -0 echo rm -fr
(remove the echo
if you're satisfied with the dry run)
You should add a -maxdepth 1
predicate just after find
if you only want ro remove files from the current directory, ie master-1991
but no subdir/master-1991
.
In bash:
shopt -s extglob
echo rm master-!(2018*)
Remove the echo
if it looks correct.
The above uses bash's extended globbing facility to match files that start with master-
but who do not have 2018
immediately following, then followed by anything (*
).