Pradeep asked this 6 years ago

Delete all files linux in which does not match a pattern

I want to delete all files in a folder on my Ubuntu machine whose file names DO NOT start with "EN" . There are hundreds of them in that directory so its not practical to delete them one by one. What is the best solution? please help.


Best Answer by Luka 6 years ago

You can use the find command like below:

find . -type f ! -name "EN*" -exec rm -f {} \;

! character will exclude the files names that start with the letters EN

Luka 6 years ago
thanks for the answer