I have a directory with a large number of files. I don't see a ls switch to provide the count. Is there some command line magic to get a count of files?
|
|
|||
|
|
|
Using a broad definition of "file"
|
|||||||||||
|
This is obviously generalizable to any glob. The In a script, this has the sometimes unfortunate side effect of overwriting the positional parameters. You can work around this with a function (Bourne/POSIX version, you can write it more clearly in fancy shells) (warning, typed directly into the browser):
An alternative solution is |
|||||||||||
|
|
Here's another technique along the lines of the one Gilles posted:
which creates an array with 13,923 elements (if that's how many files there are). |
|||
|
|
...
...
PS: Note ls -<number-one> | wc -<letter-l> |
|||||||||||||||||
|
