* [gentoo-user] Any way around "Argument list too long"?
@ 2011-07-17 19:32 Grant
2011-07-17 19:42 ` Alan Mackenzie
` (3 more replies)
0 siblings, 4 replies; 25+ messages in thread
From: Grant @ 2011-07-17 19:32 UTC (permalink / raw
To: Gentoo mailing list
My crontab deletes all files of a certain type in a certain folder
with yesterday's date in the filename. It usually executes but
sometimes fails with:
/bin/rm: Argument list too long
What would you do about this?
- Grant
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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
` (2 subsequent siblings)
3 siblings, 0 replies; 25+ messages in thread
From: Alan Mackenzie @ 2011-07-17 19:42 UTC (permalink / raw
To: gentoo-user
Hi, Grant.
On Sun, Jul 17, 2011 at 12:32:42PM -0700, Grant wrote:
> My crontab deletes all files of a certain type in a certain folder
> with yesterday's date in the filename. It usually executes but
> sometimes fails with:
> /bin/rm: Argument list too long
> What would you do about this?
Use xargs - in place of
/bin/rm lots of files ......
Use
Lots_of_file_names | xargs rm
. xargs then calls rm several times with batches of filenames each time.
xargs is a standard Unix command.
> - Grant
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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 21:14 ` Alan McKinnon
3 siblings, 0 replies; 25+ messages in thread
From: victor romanchuk @ 2011-07-17 19:52 UTC (permalink / raw
To: gentoo-user
it could be slightly less efficient comparing to plain `rm', but worked around
your problem:
find <your-dir> -ctime -1 -exec rm {} \;
basically `find' has a lot options filtering result set. these include
time/date, file name (regexp), file type and so on. consult man for details
victor
Grant wrote, at 07/17/2011 11:32 PM:
> My crontab deletes all files of a certain type in a certain folder
> with yesterday's date in the filename. It usually executes but
> sometimes fails with:
>
> /bin/rm: Argument list too long
>
> What would you do about this?
>
> - Grant
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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 21:14 ` Alan McKinnon
3 siblings, 1 reply; 25+ messages in thread
From: David W Noon @ 2011-07-17 19:53 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 609 bytes --]
On Sun, 17 Jul 2011 12:32:42 -0700, Grant wrote about [gentoo-user] Any
way around "Argument list too long"?:
> My crontab deletes all files of a certain type in a certain folder
> with yesterday's date in the filename. It usually executes but
> sometimes fails with:
>
> /bin/rm: Argument list too long
>
> What would you do about this?
Use find with the -delete option.
--
Regards,
Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
dwnoon@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* RE: [gentoo-user] Any way around "Argument list too long"?
@ 2011-07-17 19:54 Pandu Poluan
2011-07-17 21:51 ` Michael Mol
0 siblings, 1 reply; 25+ messages in thread
From: Pandu Poluan @ 2011-07-17 19:54 UTC (permalink / raw
To: gentoo-user
-original message-
Subject: Re: [gentoo-user] Any way around "Argument list too long"?
From: Alan Mackenzie <acm@muc.de>
Date: 2011-07-18 02:42
>Hi, Grant.
>
>On Sun, Jul 17, 2011 at 12:32:42PM -0700, Grant wrote:
>> My crontab deletes all files of a certain type in a certain folder
>> with yesterday's date in the filename. It usually executes but
>> sometimes fails with:
>
>> /bin/rm: Argument list too long
>
>> What would you do about this?
>
>Use xargs - in place of
> /bin/rm lots of files ......
>
>Use
> Lots_of_file_names | xargs rm
>
>. xargs then calls rm several times with batches of filenames each time.
>xargs is a standard Unix command.
You'll want to be extra careful with special characters like (space), single quote, and double quote.
Better use find ..... -exec rm {} +
See: http://en.m.wikipedia.org/wiki/Xargs
Rgds,
--
FdS Pandu E Poluan
~ IT Optimizer ~
Sent from Nokia E72-1
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-17 19:32 [gentoo-user] Any way around "Argument list too long"? Grant
` (2 preceding siblings ...)
2011-07-17 19:53 ` David W Noon
@ 2011-07-17 21:14 ` Alan McKinnon
2011-07-17 22:06 ` [gentoo-user] " walt
3 siblings, 1 reply; 25+ messages in thread
From: Alan McKinnon @ 2011-07-17 21:14 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 437 bytes --]
Are you using wildcards in the arguments to rm ?
Rather use find | xargs or find -exec which are designed to deal with
exactly this circumstance.
On 17 Jul 2011 9:32 PM, "Grant" <emailgrant@gmail.com> wrote:
My crontab deletes all files of a certain type in a certain folder
with yesterday's date in the filename. It usually executes but
sometimes fails with:
/bin/rm: Argument list too long
What would you do about this?
- Grant
[-- Attachment #2: Type: text/html, Size: 648 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-17 19:54 [gentoo-user] " Pandu Poluan
@ 2011-07-17 21:51 ` Michael Mol
0 siblings, 0 replies; 25+ messages in thread
From: Michael Mol @ 2011-07-17 21:51 UTC (permalink / raw
To: gentoo-user
On Sun, Jul 17, 2011 at 3:54 PM, Pandu Poluan <pandu@poluan.info> wrote:
> -original message-
> Subject: Re: [gentoo-user] Any way around "Argument list too long"?
> From: Alan Mackenzie <acm@muc.de>
> Date: 2011-07-18 02:42
>
>>Hi, Grant.
>>
>>On Sun, Jul 17, 2011 at 12:32:42PM -0700, Grant wrote:
>>> My crontab deletes all files of a certain type in a certain folder
>>> with yesterday's date in the filename. It usually executes but
>>> sometimes fails with:
>>
>>> /bin/rm: Argument list too long
>>
>>> What would you do about this?
>>
>>Use xargs - in place of
>> /bin/rm lots of files ......
>>
>>Use
>> Lots_of_file_names | xargs rm
>>
>>. xargs then calls rm several times with batches of filenames each time.
>>xargs is a standard Unix command.
>
> You'll want to be extra careful with special characters like (space), single quote, and double quote.
>
> Better use find ..... -exec rm {} +
>
This is why I use 'find' with the -print0 parameter.
find (path) (filespec) -print0|xargs -0 command
--
:wq
^ permalink raw reply [flat|nested] 25+ messages in thread
* [gentoo-user] Re: Any way around "Argument list too long"?
2011-07-17 21:14 ` Alan McKinnon
@ 2011-07-17 22:06 ` walt
2011-07-17 22:31 ` Mick
2011-07-17 22:35 ` Alan McKinnon
0 siblings, 2 replies; 25+ messages in thread
From: walt @ 2011-07-17 22:06 UTC (permalink / raw
To: gentoo-user
On 07/17/2011 02:14 PM, Alan McKinnon wrote:
> Are you using wildcards in the arguments to rm ?
>
> Rather use find | xargs or find -exec which are designed to deal with
> exactly this circumstance.
>
>> On 17 Jul 2011 9:32 PM, "Grant" <emailgrant@gmail.com
>> <mailto:emailgrant@gmail.com>> wrote:
>>
>> My crontab deletes all files of a certain type in a certain folder
Okay, everyone, back away slowly from this post and then delete it
from your cache. The *real* Alan McKinnon does not top post.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Re: Any way around "Argument list too long"?
2011-07-17 22:06 ` [gentoo-user] " walt
@ 2011-07-17 22:31 ` Mick
2011-07-17 22:35 ` Alan McKinnon
1 sibling, 0 replies; 25+ messages in thread
From: Mick @ 2011-07-17 22:31 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: Text/Plain, Size: 756 bytes --]
On Sunday 17 Jul 2011 23:06:32 walt wrote:
> On 07/17/2011 02:14 PM, Alan McKinnon wrote:
> > Are you using wildcards in the arguments to rm ?
> >
> > Rather use find | xargs or find -exec which are designed to deal with
> > exactly this circumstance.
> >
> >> On 17 Jul 2011 9:32 PM, "Grant" <emailgrant@gmail.com
> >> <mailto:emailgrant@gmail.com>> wrote:
> >>
> >> My crontab deletes all files of a certain type in a certain folder
>
> Okay, everyone, back away slowly from this post and then delete it
> from your cache. The *real* Alan McKinnon does not top post.
Ha, ha! Nor does he use HTML formatting in his messages! o_O
Hmm ... New smartphone or something similar which he hadn't time to hack yet?
--
Regards,
Mick
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Re: Any way around "Argument list too long"?
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
1 sibling, 1 reply; 25+ messages in thread
From: Alan McKinnon @ 2011-07-17 22:35 UTC (permalink / raw
To: gentoo-user
On Sunday 17 July 2011 15:06:32 walt did opine thusly:
> On 07/17/2011 02:14 PM, Alan McKinnon wrote:
> > Are you using wildcards in the arguments to rm ?
> >
> > Rather use find | xargs or find -exec which are designed to deal
> > with exactly this circumstance.
> >
> >> On 17 Jul 2011 9:32 PM, "Grant" <emailgrant@gmail.com
> >> <mailto:emailgrant@gmail.com>> wrote:
> >>
> >> My crontab deletes all files of a certain type in a certain
> >> folder
>
> Okay, everyone, back away slowly from this post and then delete it
> from your cache. The *real* Alan McKinnon does not top post.
He does when his ADSL modem craps out and he's forced to use the GMail
app thingamajigy on his Android phone :-)
Note to self: Put K-9 Mail back on phone for just in case moments like
this.
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Re: Any way around "Argument list too long"?
2011-07-17 22:35 ` Alan McKinnon
@ 2011-07-17 23:16 ` Neil Bothwick
2011-07-17 23:43 ` Alan McKinnon
0 siblings, 1 reply; 25+ messages in thread
From: Neil Bothwick @ 2011-07-17 23:16 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 549 bytes --]
On Mon, 18 Jul 2011 00:35:42 +0200, Alan McKinnon wrote:
> > Okay, everyone, back away slowly from this post and then delete it
> > from your cache. The *real* Alan McKinnon does not top post.
>
> He does when his ADSL modem craps out and he's forced to use the GMail
> app thingamajigy on his Android phone :-)
I'd rather tether my netbook to my phone and stick with real email :)
I hope your employer has better redundancy that you do ;-)
--
Neil Bothwick
Earlier, I didn't have time to finish anything. This time I w
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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
0 siblings, 2 replies; 25+ messages in thread
From: Grant @ 2011-07-17 23:23 UTC (permalink / raw
To: gentoo-user
> way around "Argument list too long"?:
>
>> My crontab deletes all files of a certain type in a certain folder
>> with yesterday's date in the filename. It usually executes but
>> sometimes fails with:
>>
>> /bin/rm: Argument list too long
>>
>> What would you do about this?
>
> Use find with the -delete option.
I'm getting the same thing from find:
$ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday' +\%Y\%m\%d`*.jpg
/usr/bin/find: Argument list too long
$ /usr/bin/find -delete /home/user/*-`/bin/date -d 'yesterday' +\%Y\%m\%d`*.jpg
/usr/bin/find: Argument list too long
$ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday' +\%Y\%m\%d`*.jpg|xargs rm
/usr/bin/find: Argument list too long
rm: missing operand
Try `rm --help' for more information.
- Grant
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-17 23:23 ` Grant
@ 2011-07-17 23:36 ` Michael Mol
2011-07-17 23:37 ` Alan McKinnon
1 sibling, 0 replies; 25+ messages in thread
From: Michael Mol @ 2011-07-17 23:36 UTC (permalink / raw
To: gentoo-user
On Sun, Jul 17, 2011 at 7:23 PM, Grant <emailgrant@gmail.com> wrote:
> I'm getting the same thing from find:
>
> $ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday' +\%Y\%m\%d`*.jpg
> /usr/bin/find: Argument list too long
You're using find wrong; the first argument needs to be the root path
it starts searching from. To find files matching a particular name or
pattern, try using -name or -iname.
DATE=$(/bin/date -d 'yesterday' +\%Y\%m\%d)
find /home/user -name '*-$DATE'
--
:wq
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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
1 sibling, 1 reply; 25+ messages in thread
From: Alan McKinnon @ 2011-07-17 23:37 UTC (permalink / raw
To: gentoo-user; +Cc: Grant
On Sunday 17 July 2011 16:23:54 Grant did opine thusly:
> > way around "Argument list too long"?:
> >> My crontab deletes all files of a certain type in a certain
> >> folder with yesterday's date in the filename. It usually
> >> executes but sometimes fails with:
> >>
> >> /bin/rm: Argument list too long
> >>
> >> What would you do about this?
> >
> > Use find with the -delete option.
>
> I'm getting the same thing from find:
>
> $ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg /usr/bin/find: Argument list too long
>
> $ /usr/bin/find -delete /home/user/*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg /usr/bin/find: Argument list too long
>
> $ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg|xargs rm /usr/bin/find: Argument list too long
> rm: missing operand
> Try `rm --help' for more information.
You are doing it wrong.
Each command has something between ``, so bash is expanding that
entire list and just before feeding the whole lot to find, realizes
that the list is longer than 65,536 characters. It's bash that is
returning that error, not find.
You're mistake is trying to marrow down *where* find should look
instead of *what* it should look for.
You something like this:
find /home/user -type f -name "`/bin/date -d 'yesterday'
+\%Y\%m\%d`*.jpg`"
See the difference? That will not produce a gigantic command line, it
will produce a rather short one and find will check each file it finds
one by one and see if it's name matches the supplied pattern.
Word of warning: DO NOT blindly run -delete on this, first check the
total output and make sure it only has what you want to delete. As
with all things concerning rm or file deletion, the burden rests on
you to make completely sure you delete only what you want to delete.
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Re: Any way around "Argument list too long"?
2011-07-17 23:16 ` Neil Bothwick
@ 2011-07-17 23:43 ` Alan McKinnon
0 siblings, 0 replies; 25+ messages in thread
From: Alan McKinnon @ 2011-07-17 23:43 UTC (permalink / raw
To: gentoo-user
On Monday 18 July 2011 00:16:40 Neil Bothwick did opine thusly:
> On Mon, 18 Jul 2011 00:35:42 +0200, Alan McKinnon wrote:
> > > Okay, everyone, back away slowly from this post and then
> > > delete it from your cache. The *real* Alan McKinnon does
> > > not top post.
> >
> > He does when his ADSL modem craps out and he's forced to use the
> > GMail app thingamajigy on his Android phone :-)
>
> I'd rather tether my netbook to my phone and stick with real email
> :)
My old G1 is stuck on Donut :-(
Everything from Eclair onwards just kills the poor thing, and
tethering never worked reliably.
> I hope your employer has better redundancy that you do ;-)
Of course :-) Everything on the core network is at least duplicated.
As for us plebs at home, our usual backup is the 3G card but between
one team member crashing a motorbike badly, another (me) crashing a
motorbike poorly, one off sick with flu, one transferred to another
team, and everyone at home without petrol (fuel and metal workers
strike ... please don't ask), none of us remember where the damn card
is anymore.
The other redundancy is the back up modem, which I have never needed
to use and now suffers from a bad case of electron-rot. OK, it's
probably electrolytic caps deteriorated from heat, but electron rot
sounds much more dramatic ;-)
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-17 23:37 ` Alan McKinnon
@ 2011-07-18 0:47 ` Grant
2011-07-18 1:05 ` Albert Hopkins
0 siblings, 1 reply; 25+ messages in thread
From: Grant @ 2011-07-18 0:47 UTC (permalink / raw
To: Gentoo mailing list
> You are doing it wrong.
>
> Each command has something between ``, so bash is expanding that
> entire list and just before feeding the whole lot to find, realizes
> that the list is longer than 65,536 characters. It's bash that is
> returning that error, not find.
>
> You're mistake is trying to marrow down *where* find should look
> instead of *what* it should look for.
>
> You something like this:
>
> find /home/user -type f -name "`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg`"
>
> See the difference? That will not produce a gigantic command line, it
> will produce a rather short one and find will check each file it finds
> one by one and see if it's name matches the supplied pattern.
>
> Word of warning: DO NOT blindly run -delete on this, first check the
> total output and make sure it only has what you want to delete. As
> with all things concerning rm or file deletion, the burden rests on
> you to make completely sure you delete only what you want to delete.
I 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
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?
- Grant
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-18 0:47 ` Grant
@ 2011-07-18 1:05 ` Albert Hopkins
2011-07-18 1:40 ` Grant
0 siblings, 1 reply; 25+ messages in thread
From: Albert Hopkins @ 2011-07-18 1:05 UTC (permalink / raw
To: gentoo-user
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.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-18 1:05 ` Albert Hopkins
@ 2011-07-18 1:40 ` Grant
2011-07-18 8:48 ` Neil Bothwick
0 siblings, 1 reply; 25+ messages in thread
From: Grant @ 2011-07-18 1:40 UTC (permalink / raw
To: gentoo-user
>> 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.
Alright, find is tricky. Is this the right spot for -delete?
/usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
+\%Y\%m\%d`*.jpg" - delete
- Grant
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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
0 siblings, 2 replies; 25+ messages in thread
From: Neil Bothwick @ 2011-07-18 8:48 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 452 bytes --]
On Sun, 17 Jul 2011 18:40:44 -0700, Grant wrote:
> Alright, find is tricky. Is this the right spot for -delete?
>
> /usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg" - delete
Yes, but if you don't want irreversible mistakes, move the files instead.
find /home/user -type f -name blah -exec mv -t ~/.Trashcan "{}" +
--
Neil Bothwick
The facts, although interesting, are usually irrelevant.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-18 8:48 ` Neil Bothwick
@ 2011-07-18 21:56 ` Grant
2011-07-19 13:58 ` Florian Philipp
1 sibling, 0 replies; 25+ messages in thread
From: Grant @ 2011-07-18 21:56 UTC (permalink / raw
To: gentoo-user
>> Alright, find is tricky. Is this the right spot for -delete?
>>
>> /usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
>> +\%Y\%m\%d`*.jpg" - delete
>
> Yes, but if you don't want irreversible mistakes, move the files instead.
>
> find /home/user -type f -name blah -exec mv -t ~/.Trashcan "{}" +
Thanks Neil and everyone.
- Grant
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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
` (2 more replies)
1 sibling, 3 replies; 25+ messages in thread
From: Florian Philipp @ 2011-07-19 13:58 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 865 bytes --]
Am 18.07.2011 10:48, schrieb Neil Bothwick:
> On Sun, 17 Jul 2011 18:40:44 -0700, Grant wrote:
>
>> Alright, find is tricky. Is this the right spot for -delete?
>>
>> /usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
>> +\%Y\%m\%d`*.jpg" - delete
>
> Yes, but if you don't want irreversible mistakes, move the files instead.
>
> find /home/user -type f -name blah -exec mv -t ~/.Trashcan "{}" +
>
>
In all these commands it would always be a good idea to deactivate
parameter parsing just in front of the place where the file names are
inserted.
find ... -print0 | xargs -0 mv -t ~/.Trashcan --
or
find ... -exec mv -t ~/.Trashcan -- "{}" +
The double dash will prevent mv from interpreting weird file names like
"-h" as parameters. Just about every standard GNU tool supports this.
Regards,
Florian Philipp
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-19 13:58 ` Florian Philipp
@ 2011-07-19 14:24 ` Neil Bothwick
2011-07-19 18:24 ` Grant
2011-07-20 8:54 ` Joost Roeleveld
2 siblings, 0 replies; 25+ messages in thread
From: Neil Bothwick @ 2011-07-19 14:24 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 311 bytes --]
On Tue, 19 Jul 2011 15:58:44 +0200, Florian Philipp wrote:
> In all these commands it would always be a good idea to deactivate
> parameter parsing just in front of the place where the file names are
> inserted.
Very good point!
--
Neil Bothwick
This is the day for firm decisions! Or is it?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
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
2 siblings, 1 reply; 25+ messages in thread
From: Grant @ 2011-07-19 18:24 UTC (permalink / raw
To: gentoo-user
>>> Alright, find is tricky. Is this the right spot for -delete?
>>>
>>> /usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
>>> +\%Y\%m\%d`*.jpg" - delete
>>
>> Yes, but if you don't want irreversible mistakes, move the files instead.
>>
>> find /home/user -type f -name blah -exec mv -t ~/.Trashcan "{}" +
>>
>>
>
> In all these commands it would always be a good idea to deactivate
> parameter parsing just in front of the place where the file names are
> inserted.
>
> find ... -print0 | xargs -0 mv -t ~/.Trashcan --
> or
> find ... -exec mv -t ~/.Trashcan -- "{}" +
>
> The double dash will prevent mv from interpreting weird file names like
> "-h" as parameters. Just about every standard GNU tool supports this.
Does that apply to a command like this:
/usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
+\%Y\%m\%d`*.jpg" -delete
Maybe it should be changed to this:
/usr/bin/find /home/user -type f -name -- "*-`/bin/date -d 'yesterday'
+\%Y\%m\%d`*.jpg" -delete
- Grant
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-19 18:24 ` Grant
@ 2011-07-19 19:28 ` David W Noon
0 siblings, 0 replies; 25+ messages in thread
From: David W Noon @ 2011-07-19 19:28 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 1558 bytes --]
On Tue, 19 Jul 2011 11:24:55 -0700, Grant wrote about Re: [gentoo-user]
Any way around "Argument list too long"?:
[snip]
> > The double dash will prevent mv from interpreting weird file names
> > like "-h" as parameters. Just about every standard GNU tool
> > supports this.
>
> Does that apply to a command like this:
>
> /usr/bin/find /home/user -type f -name "*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg" -delete
No.
The find command is far too complicated for such a simple mechanism to
make sense. Stopping the parser on such a character sequence has the
potential for disaster.
> Maybe it should be changed to this:
>
> /usr/bin/find /home/user -type f -name -- "*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg" -delete
If you wish to delete JPEG files that are a day or more old, you might
be better off using the ctime field in the directory entry:
find /home/user -daystart -ctime 0 -type f -name \*.jpg -delete
To see which files would be deleted, run the above command with -delete
replaced by -print.
Note also that the "back-quote" notation for command sub-shells has been
deprecated since about 1993. See:
http://compute.cnr.berkeley.edu/cgi-bin/man-cgi?ksh+1
and scroll down to the bottom of page 11. You are better off using the
more modern $(command ...) notation.
--
Regards,
Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
dwnoon@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [gentoo-user] Any way around "Argument list too long"?
2011-07-19 13:58 ` Florian Philipp
2011-07-19 14:24 ` Neil Bothwick
2011-07-19 18:24 ` Grant
@ 2011-07-20 8:54 ` Joost Roeleveld
2 siblings, 0 replies; 25+ messages in thread
From: Joost Roeleveld @ 2011-07-20 8:54 UTC (permalink / raw
To: gentoo-user
Top-posting IMPORTANT NOTE ON TOP
Do NOT create the file I mention below unless you WANT to risk deleting ALL
your files.
On Tuesday 19 July 2011 15:58:44 Florian Philipp wrote:
> The double dash will prevent mv from interpreting weird file names like
> "-h" as parameters. Just about every standard GNU tool supports this.
Or worse, a file called " -rf ".
If anyone wants to try what happens when " rm * " finds that file, please do so
ONLY on a machine you want to wipe anyway...
--
Joost
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2011-07-20 8:55 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox