Pradeep asked this 10 months 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.

Guest 10 months 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

Guest 10 months ago

thanks for the answer