I have two folders, one that I know the name of, and one that I don't:
~/foobar-as9df7 # I know the name of this one
~/foobar-7fq92h # I don't know the name of that one
How can I delete the folder that starts with foobar-
and is NOT ~/foobar-as9df7
, and that I don't know the name of?
Said differently, I want to rm -rf ~/foobar-as9df7
except that I don't know it's called foobar-as9df7
, I only know its name starts with foobar-
and it's not foobar-as9df7
.
I've tried doing:
find foobar-* ! -name "foobar-as9df7" -exec rm -rf {} \;
which works but strangely this triggers a message saying:
find: ‘foobar-7fq92h’: No such file or directory
-- EDIT
the output of this command:
find ~/ -type d -name 'foobar-*' ! -name 'foobar-as9df7' -exec echo .rm -r {} +
is as follows:
.rm -r /home/ubuntu/foobar-7fq92h
shopt -s extglob; rm -r ~/foobar-!(as9df7)
. – terdon Mar 23 '21 at 12:24shopt -s extglob
forzsh
, ideally that would work with both of them? – Jivan Mar 23 '21 at 12:25find
approach given in the answers of the dupe should work for any shell. If that isn't enough and you still want a zsh-only solution, edit your question so it can be reopened. – terdon Mar 23 '21 at 12:26shopt -s extglob; rm -r ~/foobar-!(as9df7)
in bash. Or, withfind
it would befind ~/ -type d -name 'foobar-*' ! -name 'foobar-as9df7' -exec rm -r {} +
doesn't work. Since the main issue is the same, we prefer not to cover it again. If the problem was reaching the commands I just gave (which is understandable if you're not familiar with the syntax of the relevant tools), it is probably not worth having a separate question since the main answers are given in the dupe. – terdon Mar 23 '21 at 12:42find
command but somehow it says thatfind: ‘foobar-1e91d’: No such file or directory
despite successfully removing it, which is weird – Jivan Mar 23 '21 at 12:50