'rm' Can not delete files

Randal L. Schwartz merlyn at stonehenge.com
Tue Feb 7 22:06:20 UTC 2012


>>>>> "Коньков" == Коньков Евгений <kes-kes at yandex.ru> writes:

Коньков> # rm *
Коньков> /bin/rm: Argument list too long.


Коньков> in this directory about 25000 files,
Коньков> but actually there is only one argument to rm it is '*' sign.

Коньков> Why rm get list of all files in directore instead of deleting
Коньков> one by one?

It's the way Unix works.  Individual commands typically know nothing of
'*' or '[abc]'.  The shell "globs" the command, expanding it to all the
matching files, and then hands that list to the command as individual
arguments.

However, sometimes that expansion exceeds the maximum argument size, as
you discovered.

If you have perl, try this:

  perl -e 'unlink glob("*")'

It uses Perl's internal glob() function, which can handle an unlimited
number of files.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


More information about the freebsd-questions mailing list