Find the answer to your Linux question:
Results 1 to 5 of 5
Hello I've got this line find . -type d -name 'elements' -exec rm -rf {} \; put together to find and delete all directories named elements and their contents. It ...
  1. #1
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277

    find a dir and delete it

    Hello

    I've got this line find . -type d -name 'elements' -exec rm -rf {} \; put together to find and delete all directories named elements and their contents.

    It does work but whenever I run it I get the error/warning

    Code:
    find: `./dir3/elements': No such file or directory                                                    
    find: `./dir6/elements': No such file or directory                                                    
    find: `./elements': No such file or directory
    Does anyone know why? It does delete all directories and subdirectories under the name elements though.

    Thank you
    One Love!!!

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    Could not figure out why. If it's really annoying, you can redirect to /dev/null or pipe the output of find to rm
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

  3. #3
    Linux Newbie
    Join Date
    Sep 2004
    Location
    UK
    Posts
    160
    Try

    Code:
    find  .  -name "elements"    -type d  -prune -exec rm -rf {} \;
    It's probably doing the delete at the higher level, then visiting the child sub/directories. Which are no longer there hence the error messages (just a guess)
    In a world without walls and fences, who needs Windows and Gates?

  4. #4
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Thanks guys
    One Love!!!

  5. #5
    Just Joined! Feeyo's Avatar
    Join Date
    Apr 2010
    Posts
    54
    Or easier:
    Code:
    find . -name elements -delete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...