Here's a quickie, but it was useful for something I was messing with: In Linux (or Unix, etc.), how do you list the number of items in a directory from the command line?
This Worked:
I'll admit up-front that this is a bit of a hack (in my opinion), but it works fine for simply finding out how many items are in a directory. The reason it's a hack is explained below.
This is a simple command option using the "ls" and "wc" commands in tandem. Here's what you run (from inside the directory you're interested in):
ls -l | wc -l
Briefly, that's the list command "ls" with the -l option, which gives a verbose list option to the command. This is combined with the "wc" (short for "word count") command, which displays a count of lines (the "-l" option in this case), words and characters in a file... yeah, a file, but we're interested in counting items in a directory, right? Well, that's the whole "|" bit, which is called "piping" -- executing commands in a sequence.
What we're saying with this command is roughly: "get a list of the contents in this directory, but show me a count of the lines in the list"... like I said, that's roughly what it means. I'll leave it to you to do more research to learn more about these commands and their options.
I'm calling this is a bit of a hack only because you're getting a count of lines in the listing, which can include some unwanted bits in this case... like directories will show up as a line item, which you may not be interested in counting. Maybe you see the slight draw back here? For my needs, total accuracy wasn't important -- just a close estimate.
Some variations on the theme:
ls -Rl | wc -l
Give me a count of the number of items in the current directory and all subdirectories ("R" means to "recurse" into the directories in the list... neat.)
ls -l someDirectoryNameHere | wc -l
Give me the count for a specific directory.