Hi everyone, i'd like someone chechk this script, i know it's very simple but it doesn't work good, let me tell you this script works over huge directories, maybe that's the problem, if somebody can give me other way to develop, or show me where it's the problem, i'll appreciate it.
This may be due to the ARG_MAX... every server (OS) has its own kernel limit set to argument length if it goes beyond that (that might be the case your rm command facing)..
i'm working with Red Hat 5 Enterprise, i understand what you mean, but how i can find out what to? My boss ask me for some script which do that, it was very simple, but i just a beginner.
Could you help me?
-name can match files like you were doing inside the shell, without having to match inside the shell, avoiding the 'too many arguments' problem. Putting it in single quotes prevents the shell from trying to expand it too soon.
Using '+' instead of ';' will cause it to put as many files as it can into each rm call instead of running rm 10,000 individual times for 10,000 individual files, which will make it more efficient.
Remove the echo once you've tested and are sure it does what you want.
Hi Corona, as usually, your solution are the best, i got the idea, but your way produce me others doubts, for example the "\" with that spaces at the end of each line, for what are they?
The other question, if i use this code just like you put it on, show, or print me, it works?
Just one line to delete at the end?
And the last one, why should i remove the echo?
xargs transforms text into arguments. These two commands are equivalent, for instance:
cat a b c
echo a b c | xargs cat
If you leave -exec off of find it just does its default action instead, which is, print every filename on a separate line. If you feed that into xargs commandname, it will run commandname with the filenames as arguments. If it's too many filenames to fit into one call, it will run commandname several times.
So, find without xargs:
find ... -exec something '{}' '+'
find with xargs:
find ... | xargs something
The version with -exec is preferable if you can, because spaces and quote-characters in filenames and paths can confuse xargs. -exec has no such problem, to the point that find is a useful tool for removing files which somehow ended up with humanly untypable names.