There are plenty of situations where the use of a *
is virtually inevitable - e.g. rm -rf *
in a folder that holds thousands of subfolders and files.
But what if you want to exclude just one or two files or folders from the rm
command? I've googled my way around and only found quite complicated solutions like find . -depth -not \( -name 'one' -o -name 'two' \
-o -name 'three' \) -exec rm {} \;
as stated here.
Is there a possibility to do this in an easier way - without that detour to find
?
E.g. rm -rf --exclude='one' --exclude='two' --exclude='three' *
like in rsync or just rm -rf -e 'one','two','three' *
?
Maybe even a general possibility to exclude things from *
(so other commands like cp
, mv
, ... don't have to implement their own)? Something like *{'one','two','three'}
or so?
find
with the--delete
option (no need to executerm
for each file. That is needless overhead).mv -t /tmp one two three && rm -rf * && mv -t . /tmp/one /tmp/two /tmp/three
, but I would prefer a solution giving the possibility to explicitely exclude something from*
. There will surely be situations where moving or copying the files to another destination won't be an option.