Re: Command failure: Too Many Files (rm, ls, tar)

[email protected] (Bob Proulx)
Newsgroups gmane.comp.gnu.utils
Message-ID <[email protected]>
Browder, Tom wrote:
> Last week I started getting errors indicating there were too many files
> for the command (rm *, ls *, tar cvzf xfer.tgz *) to continue.
> ...
> Is there a magic number limit on those commands?
> Or am I doing something wrong.

You are running into the kernel's ARG_MAX limitation.  Please see this
reference for more information.

  http://www.gnu.org/software/coreutils/faq/#Argument-list-too-long

> I regularly copy the files to a transfer directory, cd to that
> directory, and tar them and gzip them (tar cvzf xfer.tgz *) to take
> them to another site.

For your 'tar' case you can avoid the argument expansion entirely
simply by giving '.' as the argument.

  tar cvzf xfer.tgz .

For 'rm *' I would normally either simply remove the entire directory
with 'rm -rf ./dir' or use 'find' like this:

  find . -exec rm {} +

For 'ls *' there is no need of the '*'.  Just use ls.  Actually using
'ls *' is inefficient because the shell expands the * to match every
filename in the directory and ls then lists it.  But the entire
purpose of ls is to list directories.  So 'ls *' does the same work
twice while 'ls' does it once.  Better to simply use 'ls'.

  ls

Bob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.