This command is working perfectly when you just type it into console and run;
rm -rf !(folder1|file_name|log.txt|*.sh|*.conf)
However, when I run it from a bash script, it gives me the following error;
./test.sh: line 1: syntax error near unexpected token `('
./test.sh: line 1: `rm -rf !(folder1|file_name|log.txt|*.sh|*.conf)'
It's the extended glob matching syntax. You need to enable it with shopt -s extglob
before the rm
command.