Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
rm *.php.php* this will delete all files that have more than one php extension – debal Mar 20 '14 at 8:58
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 '14 at 9:04
Thanks a lot....I tried this find . -name ".php.php" -print0 | xargs -0 rm -rf and it worked – Danny Mar 20 '14 at 9:16

To match repeating extensions, with zsh:

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


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


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

With GNU find, recursively:

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

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
Or, under non-embedded Linux, FreeBSD, OSX or Cygwin: find . -name "*.php.php" -delete – Gilles Mar 20 '14 at 23:03

Your Answer


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.