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?

0

2 Answers 2

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$' 
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.