Counting files in a folder
ls -1 | wc -l

Deleting a lot of files when plain ol rm won’t work
find . -name 'prefix*' -print0 | xargs -0 rm

Find files containing a text string
grep -lir "some text" *

The -l switch outputs only the names of files in which the text occurs (instead of each line containing the text), the -i switch ignores the case, and the -r descends into subdirectories.

Find files recursively containing a text string
find . -type f -exec grep -l "some text" {} \; -print

Find directories recursively named ‘thumbnails’ and chmod 777 them and their contents
find . -type d -name 'thumbnails' -exec chmod -R 777 {} \; -print

Categories: LAMP

Jonathan Adjei

Jon's expertise in web development is legendary and he oversees all technical aspects of our projects from development to hosting (all through the command line!) Jon is excited by the latest techniques and keeps the company on track by finding ways to adopt new practices into our workflow.