Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Recursive Delete throughout Multiple Directories

  1. #1
    Join Date
    Jun 2013
    Beans
    20

    Recursive Delete throughout Multiple Directories

    Hey there,

    So I want to delete all avgd files in all directories, hopefully with one command. I was curious if this would be acceptable (I'm very nervous about wiping out everything and not just the intended):

    Code:
    rm -ir *avgd
    The intention is to delete interactively so it only deletes what I intended, and -r for recursive.
    I'm not sure the wild care * works that way though, I've only used it on file types, not general words.

    Is this the way, is there another way, or will I just have to go through each and every location manually?

    Stats:
    Ubuntu 13.04, 32-bit

    Thanks!
    jll339

  2. #2
    Join Date
    Apr 2008
    Location
    Southern California, USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Recursive Delete throughout Multiple Directories

    This is a dangerous command and you should be nervous. First off , back up your system. You could test it on a dummy dir's and files first.

  3. #3
    Join Date
    Jun 2013
    Beans
    20

    Re: Recursive Delete throughout Multiple Directories

    Good idea, thanks!

  4. #4
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    find

    You could use find:

    Code:
    find . -name "*avgd" -exec echo rm {} \;
    You can see the full list of options in the manual page for find. But the above looks recursively in the current directory for any files ending in avgd and then does an 'echo' with the file name in the text. Remove 'echo' once the output is what you want.

  5. #5
    Join Date
    Jun 2013
    Beans
    20

    Re: Recursive Delete throughout Multiple Directories

    The avgd files all end in different file types, though.
    Last edited by jll339; June 19th, 2013 at 07:43 PM.

  6. #6
    Join Date
    Oct 2005
    Location
    Al Ain
    Beans
    8,414

    Re: Recursive Delete throughout Multiple Directories

    Yes, that command is OK.

    What NOT to do:
    NEVER use *. with rm, because * includes . meaning that you can then get .. which will back up one directory, which will then cause it to eventually recurse over the whole file system, which is usually not what you want.

  7. #7
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Recursive Delete throughout Multiple Directories

    Quote Originally Posted by jll339 View Post
    Nope... didn't work at all. Ok thanks unless anybody has any other ideas I guess I'll do it manually. Thanks again!
    The find command listed above won't actally delete anything until you modify it. How to modify it should become more obvious once you get more familiar with how it works and what it does.

  8. #8
    Join Date
    Jun 2013
    Beans
    20

    Re: Recursive Delete throughout Multiple Directories

    Quote Originally Posted by Lars Noodén View Post
    The find command listed above won't actally delete anything until you modify it. How to modify it should become more obvious once you get more familiar with how it works and what it does.
    Hi thanks for your code from earlier, I actually made a test and tried it out on that. It worked perfectly! The not working comment I made and later changed was for another before I realized you had made a new post. Sorry!

    I liked the echo part, it helped to clarify. Thanks again! I will use this method.

  9. #9
    Join Date
    Jun 2013
    Beans
    20

    Red face Re: Recursive Delete throughout Multiple Directories

    Done! Thanks again! Quick question before I close this, I'm just curious as to why
    Code:
    locate avgd
    will still show all these files and directories that don't exist anymore?

  10. #10
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    locate

    locate searches a database (/var/lib/mlocate/mlocate.db) which is a snapshot of the system at the time the database was filled. So if you move things around, install or uninstall things, the contents of the database will vary from what is really there.

    You should be able to force an update manually.

    Code:
    sudo updatedb
    Otherwise, the database should get updated daily when your daily cronjobs get run.
    What the database contains can be fine tuned in /etc/updatedb.conf

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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