Wednesday, 13 May 2015

SOLVED Argument list too long bash issue for rm, ls, mv, cp

In case you have folder with many files and you want to list, move, copy or delete them you will see this message

#:rm -rf files*
-bash: /bin/rm: Argument list too long

#:ls |wc -l

Why this is happening? To say it in a simple way, you have to many files. Why this is a problem? Linux see that you have to many files and he is not able to do things (in are case rm, cp, ls or mv operations) because there is to many files. This have nothing do to with file size. Just with numbers of files. How to solved this? 

When I see this  Argument list too long message I always use for loop.

It goes like this

#:for i in `ls`;do rm -rf $i;done

And problem is solved.

Hope it helps! :)

No comments: