0
$ ls  <path>/ | wc -l
52137

A full directory listing works. But attempting to shorten the number of files, I get:

$ ls <path>/*horiz | wc -l
-bash: /bin/ls: Argument list too long
0  

Why?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
aerijman
  • 2,522
  • 1
  • 22
  • 32

2 Answers2

1

Because with ls <path>/, you are asking ls to list the files of <path>. But with ls <path>/*horiz, the shell is expanding the asterisk into the actual list of files, like

ls <path>/<prefix1>horiz <path>/<prefix2>horiz ... <path>/<prefixN>horiz

but that list is too long for a single shell line, so it gaves you the error.

Poshi
  • 5,332
  • 3
  • 15
  • 32
1

This has one argument, the directory name, which ls loops over internally:

ls <path>/

Note however that this is not one argument:

ls <path>/*horiz

Here, the shell itself expands <path>/*horiz into all the files that match, and then launches ls with that list of matches.

You might try something like this:

ls <path>/ | grep -c 'horiz$'
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98