I am trying to remove all the files in a directory but keeping two files in this directory.
I used the command
rm !(1file name| 2filename)
But it throws error
bash: !: event not found
Please help me to correct the command.
!
attempts to expand history event. In BASH you can enable extglob
using:
shopt -s extglob
Then use this rm
command to delete all but these 2 listed files:
rm !(@(filename1|filename2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With