Download your favorite Linux distribution at LQ ISO.
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!


  Search this Thread
Old 01-29-2006, 09:21 PM   #1
Registered: Jul 2005
Distribution: Arch
Posts: 159

Rep: Reputation: 31
bash command

How do I remove .php, .php4, and .phtml files in a directory and all its subdirectories without removing any of the subdirectories?

So far I know only this:
rm *.php *.php4 *.phtml
I already tried:
rm -R *.php *.php4 *.phtml
Old 01-29-2006, 09:44 PM   #2
Senior Member
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
rm -f
rm -rf
Old 01-29-2006, 09:48 PM   #3
Senior Member
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
Try something like:
find . -name *.php
It will print out the names of all the php files in the current directory and its children. Verify that all the files found you want removing, and then:
find . -name *.php --execute rm {} \;
I hope this helps
Old 01-29-2006, 10:20 PM   #4
Registered: Jul 2005
Distribution: Arch
Posts: 159

Original Poster
Rep: Reputation: 31
Thanks! That worked well Ian!
Old 01-30-2006, 04:22 AM   #5
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
With find, you can also combine multiple name-patterns, like this:
find . -name '*.php' -o -name '*.php4' -o -name '*.phtml'

Secondly, I would recommend putting single quotes around your wildcard patterns.
You don't want the shell to replace them by any files it finds in your current directory (filename substitution). Rather, you'll want to pass them unaltered to the "find" command.


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: <command name> command not found smash Programming 5 03-13-2006 08:48 AM
BASH command prompt Progmaker Linux - General 2 01-25-2006 12:22 PM
The ! bash command. How do I use it? funkynesh Linux - Newbie 2 10-12-2005 08:36 PM
BASH Command Result redhatnoob Programming 2 08-19-2004 06:25 PM
bash command help bobdinkel Linux - Newbie 20 07-17-2003 02:21 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:02 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration