Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


LinkBack Search this Thread
Old 03-01-2013, 09:12 AM   #1
LQ Newbie
Registered: Dec 2005
Posts: 22

Rep: Reputation: 0
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.
Old 03-01-2013, 09:17 AM   #2
Senior Member
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,408

Rep: Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883
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.

for file in *passed; do
   if [[ -f ${file}.???? ]]; then
      echo rm -f $file
2 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mencoder adds the extension of the original file to the output file ex: file.flv.mp4 linuxlicious Linux - General 2 04-17-2012 02:22 PM
Mencoder adds the extension of the original file to the output file ex: file.flv.mp4 linuxlicious Linux - General 1 04-15-2012 04:07 AM
Please chech my statement - delete all except file with largest number extension laki47 Linux - Newbie 3 02-20-2009 06:02 AM
Linux file extension vs Dos file Extension? manaa Linux - Newbie 6 02-12-2009 04:19 PM

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration