Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Delete files with same name at the end of the file

i have a lot of files in my folder and sub directories like

ajax_hostel_room_master.php.php          class_hostel_registration.php.php
ajax_hostel_room_master.php.php.php      class_hostel_registration.php.php.php
ajax_hostel_room_shifting.php            class_hostel_room_allocation.php
ajax_hostel_room_shifting.php.php        class_hostel_room_allocation.php.php
ajax_hostel_room_shifting.php.php.php    class_hostel_room_allocation.php.php.php

I want to keep the filename.php and delete the other files like filename.php.php

share|improve this question
1  
rm *.php.php* this will delete all files that have more than one php extension –  debal Mar 20 at 8:58
add comment

3 Answers 3

up vote 4 down vote accepted

rm -- *.php.php this will delete all files that have more than one php extension

for all sub directories you need

find /scripts/tmp -name "*.php.php" -exec rm {} +

/scripts/tmp is the directory under which my files and subdirectories existed

share|improve this answer
    
this command helps me remove the files in the directory ...I have those files in Sub directory too..... –  Danny Mar 20 at 9:04
    
Thanks a lot....I tried this find . -name ".php.php" -print0 | xargs -0 rm -rf and it worked –  Danny Mar 20 at 9:16
add comment

To match repeating extensions, with zsh:

rm -- *.*.*(e{'[[ $REPLY:t =~ "(\..*)\1$" ]]'})

Recursively:

rm -- **/*.*.*(e{'[[ $REPLY:t =~ "(\..*)\1$" ]]'})

That would match a.php.php and b.x.x and c.x.y.x.y (and .php.php).

With ksh93:

rm -- *@(.*)\1

Recursively:

set -o globstar
rm -- **/*@(.*)\1

With GNU find, recursively:

find . -regex '.*\(\.[^/]*\)\1' -exec rm {} +
share|improve this answer
add comment

Try this at the root of your directory where you want to delete the files:

find . -name "*.php.php*" -exec rm '{}' \;
share|improve this answer
1  
Or, under non-embedded Linux, FreeBSD, OSX or Cygwin: find . -name "*.php.php" -delete –  Gilles Mar 20 at 23:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.