Ben's Blog

I.T., unix / linux ben May 27, 2009

recursive name based delete

Here’s a neat little command that will let you delete specified files/directories recursively and based on their names.

Let’s do a dry run first to make sure that the command will go through the right files. Run:

[bash]<code class="plain plain">find <directory_to_start_the_recursion_in> -name <file_name</code>>[/bash]

Keep in mind that if you’re gonna have asterisks (*) in the <file_name> you need to escape them like so:

[bash]find /var/www -name *.jpg[/bash]

make sure that the result only lists the files/directories that you indeed want to obliterate. Then improve that last command by adding:

[bash]find <directory_to_start_the_recursion_in> -name <file_name> -exec rm -rf {} ;[/bash]

Since this is a pretty dangerous command even after a dry run, you can use -ok instead of -exec which will prompt you for approval everytime the command it executed.

[bash]find <directory_to_start_the_recursion_in> -name <file_name> -ok rm -rf {} ;[/bash]

This is of course not limited to rm 🙂

Leave a Comment

Cancel reply

This blog is solar powered

Interactive

Handwriting Capture
Mandalagaba
IPv6 link-local to MAC converter
IPv6 MAC to link-local converter
Markov Text Generation
Markov Word Generation
Markov Music Generation
Duplogrifier
Flood Fill Algorithms
Homestead Metrics
RGB Playground
Web Games

Categories

  • aesthetics111
    • plots54
    • specular holography6
  • Books3
  • I.T.202
    • 3D modeling / printing21
    • AI6
    • all out geekery36
    • electronics27
    • homestead automation6
    • maniacal paranoia25
    • plotters49
    • unix / linux29
    • video games4
    • web development29
    • web games3
  • Lego / Duplo67
  • life in the U.S.42
  • miscellaneous202
  • nature encounters114
  • old vinyls3
  • organs2
  • self sustainability560
    • agriculture105
    • apiculture38
    • apple20
    • building131
    • canning3
    • crochet6
    • foraging6
    • hunting10
    • maple syrup47
    • poultry39
    • preserving2
    • solar power28
    • water23
    • wood84
  • trip to a new life6
Theme by Bloompixel. Proudly Powered by WordPress