CLI – We all find ourselves searching our Mac looking for a particular file or files that satisfy certain criteria. Certainly, you can use Spotlight for that, but there are also methods of searching through the command line. Those options give you much better control over your search criteria. The find command is a very flexible way of searching your machine for files.
The description of find in the macOS man page is:
NAME
find — walk a file hierarchy
SYNOPSIS
find [-H | -L | -P] [-EXdsx] [-f path] path … [expression]
find [-H | -L | -P] [-EXdsx] -f path [path …] [expression]
DESCRIPTION
The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the “primaries” and “operands” listed below) in terms of each file in the tree.
I didn’t attempt to list the switches, primaries and operands. There are nine switches and over 60 primaries. I suggest checking out the man page for find on your macOS machine (or on the web) to see all of your options.
One of the ways I have used find is to look for large files. In the example above, I searched a directory for all files larger than 10 megabytes. This could easily be used to search your entire disk for large files (use +1G instead of +10M to find files larger than 1 Gagabyte in length).
You can also search for files older than (or newer than) a specific date. I have used this feature of the find command many times. In the example above I have used cd to move to a directory that contains Science Fiction images I use for one of my Desktops. I am searching that directory looking for files that were modified (in my use case this means added) more than 10 days ago.
Those ae just two simple examples of using the find command. There are many other examples of how find can be used in the references listed at the end of this article. Because of the flixibility of the find command, it can be put to use for many tasks by the SysAdmin as well as the macOS/Linux/UNIX user.
To learn a lot more about how to use find, take a look at “Finding Files On The Command Line“. Yes, this is a Linux article, but the find command as implemented on macOS is fundamentally the same.
Check the macOS man page for cd for all of the available options.
References
- 25 simple examples of Linux find command
- 14 Practical Examples of Linux Find Command for Beginners
- Finding Files On The Command Line
See my other CLI and macOS articles