public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Albert Hopkins <marduk@letterboxes.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Any way around "Argument list too long"?
Date: Sun, 17 Jul 2011 21:05:10 -0400	[thread overview]
Message-ID: <1310951110.304502.9.camel@localhost.localdomain> (raw)
In-Reply-To: <CAN0CFw2RX2wZQaxVmmoSShwZwdKZXDr1c-WOCsnZpJjrGzp3DA@mail.gmail.com>



On Sunday, July 17 at 17:47 (-0700), Grant said:

> ran this and the output was voluminous but looked good:
> 
> /usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg"
> 
> So I ran it again, adding -delete right before -type.  After a lot of
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That was a mistake.

> processing I got a line of output like this for each file:
> 
> /usr/bin/find: `/home/user/1-2011071612345.jpg': No such file or
> directory
> 
> Unfortunately the command actually deleted the entire /home/user
> folder.  Can anyone tell me what went wrong?  Maybe '/home/user' was
> at the very top of the long list that scrolled up the screen when I
> ran the find command without -delete?
> 
Well this is an unfortunate way to learn how find works.  A better way
would be:

$ man find

Basically find works of a chain of selection criteria.  It crawls all
the files/dirs and when one item in the chain is true for the criteria,
it checks for the other.  For example

$ find /path -type f -name blah -print

Crawls /path, for each file/dir it checks if it is a regular file (-type
f), if that is true, it checks if it's name is "blah", if that is true,
it prints the name (blah).

Therefore, 

$ find /path -delete -type f -name ....

Crawls path, then checks "-delete".. but wait, -delete evaluates to
"true if removal succeeded" (find(1)), so it deletes the file, then
checks to see if it is a regular file, then if that is true then it
checks the name... but all that doesn't matter because your files are
deleted.

You should never put -delete at the beginning of a chain and, arguably,
you shouldn't use -delete at all.  It even says in the man page:

        Warnings:  Don't  forget that the find command line is evaluated
        as an expression, so putting -delete first will make find try to
        delete everything below the starting points you specified.  When
        testing a find command line that you later intend  to  use  with
        -delete,  you should explicitly specify -depth in order to avoid
        later surprises.  Because -delete  implies  -depth,  you  cannot
        usefully use -prune and -delete together.







  reply	other threads:[~2011-07-18  1:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-17 19:32 [gentoo-user] Any way around "Argument list too long"? Grant
2011-07-17 19:42 ` Alan Mackenzie
2011-07-17 19:52 ` victor romanchuk
2011-07-17 19:53 ` David W Noon
2011-07-17 23:23   ` Grant
2011-07-17 23:36     ` Michael Mol
2011-07-17 23:37     ` Alan McKinnon
2011-07-18  0:47       ` Grant
2011-07-18  1:05         ` Albert Hopkins [this message]
2011-07-18  1:40           ` Grant
2011-07-18  8:48             ` Neil Bothwick
2011-07-18 21:56               ` Grant
2011-07-19 13:58               ` Florian Philipp
2011-07-19 14:24                 ` Neil Bothwick
2011-07-19 18:24                 ` Grant
2011-07-19 19:28                   ` David W Noon
2011-07-20  8:54                 ` Joost Roeleveld
2011-07-17 21:14 ` Alan McKinnon
2011-07-17 22:06   ` [gentoo-user] " walt
2011-07-17 22:31     ` Mick
2011-07-17 22:35     ` Alan McKinnon
2011-07-17 23:16       ` Neil Bothwick
2011-07-17 23:43         ` Alan McKinnon
  -- strict thread matches above, loose matches on Subject: below --
2011-07-17 19:54 [gentoo-user] " Pandu Poluan
2011-07-17 21:51 ` Michael Mol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1310951110.304502.9.camel@localhost.localdomain \
    --to=marduk@letterboxes.org \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox