I want to delete all files and directories from a specific directory except for one directory. For the same operation I had run this command
# rm -R -df !(dir_name_not_to_delete)
It works in Ubuntu but it gives an error in CentOS; i.e.,
-bash: !: event not found " what is the reason for this error"
What do I have to use in CentOS to get this to work? Is there any alternative of '!' this sign in Centos?
First, !(dir_name_not_to_delete)
is an extended glob. For it to work, you need to have the extended globs option turned on. Run:
shopt -s extglob
Secondly, the specific error message that you see, -bash: !: event not found
, means that you also have history expansion turned on. If you don't want history expansion, it it safest to turn it off:
set +H
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments