LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to use rm to keep the files needed and delete others (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-use-rm-to-keep-the-files-needed-and-delete-others-701679/)

alan43 02-02-2009 11:22 AM

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

colucix 02-02-2009 11:31 AM

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.

alan43 02-02-2009 11:58 AM

Thanks, it works very well


All times are GMT -5. The time now is 12:17 PM.