devork

E pur si muove

Campaigning for -delete

Tuesday, May 01, 2007

Whenever find(1) is used to delete some files there are always a few variants that can be seen. They are generally combinations of -exec and -print piped to xargs. While demonstrating the increadible power of UNIX shells and pipes etc they don't appear very practical.

Most implementations struggle with embedded spaces, newlines, quotes etc. So even more exciting things get produced to cope with all these weird things. So why not simply use -delete at the end of the desired expression? Is it because it is a GNU extension? I swear that most of the expressions that actually try to cope with weird filenames depend on GNU extensions anyway. Not to mention that most of the scripts know they will have GNU find and don't behave scrictly POSIX compliant anyway.

So why is it that in no example -delete is used? There's no point as far as I can tell.

In light of that this post is my campain for the more frequent use of -delete in find(1) expressions. I'm sure you won't care. Neither will I; by tomorrow I'll have forgotten about this campain. But at least I'll be using -delete myself.

Tuesday, May 01, 2007 |

5 comments:

Jay Parlar said...

At a minimum, while it may be GNU, it does seem to appear in the (BSD) OS X 'find'.

And OS X generally gets its userspace BSD stuff from FreeBSD and NetBSD, so it probably lives there too.

And I didn't know about -delete either, so add another success to your campaign.

Paddy3118 said...

Hi Floris,
find is one of those core unix utilities that doesn't stick to doing one thing well. Personally I think -exec is going to far.
Let find find stuff, you can pipe it to other commands to do things with what is found :-)

- Paddy.

mike said...

I hadn't known about -delete, either.

It's pretty cool, but not present in my work CentOS 4.4 box, which has findutils 4.1.20.

I was curious, so dug around a bit. It looks like a pretty new feature - 4.2.3 and up; according to the changelog it was added 2004-10-30.

This could explain some of the lack of use out there.

On with your campaign!

New comments are not allowed.

Subscribe to: Post Comments (Atom)