Related to this question.
How do I count the number of files in a directory so huge that ls
returns too many characters for the command line to handle?
$ ls 150_sims/combined/ | wc -l
bash: /bin/ls: Argument list too long
Related to this question.
How do I count the number of files in a directory so huge that ls
returns too many characters for the command line to handle?
$ ls 150_sims/combined/ | wc -l
bash: /bin/ls: Argument list too long
Try this:
$ find 150_sims/combined/ -maxdepth 1 -type f | wc -l
If you're sure there are no directories inside your directory, you can reduce the command to just:
$ find 150_sims/combined/ | wc -l
If there are no newlines in file names, a simple ls -A | wc -l
tells you how many files there are in the directory. Please note that if you have an alias for ls
, this may trigger a call to stat (Example: ls --color
or ls -F
need to know the file type, which requires a call to stat), so from the command line, call command ls -A | wc -l
or \ls -A | wc -l
to avoid an alias.
ls -A 150_sims/combined | wc -l
If you are interested in counting both the files and directories you can try something like this:
\ls -afq 150_sims/combined | wc -l
This includes .
and ..
, so you need subtract 2
from the count:
echo $(\ls -afq 150_sims/combined | wc -l) - 2 | bc