1

I have been using the following code for the longest on a system I took over:

find /mnt/tmp -atime +91 -exec rm -f {} \;

However, researching further I see everyone saying the curly braces should be enclosed in single quotes like below:

find /mnt/tmp -atime +91 -exec rm -f '{}' \;

I have never had issues before, but I am curious of any negative impact not using the single quotes might have. Also curious if it varies across linux flavors?

The servers are Ubuntu.

4
  • you may want to add '-type f' so it won't complain it can't "rm" a directory? : find /mnt/tmp -type f -atime +91 -exec rm -f '{}' \; Nov 21, 2013 at 19:46
  • A simpler version is: find /mnt/tmp -atime +91 -delete - or use tmpwatch/tmpreaper :) Nov 21, 2013 at 19:48
  • @DennisKaarsemaker, is there any difference in functionality between rm -f and -delete in the way I am trying to use it? @ Oliver, thanks for the input :)
    – Damainman
    Nov 26, 2013 at 7:38
  • 1
    Yes, -exec rm -f forks and exec's one rm per file. -delete makes find simply unlink the file, that's a lot faster. Nov 27, 2013 at 19:57

1 Answer 1

1

The impacts you're speaking of will show up if you have "special" characters in your filenames (as distinct from regex-type special characters). The most obvious would be if you have a file named foo /* - your rm command would go and remove foo then /* without the single quotes, which you probably wouldn't want.

1
  • Ahh thanks. Yes currently the files are all alphanumeric with no spaces or special characters, which would explain why I haven't ran into any issues. Thank you.
    – Damainman
    Nov 21, 2013 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .