This post was originally published on go2linux.org, a Linux blog I ran from 2007 to 2011. The domain is no longer mine, but I am the original author. I am republishing it here on garron.me with corrections and improvements.

Introduction

In these days when disk are everyday bigger and bigger as well as cheaper, you will find yourself storing everything, we almost never delete a file anymore, we just store it. But, I do not know about yourself, but sometimes it happens to me, that I can’t just remember where a given file, picture, or song was archived.

So, I know I have it, somewhere in my disk, but not know where. You you might think I am not too organized, and you will be right with that statement, :).

What I do, is to use find to locate those missed files, find is extremely powerful, and I’ve written about it in the past, for example:

Today, I just want to give you a small tip about it, and it is how to combine searches using boolean operators like:

  • AND
  • OR
  • NOT

Find and boolean operators

Let’s do this by examples, and to start let’s suppose I want to find the files with .png and .jpg extensions.

find /path/ -name '*.png' -or -name '*.jpg'

This way, files with .jpg or .png in other words image files.

Now, let’s imagine we need to find movies that are bigger than a certain size.

find /path/ -name '*.mpeg' -and -size +300000k

So, we will find only files ending in .mpeg and bigger than 300 Mega bytes of size.

I’m sure you will find other applications.