Delete all files in a folder that don't match a certain file extension

2010-04-30 1 min read bash Fedora Linux

$ rm !(.foo|.bar|*.baz)

Deletes all files in a folder that are NOT *.foo, *.bar or *.baz files. Edit the pattern inside the brackets as you like.

  • <a href="http://www.commandlinefu.com/commands/view/5351/delete-all-files-in-a-folder-that-dont-match-a-certain-file-extension">View this command to comment, vote or add to favourites
  • <a href="http://feeds2.feedburner.com/commands/by/hutch">View all commands by <a href="http://feeds2.feedburner.com/commands/by/hutch">hutch

<a href="http://www.commandlinefu.com"><img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/header-logo.jpg" alt="" align="bottom" />

by David Winterbottom (<a href="http://codeinthehole.com">codeinthehole.com)

<a href="http://feedads.g.doubleclick.net/~a/kewaFMgsXI4A1vQfeLscg2Vcv8o/0/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/kewaFMgsXI4A1vQfeLscg2Vcv8o/0/di" alt="" align="bottom" />
<a href="http://feedads.g.doubleclick.net/~a/kewaFMgsXI4A1vQfeLscg2Vcv8o/1/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/kewaFMgsXI4A1vQfeLscg2Vcv8o/1/di" alt="" align="bottom" />

<img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~r/Command-line-fu/~4/TCRb2ku_V1Y" alt="" width="1" height="1" align="bottom" />

URL: <a href="http://feedproxy.google.com/~r/Command-line-fu/~3/TCRb2ku_V1Y/delete-all-files-in-a-folder-that-dont-match-a-certain-file-extension">http://feedproxy.google.com/~r/Command-line-fu/~3/TCRb2ku_V1Y/delete-all-files-in-a-folder-that-dont-match-a-certain-file-extension<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://blog.amit-agarwal.co.in/2010/04/12/visualizing-system-performance-data/">Visualizing system performance data (amit-agarwal.co.in) <li class="zemanta-article-ul-li"><a href="http://www.macworld.com/reviews/product/499328/review/moofmenu_183.html?expand=true">MoofMenu puts your files in the menu bar (macworld.com) <li class="zemanta-article-ul-li"><a href="http://domainmacher.com/shadyemail-mask-your-email-to-make-it-look-suspicious/">ShadyEmail: Mask Your Email to Make it Look Suspicious (domainmacher.com) <li class="zemanta-article-ul-li"><a href="http://emilychang.com/ehub/app/like-it-tweet-it/">Like it? Tweet it! (emilychang.com) <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/b8c8dbb8-3746-462e-a8cb-d66d1d28031e/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b74.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">

comments powered by Disqus