LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-29-2006, 09:21 PM   #1
Berticus
Member
 
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:
Code:
rm *.php *.php4 *.phtml
I already tried:
Code:
rm -R *.php *.php4 *.phtml
 
Old 01-29-2006, 09:44 PM   #2
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

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

Rep: Reputation: 62
Try something like:
Code:
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:
Code:
find . -name *.php --execute rm {} \;
I hope this helps
--Ian
 
Old 01-29-2006, 10:20 PM   #4
Berticus
Member
 
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
timmeke
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:13 PM.

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