MoiMême.ca

Why Not?

macOS quick tip: Find a file using the Terminal

As a systems administrator, I often have to search for a file on different systems. I usually go into the terminal and use the #!shell find command.

However, on macOS, you usually get a lot of output that is not relevant, such as Permission denied or Not a directory errors. Since those errors are output into a standard file descriptor, called stderr, I can simply redirect the errors to the #!shell /dev/null file.

For instance, if I want to search for all files on the file system ending in .sh, I will run a command as follows:

find / -name *.sh 2>/dev/null

There are many ways you can use the #!shell find command on macOS, like search only for folders containing a specific sequence of letters in the name. The command’s manual lists all of the possible operations you can do with it; you can read the manual by running #!shell man find in the Terminal, or in Apple’s documentation.