Pradeep asked this 5 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 5 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 5 months ago

thanks for the answer