ls

Counting files (list and word count, ls & wc)

How do you count the number of files in a directory? That becomes non-trivial if you have thousands of files in a directory. Your file manager chokes on counting them, especially if they are not local. On the Linux command line, this task is fast and easy:
ls | wc
ls lists your files one per row and wc returns three numbers: lines, words and bytes. In the file counting example, lines and words are the same and equal the number of files in the directory.

The ls command

I have been using is for years, but hardly have used its "advanced" options. That is:ls -t to sort the content of the directory according to modification date. ls -d to display the directories and not their contents. ls -alh lists the complete content of the directory in long, human-readable form (that means file sizes are given in B, K, M or G and not in bytes).