6/28/2006 ↓

rm on steroids

Author: Mark Ghosh Category: General

Thanks for visiting! We would like to serve you better. Please subscribe to our RSS feed for daily updates. This blog posts regular Wordpress news, updates of themes, plugins, ideas, hacks, quick fixes and everything about blogging, especially about Wordpress. You can also receive updates from this blog via email if you want that method of notification.

If you run Linux and have been working with the filesystem(s) for any length of time, you have used and abused rm. However, when the number of files concerned is very large or there are unescaped characters in your filenames, rm can misbehave. The following code will take care of all your worries. The exec command always makes me stand back and wonder at the power of the Linux shell.
find . -name '*.*' -exec rm {} \;
From: http://howtos.linux.com/guides/abs-guide/moreadv.shtml

Also, Veen overhears an rm conversation

[EDIT] Be very careful using find to remove files.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Visitors who read this post, also read:

    Friends

    Translate

    Translate to German Translate to Spanish Translate to French Translate to Italian Translate to Portuguese Translate to Japanese Translate to Korean Translate to Russian Translate to Chinese

    Latest Videos

    8 Comments | Leave a comment | Comments RSS

    1. Ok, that erases all your files with a dot in the name… What about “rm -rf .”?

      [Reply] Pablo Lopez Cienfuegos (1 comments.) — 06/28/2006 @ 11:42 am
    2. Be very careful using find to remove files.

      The find command by default is recursive so any and all files in all subdirs below the current directory will go away too.

      Using ‘*.*’ for the pattern will miss all files without dots in them. rm is not able to remove the directories so you will get an error for each of them found (include ‘.’, the current dir).

      If you really want to remove all files from the current directory through all it’s subdirectories and leave the dirs alone then the better find parameters would be:
      find . -type f -exec rm {} \;

      You could also use “find . -exec rm {} \;” and ignore the errors rm throws out for the dirs.

      [Reply] Anton Olsen (5 comments.) — 06/28/2006 @ 12:02 pm
    3. Very good advice indeed. My post was much more general but the link explains things further.
      The best advice is to use the find without the rm to see what gets included before using the rm in the exec.

      [Reply] Mark (118 comments.) — 06/28/2006 @ 12:25 pm
    4. I posted about this a few days ago:
      http://raybdbomb.com/p/argument-list-too-long.html

      find . -name ‘*\.*’ | xargs rm

      [Reply] Ray (5 comments.) — 06/28/2006 @ 12:56 pm
    5. rm on steroids (a safer way)

      I came across an excellent tip about mixing rm and find commands in Linux shell.
      The only thing I’d add to it is a bit of safety. Before executing the mix of find and rm, run the find command with the same options, but without rm. It will pri…

      Blog of Leonid Mamchenkov — 06/28/2006 @ 2:11 pm
    6. Try

      find . -name ‘*.*’ -exec rm -rf {} \;

      if you want to erase everything. Of course, I have yet to find a purpose for doing such except to be mean to *n*x newbies.

      NOTE: This will erase everything - do NOT try.

      [Reply] zeroHalo (1 comments.) — 06/28/2006 @ 3:23 pm
    7. If you’re converting from mod_php to phpsuexec on a cpanel system, the following commands help:

      find /home/user/public_html/ -user nobody -exec chown user:user {} \;
      find /home/user/public_html/ -perm 777 -exec chmod 755 {} \;

      Run that for each user on the system, and you won’t have any phpsuexec internal server errors.

      [Reply] Mike Bailey (1 comments.) — 06/28/2006 @ 4:23 pm
    8. find . -name ‘*.*’ -exec rm -rf {} \;

      is really, really mean :x

      [Reply] jez (55 comments.) — 07/2/2006 @ 12:09 pm

    Leave a comment

    Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    (required)

    (required, will not be published)


    S2