Gentoo Archives: gentoo-user

From: Alan McKinnon <alan.mckinnon@×××××.com>
To: gentoo-user@l.g.o
Cc: Grant <emailgrant@×××××.com>
Subject: Re: [gentoo-user] Any way around "Argument list too long"?
Date: Sun, 17 Jul 2011 23:40:25
Message-Id: 16810050.Acf57OJLs1@nazgul
In Reply to: Re: [gentoo-user] Any way around "Argument list too long"? by Grant
1 On Sunday 17 July 2011 16:23:54 Grant did opine thusly:
2 > > way around "Argument list too long"?:
3 > >> My crontab deletes all files of a certain type in a certain
4 > >> folder with yesterday's date in the filename. It usually
5 > >> executes but sometimes fails with:
6 > >>
7 > >> /bin/rm: Argument list too long
8 > >>
9 > >> What would you do about this?
10 > >
11 > > Use find with the -delete option.
12 >
13 > I'm getting the same thing from find:
14 >
15 > $ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday'
16 > +\%Y\%m\%d`*.jpg /usr/bin/find: Argument list too long
17 >
18 > $ /usr/bin/find -delete /home/user/*-`/bin/date -d 'yesterday'
19 > +\%Y\%m\%d`*.jpg /usr/bin/find: Argument list too long
20 >
21 > $ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday'
22 > +\%Y\%m\%d`*.jpg|xargs rm /usr/bin/find: Argument list too long
23 > rm: missing operand
24 > Try `rm --help' for more information.
25
26 You are doing it wrong.
27
28 Each command has something between ``, so bash is expanding that
29 entire list and just before feeding the whole lot to find, realizes
30 that the list is longer than 65,536 characters. It's bash that is
31 returning that error, not find.
32
33 You're mistake is trying to marrow down *where* find should look
34 instead of *what* it should look for.
35
36 You something like this:
37
38 find /home/user -type f -name "`/bin/date -d 'yesterday'
39 +\%Y\%m\%d`*.jpg`"
40
41 See the difference? That will not produce a gigantic command line, it
42 will produce a rather short one and find will check each file it finds
43 one by one and see if it's name matches the supplied pattern.
44
45 Word of warning: DO NOT blindly run -delete on this, first check the
46 total output and make sure it only has what you want to delete. As
47 with all things concerning rm or file deletion, the burden rests on
48 you to make completely sure you delete only what you want to delete.
49
50
51 --
52 alan dot mckinnon at gmail dot com

Replies

Subject Author
Re: [gentoo-user] Any way around "Argument list too long"? Grant <emailgrant@×××××.com>