In general, the answer by blonfu works. However, Linux has the curious virtue of allowing file names to contain line breaks:
$ touch "hola" "hola que
> tal"
$ ls | wc -l
3 # incorrecto, hay 2 ficheros solamente
Therefore, it can be safer to do a find
that runs through all the cases that interest us (that is, only at this level, without entering subdirectories) and print a character for each file it finds. Then, add characters:
find . -maxdepth 1 -mindepth 1 ! -print0 | xargs -0 -I {} sh -c 'echo .' | wc -l
Discarding the names you indicate:
find . -maxdepth 1 -mindepth 1 ! -name '$RECYCLE.BIN' ! -name 'System Volume Information' -print0 | xargs -0 -I {} sh -c 'echo .' | wc -l
In the previous case it returns:
$ find . -maxdepth 1 -mindepth 1 -print0 | xargs -0 -I {} sh -c 'echo .' | wc -l
2
Or you can also do a loop that does the same:
$ for f in *; do echo "."; done | wc -l
2
Discarding those names:
for f in *; do [ "$f" = '$RECYCLE.BIN' -o "$f" = 'System Volume Information' ] && continue; echo "."; done | wc -l