How to Count Files Containing Specific Text on macOS

A Step-by-Step Guide to using grep via terminal.

Luca Berton

--

Managing large numbers of files can be a daunting task, especially when you need to identify which files contain specific text and which do not. If you’re working with Markdown files (.md) on macOS and need to search for a particular string within those files, Terminal provides a powerful set of tools to get the job done efficiently. In this article, we’ll walk you through how to count the number of .md files that contain a specific string, such as "subtitle," and how many do not.

Step 1: Open Terminal

The first step is to open the Terminal application on your macOS. You can find Terminal in Applications > Utilities, or you can quickly access it by using Spotlight Search (Cmd + Space) and typing "Terminal."

Step 2: Navigate to the Directory

Once Terminal is open, you’ll need to navigate to the directory that contains your .md files. You can do this using the cd command. For example, if your files are stored in a folder on your desktop, you would enter the following command:

cd ~/Desktop/YourFolderName

Replace YourFolderName with the actual name of your directory. This command directs Terminal to the location of your files.

Step 3: Count Files Containing the String “subtitle”

--

--

Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday