Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rm !(file name) is not working in ubuntu it showing error " bash: !: event not found"

Tags:

bash

command

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.

like image 667
skesh Avatar asked Dec 10 '15 06:12

skesh


1 Answers

! 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))
like image 186
anubhava Avatar answered Nov 15 '22 18:11

anubhava