The Unix shell is built around using a series of utilities that each do one small task,Īnd do it very well. If you wanna wedge your current directory in there, an easy way would be via theīackticks trick: "find `pwd` -print | wc -l". Of course the GUI is much easier, but if you're connecting remotely via SSH, you won't have that option available!Ĭlever. Subdirectories count as one entry the files in the subdirectory are not counted. The output of this command is the number of files in the directory. Ls | wc -lThat's the "ls" directory listing command, the vertical bar (which 'pipes' the output of "ls" to the next command), and then the "wc" word count command with the "l" (lower-case L) option to count the number of lines instead of characters. To count the number of files in a directory, enter: cd directory_to_count The answer definitely speaks to the sometimes non-intuitive nature of UNIX, but also shows how you can pretty much make it do what you want by combining commands. I finally had to use a lifeline and phoned a friend -). Given my basic UNIX skills, I headed to the "man" pages for "ls", but found nothing useful there. Size information is easy to get (type "du directory_name"), but how do you know how many files are in a directory in the terminal? Everything scrolled by, and then I noticed that there's no total file or total size information. So I made my large directory, opened a terminal, then did an "ls" on the directory.
I was trying to replicate an error someone was experiencing involving a large number of files in a directory.