LinuxQuestions.org
Visit Jeremy's Blog.
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 02-02-2009, 12:22 PM   #1
alan43
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Rep: Reputation: 0
how to use rm to keep the files needed and delete others


I have a folder, ~/html.

I want to delete all the files except for the files which end with ".html" or ".htm".

How could I use rm to achieve this? Thanks
 
Old 02-02-2009, 12:31 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You can try the find command in this way:
Code:
find ~/html -mindepth 1 ! \( -name \*.html -o -name \*.htm \) -exec echo rm {} \;
I intentionally left a echo before the rm command, to let you test the result before actually remove anything. When you're sure the output is exactly what do you want to achieve, remove the echo command and the trick is done.
 
Old 02-02-2009, 12:58 PM   #3
alan43
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks, it works very well
 
  


Reply


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
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 04:43 PM
delete not needed servers modules at webmin cccc Debian 2 05-01-2007 09:31 AM
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 10:14 PM
Preinstalled Win XP Pro: Keep or Delete? Needed or just taking up space? hanzj Linux - Newbie 11 04-20-2005 07:35 PM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 02:13 PM

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

All times are GMT -5. The time now is 11:55 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration