LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   delete a file if a file with same name with different extension is there (https://www.linuxquestions.org/questions/linux-newbie-8/delete-a-file-if-a-file-with-same-name-with-different-extension-is-there-4175452245/)

samanp 03-01-2013 09:12 AM

delete a file if a file with same name with different extension is there
 
One of our dev servers have files such as test123.passed.2013, test456.passed.2013 etc... due to some issue now it has generated files such as test123.passed, test456.passed etc...

How can i delete files without .2013 if there is a same name one with .2013 exists.

suicidaleggroll 03-01-2013 09:17 AM

Like this? The way it's written it will only print the names of the files it would delete. Once you confirm it's all working well just remove the "echo" to actually delete them.

Code:

for file in *passed; do
  if [[ -f ${file}.???? ]]; then
      echo rm -f $file
  fi
done



All times are GMT -5. The time now is 07:44 PM.