Unix / Linux: Count Files in Directory

Objective: Count the number of files in a directory on Unix or Linux.

Use the ls and wc commands to get the file count in a directory. Hidden files (files that start with “.”) will be excluded from the count. If there are sub directories or soft links (symbolic links) within that directory, they will be counted as a file as well. Use one of the following syntax.

If you are only interested in counting regular files, including hidden files, use the find command. Note that the “maxdepth” option is not supported in some Unix distributions. GNU find supports the “maxdepth” option. The below syntax will not include soft links.

To count all regular files, including hidden files and soft links, use the “-L” option.

To count the number of executable files, use the “-perm” option. Again, this syntax only works with GNU find.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }