files

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.

File permissions on html server (recursive chmod) differentiating between files and directories

I recursively screwed up the file permissions in my html servers root directory. To fix it I needed to deploy some "advanced" chmod settings. Obviously I want to treat directories and files differently. I didn't come up with a better solution than the following:

chmod -R u=rw-x,g=rw-x,o=r-wx *
chmod -R a+X *