August 1, 2023

Count the number of files in a folder with wc

$ ls | wc -l

will display the number of files in the current directory (folder).

$ ls *.md | wc -l

will display the number of Markdown files in the current directory.

In these two examples, we use ls to list the content of the directory and then pipe (i.e. |) the output of ls to the command wc which will display number of lines as we invoke the option -l, short for --lines.

In the second example we tell ls to only list Markdown files using a wildcard (i.e. *) and the extension of Markdown files (i.e. .md).

To learn about wc run $ man wc.

wc was first released in 19711. It is now part of the coreutils package which is copyleft-licensed and is maintained by Jim Meyering2

  1. wc’s first man page.↩︎

  2. Coreutils - GNU core utilities’s webpage.↩︎

personal computing command-line interface (cli) gnu linux trisquel shell literacy wc grep wiki office applications

No affiliate links, no analytics, no tracking, no cookies. © 2016-2023 Content is licensed under CC BY-NC-SA 4.0 .