LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find mtime exec still gets too many arguments (https://www.linuxquestions.org/questions/linux-newbie-8/find-mtime-exec-still-gets-too-many-arguments-929908/)

anon091 02-17-2012 09:28 AM

find mtime exec still gets too many arguments
 
I thought the trick when you couldn't do a straight up rm on a large number of files was to do a
find /path/* -mtime +7 -exec rm -rf {} \;
but is there a trick for when even that kicks back a too many warning? or do i just need to use it multiple times with a more specific wildcard?

jhwilliams 02-17-2012 09:37 AM

Hm, really? How many files are you trying to delete? What is the specific text of the error message? I've not encountered such a problem before, but would be curious to see.

Anyway, you could of course split up the problem size.

If there's not another more direct solution with find.

anon091 02-17-2012 09:40 AM

think it's like over 480,000 or so? and i'm getting the too many arguments error.

jhwilliams 02-17-2012 09:49 AM

Ah, maybe this, that glob is probably the issue:

Code:

find /path/* -mtime +7 -exec rm -rf {} \
Try this:

Code:

find /path -mtime +7 | xargs rm
Again, please report your full error, with [ code ] tags.

anon091 02-17-2012 09:54 AM

so no wildcard in that new one you want me to try? won't be able to try it till next week now unfortunately.

jhwilliams 02-17-2012 09:56 AM

Right, I think the wildcard is the problem, not the find command itself.

anon091 02-20-2012 10:16 AM

That worked! Thanks. But can you explain again why this worked? ;)

David the H. 02-20-2012 10:32 AM

Unless quoted or escaped, globbing patterns such as "*" are expanded by the shell before the command is executed. So when you ran the above command, the shell was really trying to run this:

Code:

find /path/file1 /path/file2 /path/file3 /path/file4 (...etc) -mtime +7 -exec rm -rf {} \;
find only needs to be given the top-level director(y/ies) to start searching from, so it's not generally necessary to use globbing patterns there.

But note also that find has it's own built-in globbing ability, for use in options like -name. This is separate from the shell's globbing feature, and so these patterns must be quoted so that the shell passes them to the command as-is. e.g.:

Code:

find /path -type f -name "*.txt" -print
Edit: Speaking of which, you'd probably want to add at least a -type f to your command, to keep it from deleting directories as well. You have to be careful not to match more than you intend it to, especially when deleting things.

anon091 02-20-2012 10:36 AM

Ah, so that's why find was choking, it expands it right there. and now i know what a glob is too. thanks.


All times are GMT -5. The time now is 01:46 AM.